Drop cloud and Ollama engine choices so audio stays on-machine via Docker Whisper, and tighten orphan detection plus UI around a single local flow.
33 lines
1012 B
PHP
33 lines
1012 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Recording;
|
|
use Closure;
|
|
use Laravel\Ai\Transcription;
|
|
|
|
class TranscriptionService
|
|
{
|
|
/**
|
|
* Transcribe a recording with the local faster-whisper server.
|
|
*
|
|
* @param (Closure(string, int): void)|null $onProgress
|
|
*/
|
|
public function transcribe(Recording $recording, ?Closure $onProgress = null): string
|
|
{
|
|
$report = $onProgress ?? static fn (string $message, int $percent) => null;
|
|
$model = config('ai.local_whisper_model', 'Systran/faster-whisper-base');
|
|
|
|
$report('Connecting to local faster-whisper server…', 30);
|
|
$report("Transcribing locally with {$model} (audio stays on this machine)…", 50);
|
|
|
|
$transcript = Transcription::fromStorage($recording->file_path)
|
|
->timeout((int) config('ai.transcription_timeout', 600))
|
|
->generate('local-whisper', $model);
|
|
|
|
$report('Received transcript from local Whisper…', 85);
|
|
|
|
return (string) $transcript;
|
|
}
|
|
}
|