Skip to content

Commit 4beecf5

Browse files
committed
add test
1 parent a777284 commit 4beecf5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

video/src/analyze_transcription.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function analyze_transcription($uri, array $options = [])
3434
$features = [Feature::SPEECH_TRANSCRIPTION];
3535
$speechTranscriptionConfig = (new SpeechTranscriptionConfig())
3636
->setLanguageCode('en-US')
37-
->setEnableAutomaticPunctuation(True);
37+
->setEnableAutomaticPunctuation(true);
3838
$videoContext = (new VideoContext())
3939
->setSpeechTranscriptionConfig($speechTranscriptionConfig);
4040

@@ -48,7 +48,7 @@ function analyze_transcription($uri, array $options = [])
4848
'videoContext' => $videoContext
4949
]);
5050

51-
print('Processing video for speech transcription...');
51+
print('Processing video for speech transcription...' . PHP_EOL);
5252
# Wait for the request to complete.
5353
$operation->pollUntilComplete($options);
5454

@@ -66,7 +66,7 @@ function analyze_transcription($uri, array $options = [])
6666
# each alternative is a different possible transcription
6767
# and has its own confidence score.
6868
foreach ($transcription->getAlternatives() as $alternative) {
69-
print('Alternative level information');
69+
print('Alternative level information' . PHP_EOL);
7070

7171
printf('Transcript: %s' . PHP_EOL, $alternative->getTranscript());
7272
printf('Confidence: %s' . PHP_EOL, $alternative->getConfidence());
@@ -76,7 +76,7 @@ function analyze_transcription($uri, array $options = [])
7676
$word = $wordInfo->getWord();
7777
$startTime = $wordInfo->getStartTime();
7878
$endTime = $wordInfo->getEndTime();
79-
printf('%s s - %s s: %s' . PHP_EOL, $startTime, $endTime, $word);
79+
printf('%s s - %s s: %s' . PHP_EOL, $startTime->getSeconds(), $endTime->getSeconds(), $word);
8080
}
8181
}
8282
}

video/test/videoTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,30 @@ public function testAnalyzeShots()
8585
$this->assertContains(' to ', $output);
8686
}
8787

88+
public function testTranscription()
89+
{
90+
$output = $this->runCommand('transcription', [
91+
'uri' => $this->gcsUriTwo(),
92+
'--polling-interval-seconds' => 10,
93+
]);
94+
$this->assertContains('Transcript:', $output);
95+
$this->assertContains('Paris', $output);
96+
$this->assertContains('France', $output);
97+
}
98+
8899
private function gcsUri()
89100
{
90101
return sprintf(
91102
'gs://%s/video/cat_shortened.mp4',
92103
$this->requireEnv('GOOGLE_STORAGE_BUCKET')
93104
);
94105
}
106+
107+
private function gcsUriTwo()
108+
{
109+
return sprintf(
110+
'gs://%s/video/googlework_short.mp4',
111+
$this->requireEnv('GOOGLE_STORAGE_BUCKET')
112+
);
113+
}
95114
}

0 commit comments

Comments
 (0)