Skip to content

Commit

Permalink
samples: Model selection (#1074)
Browse files Browse the repository at this point in the history
* Add model selection to streaming sample

* Fix model selection naming
  • Loading branch information
nnegrey authored and chingor13 committed Aug 15, 2020
1 parent c9faebc commit 3001154
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions speech/snippets/src/main/java/com/example/speech/Recognize.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String... args) throws Exception {
System.out.printf(
"\tjava %s \"<command>\" \"<path-to-image>\"\n"
+ "Commands:\n"
+ "\tsyncrecognize | asyncrecognize | streamrecognize | wordoffsets\n"
+ "\tsyncrecognize | asyncrecognize | streamrecognize | wordoffsets | model-selection\n"
+ "Path:\n\tA file path (ex: ./resources/audio.raw) or a URI "
+ "for a Cloud Storage resource (gs://...)\n",
Recognize.class.getCanonicalName());
Expand Down Expand Up @@ -82,11 +82,11 @@ public static void main(String... args) throws Exception {
}
} else if (command.equals("streamrecognize")) {
streamingRecognizeFile(path);
} else if (command.equals("video")) {
} else if (command.equals("model-selection")) {
if (path.startsWith("gs://")) {
transcribeGcsVideoFile(path);
transcribeModelSelectionGcs(path);
} else {
transcribeVideoFile(path);
transcribeModelSelection(path);
}
}
}
Expand Down Expand Up @@ -420,10 +420,10 @@ public SettableFuture<List<T>> future() {
// [START speech_transcribe_model_selection]
/**
* Performs transcription of the given audio file synchronously with
* video as the original media type.
* @param fileName the path to a video file to transcribe
* the selected model.
* @param fileName the path to a audio file to transcribe
*/
public static void transcribeVideoFile(String fileName) throws Exception {
public static void transcribeModelSelection(String fileName) throws Exception {
Path path = Paths.get(fileName);
byte[] content = Files.readAllBytes(path);

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

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

// Configure request with video media type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ public void testStreamRecognize() throws Exception {
}

@Test
public void testVideoTranscription() throws Exception {
Recognize.transcribeVideoFile(videoFileName);
public void testModelSelection() throws Exception {
Recognize.transcribeModelSelection(videoFileName);
String got = bout.toString();
assertThat(got).contains("OK Google");
assertThat(got).contains("the weather outside is sunny");
}

@Test
public void testGcsVideoTranscription() throws Exception {
Recognize.transcribeGcsVideoFile(gcsVideoPath);
public void testGcsModelSelection() throws Exception {
Recognize.transcribeModelSelectionGcs(gcsVideoPath);
String got = bout.toString();
assertThat(got).contains("OK Google");
assertThat(got).contains("the weather outside is sunny");
Expand Down

0 comments on commit 3001154

Please sign in to comment.