Add transcription progress handling and local Whisper integration.
Implement a new method for calculating elapsed transcription time in the Recording model. Enhance the TranscriptionService to handle local Whisper requests, including asynchronous processing and progress reporting. Update the recordings index view to display transcription progress percentage. Add unit tests for the new transcription service functionality.
This commit is contained in:
@@ -14,6 +14,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Ai\Transcription;
|
||||
use Livewire\Livewire;
|
||||
@@ -203,6 +204,34 @@ class RecordingUploadTest extends TestCase
|
||||
->assertJsonPath('driver_label', 'Local (faster-whisper)');
|
||||
}
|
||||
|
||||
public function test_transcription_service_calls_local_whisper_http(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
Storage::disk('local')->put('recordings/long.mp3', 'fake-audio-bytes');
|
||||
|
||||
Http::fake([
|
||||
'*' => Http::response(['text' => 'Hello from whisper.']),
|
||||
]);
|
||||
|
||||
$recording = Recording::query()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'title' => 'Long whisper',
|
||||
'original_filename' => 'long.mp3',
|
||||
'file_path' => 'recordings/long.mp3',
|
||||
'file_size_bytes' => 100,
|
||||
'transcription_status' => 'processing',
|
||||
'transcription_driver' => 'local',
|
||||
]);
|
||||
|
||||
$text = app(TranscriptionService::class)->transcribe($recording);
|
||||
|
||||
$this->assertSame('Hello from whisper.', $text);
|
||||
|
||||
Http::assertSent(function ($request): bool {
|
||||
return str_contains($request->url(), '/audio/transcriptions');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_transcription_job_stores_transcript(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
@@ -126,6 +126,7 @@ class IndexTest extends TestCase
|
||||
Livewire::test(Index::class)
|
||||
->assertSee('wire:poll', false)
|
||||
->assertSee('Transcribing')
|
||||
->assertSee('40%')
|
||||
->assertDontSee('Transcribing locally…')
|
||||
->assertSeeHtml('bg-amber-400');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user