Files
AndyTranscribe/app/Jobs/TranscribeRecording.php
T
ben e0400aadef Add live transcription progress and Docker Whisper.
Surface stage, percent, and elapsed time while jobs run, and ship Compose so local confidential transcription can use faster-whisper on port 8090.
2026-08-12 14:32:56 +02:00

90 lines
2.7 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Recording;
use App\Services\TranscriptionService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use Throwable;
class TranscribeRecording implements ShouldQueue
{
use Queueable;
/**
* The number of seconds the job can run before timing out.
*/
public int $timeout = 600;
/**
* Create a new job instance.
*/
public function __construct(public Recording $recording)
{
//
}
/**
* Execute the job.
*/
public function handle(TranscriptionService $transcription): void
{
$this->recording->refresh();
$this->recording->forceFill([
'transcription_status' => 'processing',
'transcription_started_at' => $this->recording->transcription_started_at ?? now(),
'transcription_error' => null,
])->save();
$this->recording->reportProgress('Preparing audio file…', 15);
try {
$text = $transcription->transcribe(
$this->recording,
fn (string $message, int $percent) => $this->recording->reportProgress($message, $percent),
);
$this->recording->reportProgress('Saving transcript…', 90);
$this->recording->forceFill([
'transcript' => $text,
'transcription_status' => 'done',
'transcription_progress' => 'Transcription complete',
'transcription_percent' => 100,
'transcription_error' => null,
'transcribed_at' => now(),
])->save();
} catch (Throwable $e) {
Log::error('Transcription failed', [
'recording_id' => $this->recording->id,
'driver' => $this->recording->transcription_driver,
'message' => $e->getMessage(),
]);
$this->recording->forceFill([
'transcription_status' => 'failed',
'transcription_progress' => 'Transcription failed',
'transcription_percent' => $this->recording->transcription_percent ?: 0,
'transcription_error' => $e->getMessage(),
])->save();
throw $e;
}
}
/**
* Handle a job failure (timeouts, worker kill, etc.).
*/
public function failed(?Throwable $e): void
{
$this->recording->forceFill([
'transcription_status' => 'failed',
'transcription_progress' => 'Transcription failed',
'transcription_error' => $e?->getMessage() ?: 'Transcription stopped unexpectedly.',
])->save();
}
}