@@ -523,8 +523,10 @@ public static void transcribeVideoFile(String fileName) throws Exception {
523
523
524
524
// Configure request with video media type
525
525
RecognitionConfig recConfig = RecognitionConfig .newBuilder ()
526
+ // encoding may either be omitted or must match the value in the file header
526
527
.setEncoding (AudioEncoding .LINEAR16 )
527
528
.setLanguageCode ("en-US" )
529
+ // sample rate hertz may be either be omitted or must match the value in the file header
528
530
.setSampleRateHertz (16000 )
529
531
.setMetadata (recognitionMetadata )
530
532
.build ();
@@ -539,12 +541,13 @@ public static void transcribeVideoFile(String fileName) throws Exception {
539
541
540
542
if (results .isEmpty ()) {
541
543
System .out .println ("No results" );
542
- return ;
543
544
}
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
+ }
548
551
}
549
552
}
550
553
// [END transcribe_video_file]
@@ -565,8 +568,10 @@ public static void transcribeGcsVideoFile(String gcsUri) throws Exception {
565
568
566
569
// Configure request with video media type
567
570
RecognitionConfig config = RecognitionConfig .newBuilder ()
571
+ // encoding may either be omitted or must match the value in the file header
568
572
.setEncoding (AudioEncoding .LINEAR16 )
569
573
.setLanguageCode ("en-US" )
574
+ // sample rate hertz may be either be omitted or must match the value in the file header
570
575
.setSampleRateHertz (16000 )
571
576
.setMetadata (recognitionMetadata )
572
577
.build ();
@@ -586,6 +591,9 @@ public static void transcribeGcsVideoFile(String gcsUri) throws Exception {
586
591
587
592
List <SpeechRecognitionResult > results = response .get ().getResultsList ();
588
593
594
+ if (results .isEmpty ()) {
595
+ System .out .println ("No results" );
596
+ }
589
597
for (SpeechRecognitionResult result : results ) {
590
598
List <SpeechRecognitionAlternative > alternatives = result .getAlternativesList ();
591
599
for (SpeechRecognitionAlternative alternative : alternatives ) {
0 commit comments