Skip to content

Commit

Permalink
chore: [TranscriptionManager] support optional argument to decide max…
Browse files Browse the repository at this point in the history
… speaker count
  • Loading branch information
ericHao22 committed Aug 30, 2023
1 parent f49b8c3 commit 37564da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/TranscriptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/TranscriptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/TranscriptionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit 37564da

Please sign in to comment.