Skip to content

Commit 3001154

Browse files
nnegreychingor13
authored andcommitted
samples: Model selection (#1074)
* Add model selection to streaming sample * Fix model selection naming
1 parent c9faebc commit 3001154

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

speech/snippets/src/main/java/com/example/speech/Recognize.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void main(String... args) throws Exception {
5252
System.out.printf(
5353
"\tjava %s \"<command>\" \"<path-to-image>\"\n"
5454
+ "Commands:\n"
55-
+ "\tsyncrecognize | asyncrecognize | streamrecognize | wordoffsets\n"
55+
+ "\tsyncrecognize | asyncrecognize | streamrecognize | wordoffsets | model-selection\n"
5656
+ "Path:\n\tA file path (ex: ./resources/audio.raw) or a URI "
5757
+ "for a Cloud Storage resource (gs://...)\n",
5858
Recognize.class.getCanonicalName());
@@ -82,11 +82,11 @@ public static void main(String... args) throws Exception {
8282
}
8383
} else if (command.equals("streamrecognize")) {
8484
streamingRecognizeFile(path);
85-
} else if (command.equals("video")) {
85+
} else if (command.equals("model-selection")) {
8686
if (path.startsWith("gs://")) {
87-
transcribeGcsVideoFile(path);
87+
transcribeModelSelectionGcs(path);
8888
} else {
89-
transcribeVideoFile(path);
89+
transcribeModelSelection(path);
9090
}
9191
}
9292
}
@@ -420,10 +420,10 @@ public SettableFuture<List<T>> future() {
420420
// [START speech_transcribe_model_selection]
421421
/**
422422
* Performs transcription of the given audio file synchronously with
423-
* video as the original media type.
424-
* @param fileName the path to a video file to transcribe
423+
* the selected model.
424+
* @param fileName the path to a audio file to transcribe
425425
*/
426-
public static void transcribeVideoFile(String fileName) throws Exception {
426+
public static void transcribeModelSelection(String fileName) throws Exception {
427427
Path path = Paths.get(fileName);
428428
byte[] content = Files.readAllBytes(path);
429429

@@ -456,11 +456,11 @@ public static void transcribeVideoFile(String fileName) throws Exception {
456456

457457
// [START speech_transcribe_model_selection_gcs]
458458
/**
459-
* Performs transcription on remote video file and prints the transcription.
460-
*
461-
* @param gcsUri the path to the remote video file to transcribe.
459+
* Performs transcription of the remote audio file asynchronously with
460+
* the selected model.
461+
* @param gcsUri the path to the remote audio file to transcribe.
462462
*/
463-
public static void transcribeGcsVideoFile(String gcsUri) throws Exception {
463+
public static void transcribeModelSelectionGcs(String gcsUri) throws Exception {
464464
try (SpeechClient speech = SpeechClient.create()) {
465465

466466
// Configure request with video media type

speech/snippets/src/test/java/com/example/speech/RecognizeIT.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ public void testStreamRecognize() throws Exception {
110110
}
111111

112112
@Test
113-
public void testVideoTranscription() throws Exception {
114-
Recognize.transcribeVideoFile(videoFileName);
113+
public void testModelSelection() throws Exception {
114+
Recognize.transcribeModelSelection(videoFileName);
115115
String got = bout.toString();
116116
assertThat(got).contains("OK Google");
117117
assertThat(got).contains("the weather outside is sunny");
118118
}
119119

120120
@Test
121-
public void testGcsVideoTranscription() throws Exception {
122-
Recognize.transcribeGcsVideoFile(gcsVideoPath);
121+
public void testGcsModelSelection() throws Exception {
122+
Recognize.transcribeModelSelectionGcs(gcsVideoPath);
123123
String got = bout.toString();
124124
assertThat(got).contains("OK Google");
125125
assertThat(got).contains("the weather outside is sunny");

0 commit comments

Comments
 (0)