diff --git a/config/transcription.php b/config/transcription.php index 1c4d38f..aaacc4b 100644 --- a/config/transcription.php +++ b/config/transcription.php @@ -42,7 +42,6 @@ 'tags' => [], ], ], - 'speaker_identification' => false, ], /* diff --git a/src/AudioTranscribers/AwsTranscribeAudioTranscriber.php b/src/AudioTranscribers/AwsTranscribeAudioTranscriber.php index 7eee771..78ec212 100644 --- a/src/AudioTranscribers/AwsTranscribeAudioTranscriber.php +++ b/src/AudioTranscribers/AwsTranscribeAudioTranscriber.php @@ -43,7 +43,7 @@ public function __construct(array $config) /** * Transcribe audio file into text records in specific language. */ - public function transcribe(string $audioUrl, string $languageCode, bool $shouldIdentifySpeaker): Transcription + public function transcribe(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null): Transcription { // TODO: should support speaker identification $this->validateUrl($audioUrl); diff --git a/src/Contracts/AudioTranscriber.php b/src/Contracts/AudioTranscriber.php index b82b913..60e5c61 100644 --- a/src/Contracts/AudioTranscriber.php +++ b/src/Contracts/AudioTranscriber.php @@ -10,7 +10,7 @@ interface AudioTranscriber /** * Transcribe audio file into text records in specific language. */ - public function transcribe(string $audioUrl, string $languageCode, bool $shouldIdentifySpeaker): Transcription; + public function transcribe(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null): Transcription; /** * Parse transcripts result of transcription and persist them into database. diff --git a/src/Contracts/TranscriptionManager.php b/src/Contracts/TranscriptionManager.php index 54b9f6e..c0e7c26 100644 --- a/src/Contracts/TranscriptionManager.php +++ b/src/Contracts/TranscriptionManager.php @@ -9,7 +9,7 @@ interface TranscriptionManager /** * Make transcription for audio file in specific language */ - public function make(string $audioUrl, string $languageCode, ?bool $shouldRedact = false, ?string $transcriberName = null): Transcript; + public function make(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null, ?bool $shouldRedact = false, ?string $transcriberName = null): Transcript; /** * Confirm asynchronous transcription process diff --git a/src/TranscriptionManager.php b/src/TranscriptionManager.php index a57127f..62ff71a 100644 --- a/src/TranscriptionManager.php +++ b/src/TranscriptionManager.php @@ -71,7 +71,7 @@ public function addDetector(string $driverName, Closure $resolver): void /** * Make transcription for audio file in specific language */ - public function make(string $audioUrl, string $languageCode, ?bool $shouldRedact = false, ?string $transcriberName = null): Transcript + public function make(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null, ?bool $shouldRedact = false, ?string $transcriberName = null): Transcript { $type = Str::kebab(Str::camel($transcriberName ?: $this->getDefaultProcessor('transcription'))); $transcriber = $this->resolveTranscriber($transcriberName); @@ -80,8 +80,7 @@ public function make(string $audioUrl, string $languageCode, ?bool $shouldRedact $transcriber->setUp('POST', URL::route('transcription.callback', ['type' => $type])); } - $shouldIdentifySpeaker = $this->app['config']['transcription.transcription.speaker_identification'] ?? false; - $transcription = $transcriber->transcribe($audioUrl, $languageCode, $shouldIdentifySpeaker); + $transcription = $transcriber->transcribe($audioUrl, $languageCode, $maxSpeakerCount); $transcript = Transcript::create([ 'type' => $type, diff --git a/tests/Classes/AudioTranscribers/CallbackableTranscriber.php b/tests/Classes/AudioTranscribers/CallbackableTranscriber.php index 37aa81b..06c4d0e 100644 --- a/tests/Classes/AudioTranscribers/CallbackableTranscriber.php +++ b/tests/Classes/AudioTranscribers/CallbackableTranscriber.php @@ -12,7 +12,7 @@ class CallbackableTranscriber implements AudioTranscriber, Callbackable /** * Transcribe audio file into text records in specific language. */ - public function transcribe(string $audioUrl, string $languageCode, bool $shouldIdentifySpeaker): Transcription + public function transcribe(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null): Transcription { return new Transcription([]); } diff --git a/tests/Classes/AudioTranscribers/ConfirmableTranscriber.php b/tests/Classes/AudioTranscribers/ConfirmableTranscriber.php index 0de009f..fd7128b 100644 --- a/tests/Classes/AudioTranscribers/ConfirmableTranscriber.php +++ b/tests/Classes/AudioTranscribers/ConfirmableTranscriber.php @@ -12,7 +12,7 @@ class ConfirmableTranscriber implements AudioTranscriber, Confirmable /** * Transcribe audio file into text records in specific language. */ - public function transcribe(string $audioUrl, string $languageCode, bool $shouldIdentifySpeaker): Transcription + public function transcribe(string $audioUrl, string $languageCode, ?int $maxSpeakerCount = null): Transcription { return new Transcription([]); } diff --git a/tests/Unit/AudioTranscribers/AwsTranscribeAudioTranscriberTest.php b/tests/Unit/AudioTranscribers/AwsTranscribeAudioTranscriberTest.php index 0aec39d..25daccb 100644 --- a/tests/Unit/AudioTranscribers/AwsTranscribeAudioTranscriberTest.php +++ b/tests/Unit/AudioTranscribers/AwsTranscribeAudioTranscriberTest.php @@ -31,7 +31,7 @@ class AwsTranscribeAudioTranscriberTest extends TestCase private string $languageCode; - private bool $shouldIdentifySpeaker; + private int $maxSpeakerCount; private MockInterface $clientMock; @@ -51,7 +51,7 @@ protected function setUp(): void ], ]; $this->languageCode = 'en-US'; - $this->shouldIdentifySpeaker = false; + $this->maxSpeakerCount = 2; $this->clientMock = Mockery::mock(TranscribeServiceClient::class); $this->transcriber = new AwsTranscribeAudioTranscriber($this->config, $this->clientMock); @@ -85,7 +85,7 @@ public function transcribe_should_work(string $audioUrl): void }) ->andReturn($result); - $transcription = $this->transcriber->transcribe($audioUrl, $this->languageCode, $this->shouldIdentifySpeaker); + $transcription = $this->transcriber->transcribe($audioUrl, $this->languageCode, $this->maxSpeakerCount); $this->assertTrue(Str::isUuid($transcription->id)); $this->assertEquals($transcription->status, TranscriptionStatusEnum::PROCESSING); @@ -101,7 +101,7 @@ public function transcribe_should_fail_with_invalid_audio_url(): void $audioUrl = 'https://www.example.com'; - $this->transcriber->transcribe($audioUrl, $this->languageCode, $this->shouldIdentifySpeaker); + $this->transcriber->transcribe($audioUrl, $this->languageCode, $this->maxSpeakerCount); } /** diff --git a/tests/Unit/TranscriptionManagerTest.php b/tests/Unit/TranscriptionManagerTest.php index 34a6ec7..2f2b354 100644 --- a/tests/Unit/TranscriptionManagerTest.php +++ b/tests/Unit/TranscriptionManagerTest.php @@ -87,7 +87,7 @@ public function make_should_work(string $transcriberName): void { $audioUrl = 'https://www.example.com/audio/test.wav'; $languageCode = 'en-US'; - $shouldIdentifySpeaker = true; + $maxSpeakerCount = 2; $shouldRedact = true; $transcription = new Transcription([ 'id' => Str::uuid(), @@ -97,7 +97,6 @@ public function make_should_work(string $transcriberName): void $transcriberMock = $this->{Str::camel($transcriberName) . "Mock"}; $this->app['config']->set('transcription.transcription.default', $transcriberName); - $this->app['config']->set('transcription.transcription.speaker_identification', $shouldIdentifySpeaker); if ($transcriberMock instanceof Callbackable) { $callbackMethod = 'POST'; @@ -114,10 +113,10 @@ public function make_should_work(string $transcriberName): void $transcriberMock ->shouldReceive('transcribe') ->once() - ->with($audioUrl, $languageCode, $shouldIdentifySpeaker) + ->with($audioUrl, $languageCode, $maxSpeakerCount) ->andReturn($transcription); - $transcript = $this->manager->make($audioUrl, $languageCode, $shouldRedact); + $transcript = $this->manager->make($audioUrl, $languageCode, $maxSpeakerCount, $shouldRedact); $this->assertEquals($transcript->type, Str::kebab(Str::camel($transcriberName))); $this->assertEquals($transcript->external_id, $transcription->id);