diff --git a/speech/cloud-client/README.md b/speech/cloud-client/README.md index c5adea63b89..42ff0729978 100644 --- a/speech/cloud-client/README.md +++ b/speech/cloud-client/README.md @@ -19,63 +19,54 @@ Install [Maven](http://maven.apache.org/). Build your project with: ``` -mvn clean compile assembly:single +mvn clean package ``` ## Quickstart Transcribe a local audio file ``` -java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ -com.example.speech.QuickstartSample +mvn exec:java -DQuickstart ``` ## Transcribe a audio file Transcribe a local audio file ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize syncrecognize ./resources/audio.raw +mvn exec:java -DRecognize -Dexec.args="syncrecognize ./resources/audio.raw" ``` Asynchronously transcribe a local audio file ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize asyncrecognize ./resources/audio.raw +mvn exec:java -DRecognize -Dexec.args="asyncrecognize ./resources/audio.raw" ``` Transcribe a remote audio file ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize syncrecognize gs://cloud-samples-tests/speech/brooklyn.flac +mvn exec:java -DRecognize -Dexec.args="syncrecognize gs://cloud-samples-tests/speech/brooklyn.flac" ``` Asynchronously transcribe a remote audio file ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize asyncrecognize gs://cloud-samples-tests/speech/vr.flac +mvn exec:java -DRecognize -Dexec.args="asyncrecognize gs://cloud-samples-tests/speech/vr.flac" ``` ## Transcribe a audio file and print word offsets Synchronously transcribe an audio file and print word offsets ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize wordoffsets ./resources/audio.raw +mvn exec:java -DRecognize -Dexec.args="wordoffsets ./resources/audio.raw" ``` Asynchronously transcribe a remote audio file and print word offsets ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize wordoffsets gs://cloud-samples-tests/speech/vr.flac +mvn exec:java -DRecognize -Dexec.args="wordoffsets gs://cloud-samples-tests/speech/vr.flac" ``` -## Transcribe a video file -Synchronously transcribe a video file +## Model Selection +Synchronously transcribe a audio file ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize video ./resources/Google_Gnome.wav +mvn exec:java -DRecognize -Dexec.args="model-selection ./resources/Google_Gnome.wav" ``` -Asynchronously transcribe a video file hosted on GCS +Asynchronously transcribe a audio file hosted on GCS ``` - java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \ - com.example.speech.Recognize video gs://cloud-samples-tests/speech/Google_Gnome.wav +mvn exec:java -DRecognize -Dexec.args="model-selection gs://cloud-samples-tests/speech/Google_Gnome.wav" ``` diff --git a/speech/cloud-client/pom.xml b/speech/cloud-client/pom.xml index 66a0451a532..a93abe2f05c 100644 --- a/speech/cloud-client/pom.xml +++ b/speech/cloud-client/pom.xml @@ -76,4 +76,64 @@ + + + + Quickstart + + + Quickstart + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + com.example.speech.QuickstartSample + false + + + + + + + + Recognize + + + Recognize + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + com.example.speech.Recognize + false + + + + + + diff --git a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java index 5d00d5cc9d6..f1fb3273ccd 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java @@ -52,7 +52,7 @@ public static void main(String... args) throws Exception { System.out.printf( "\tjava %s \"\" \"\"\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()); @@ -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); } } } @@ -420,10 +420,10 @@ public SettableFuture> 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); @@ -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 diff --git a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java index 2970647a010..f51a4c9b9a7 100644 --- a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java +++ b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java @@ -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");