Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model selection #1074

Merged
merged 5 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions speech/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a audio file -> an audio file

```
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"
```
60 changes: 60 additions & 0 deletions speech/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,64 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>Quickstart</id>
<activation>
<property>
<name>Quickstart</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.speech.QuickstartSample</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>Recognize</id>
<activation>
<property>
<name>Recognize</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.speech.Recognize</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
22 changes: 11 additions & 11 deletions speech/cloud-client/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