Skip to content

Commit

Permalink
Merge pull request #16 from OnrampLab/15-feat-make-speaker-identifica…
Browse files Browse the repository at this point in the history
…tion-become-optional

Make speaker identification become optional
  • Loading branch information
ericHao22 authored Sep 7, 2023
2 parents 7b054d0 + 423b254 commit 74fc65b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion config/transcription.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
'tags' => [],
],
],
'speaker_identification' => false,
],

/*
Expand Down
2 changes: 1 addition & 1 deletion src/AudioTranscribers/AwsTranscribeAudioTranscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/AudioTranscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Classes/AudioTranscribers/ConfirmableTranscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AwsTranscribeAudioTranscriberTest extends TestCase

private string $languageCode;

private bool $shouldIdentifySpeaker;
private int $maxSpeakerCount;

private MockInterface $clientMock;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

/**
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 74fc65b

Please sign in to comment.