Skip to content

Commit 71e8faf

Browse files
committed
speech samples
1 parent f8a1f68 commit 71e8faf

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
1.7 MB
Binary file not shown.

speech/cloud-client/src/main/java/com/example/speech/Recognize.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,10 @@ public static void transcribeVideoFile(String fileName) throws Exception {
523523

524524
// Configure request with video media type
525525
RecognitionConfig recConfig = RecognitionConfig.newBuilder()
526+
// encoding may either be omitted or must match the value in the file header
526527
.setEncoding(AudioEncoding.LINEAR16)
527528
.setLanguageCode("en-US")
529+
// sample rate hertz may be either be omitted or must match the value in the file header
528530
.setSampleRateHertz(16000)
529531
.setMetadata(recognitionMetadata)
530532
.build();
@@ -539,12 +541,13 @@ public static void transcribeVideoFile(String fileName) throws Exception {
539541

540542
if (results.isEmpty()) {
541543
System.out.println("No results");
542-
return;
543544
}
544-
List<SpeechRecognitionAlternative> alternatives = results.get(0).getAlternativesList();
545-
for (SpeechRecognitionAlternative alternative : alternatives) {
546-
System.out.printf("Confidence : %f, Transcript : %s\n", alternative.getConfidence(),
547-
alternative.getTranscript());
545+
for (SpeechRecognitionResult recognitionResult: results) {
546+
List<SpeechRecognitionAlternative> alternatives = recognitionResult.getAlternativesList();
547+
for (SpeechRecognitionAlternative alternative : alternatives) {
548+
System.out.printf("Confidence : %f, Transcript : %s\n", alternative.getConfidence(),
549+
alternative.getTranscript());
550+
}
548551
}
549552
}
550553
// [END transcribe_video_file]
@@ -565,8 +568,10 @@ public static void transcribeGcsVideoFile(String gcsUri) throws Exception {
565568

566569
// Configure request with video media type
567570
RecognitionConfig config = RecognitionConfig.newBuilder()
571+
// encoding may either be omitted or must match the value in the file header
568572
.setEncoding(AudioEncoding.LINEAR16)
569573
.setLanguageCode("en-US")
574+
// sample rate hertz may be either be omitted or must match the value in the file header
570575
.setSampleRateHertz(16000)
571576
.setMetadata(recognitionMetadata)
572577
.build();
@@ -586,6 +591,9 @@ public static void transcribeGcsVideoFile(String gcsUri) throws Exception {
586591

587592
List<SpeechRecognitionResult> results = response.get().getResultsList();
588593

594+
if (results.isEmpty()) {
595+
System.out.println("No results");
596+
}
589597
for (SpeechRecognitionResult result: results) {
590598
List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList();
591599
for (SpeechRecognitionAlternative alternative: alternatives) {

0 commit comments

Comments
 (0)