Skip to content

Commit 017ff5f

Browse files
committed
speech punctuation, video samples
1 parent c7e1d91 commit 017ff5f

File tree

5 files changed

+378
-146
lines changed

5 files changed

+378
-146
lines changed

speech/cloud-client/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,28 @@ Build your project with:
5757
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
5858
com.example.speech.Recognize wordoffsets gs://cloud-samples-tests/speech/vr.flac
5959
```
60+
61+
### Synchronously transcribe and punctuate a remote audio file
62+
```
63+
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
64+
com.example.speech.Recognize punctuation ./resources/audio.raw
65+
```
66+
67+
### Asynchronously transcribe and punctuate an audio file hosted on GCS
68+
```
69+
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
70+
com.example.speech.Recognize punctuation gs://cloud-samples-tests/speech/brooklyn.flac
71+
```
72+
73+
### Synchronously transcribe a video file
74+
```
75+
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
76+
com.example.speech.Recognize video ./resources/Google_Gnome.wav
77+
```
78+
79+
### Asynchronously transcribe a video file hosted on GCS
80+
```
81+
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
82+
com.example.speech.Recognize video gs://cloud-samples-tests/speech/Google_Gnome.wav
83+
```
84+

speech/cloud-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>com.google.cloud</groupId>
4040
<artifactId>google-cloud-speech</artifactId>
41-
<version>0.21.1-alpha</version>
41+
<version>0.23.0</version>
4242
</dependency>
4343
<!-- [END dependencies] -->
4444

speech/cloud-client/src/main/java/com/example/speech/QuickstartSample.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.google.cloud.speech.v1.RecognitionConfig;
2323
import com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding;
2424
import com.google.cloud.speech.v1.RecognizeResponse;
25-
import com.google.cloud.speech.v1.SpeechClient;
25+
import com.google.cloud.speech.v1_1beta1.SpeechClient;
2626
import com.google.cloud.speech.v1.SpeechRecognitionAlternative;
2727
import com.google.cloud.speech.v1.SpeechRecognitionResult;
2828
import com.google.protobuf.ByteString;
@@ -35,37 +35,37 @@
3535
public class QuickstartSample {
3636
public static void main(String... args) throws Exception {
3737
// Instantiates a client
38-
SpeechClient speech = SpeechClient.create();
38+
try (SpeechClient speechClient = SpeechClient.create()) {
3939

40-
// The path to the audio file to transcribe
41-
String fileName = "./resources/audio.raw";
40+
// The path to the audio file to transcribe
41+
String fileName = "./resources/audio.raw";
4242

43-
// Reads the audio file into memory
44-
Path path = Paths.get(fileName);
45-
byte[] data = Files.readAllBytes(path);
46-
ByteString audioBytes = ByteString.copyFrom(data);
43+
// Reads the audio file into memory
44+
Path path = Paths.get(fileName);
45+
byte[] data = Files.readAllBytes(path);
46+
ByteString audioBytes = ByteString.copyFrom(data);
4747

48-
// Builds the sync recognize request
49-
RecognitionConfig config = RecognitionConfig.newBuilder()
50-
.setEncoding(AudioEncoding.LINEAR16)
51-
.setSampleRateHertz(16000)
52-
.setLanguageCode("en-US")
53-
.build();
54-
RecognitionAudio audio = RecognitionAudio.newBuilder()
55-
.setContent(audioBytes)
56-
.build();
48+
// Builds the sync recognize request
49+
RecognitionConfig config = RecognitionConfig.newBuilder()
50+
.setEncoding(AudioEncoding.LINEAR16)
51+
.setSampleRateHertz(16000)
52+
.setLanguageCode("en-US")
53+
.build();
54+
RecognitionAudio audio = RecognitionAudio.newBuilder()
55+
.setContent(audioBytes)
56+
.build();
5757

58-
// Performs speech recognition on the audio file
59-
RecognizeResponse response = speech.recognize(config, audio);
60-
List<SpeechRecognitionResult> results = response.getResultsList();
58+
// Performs speech recognition on the audio file
59+
RecognizeResponse response = speechClient.recognize(config, audio);
60+
List<SpeechRecognitionResult> results = response.getResultsList();
6161

62-
for (SpeechRecognitionResult result: results) {
63-
List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList();
64-
for (SpeechRecognitionAlternative alternative: alternatives) {
65-
System.out.printf("Transcription: %s%n", alternative.getTranscript());
62+
for (SpeechRecognitionResult result : results) {
63+
List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList();
64+
for (SpeechRecognitionAlternative alternative : alternatives) {
65+
System.out.printf("Transcription: %s%n", alternative.getTranscript());
66+
}
6667
}
6768
}
68-
speech.close();
6969
}
7070
}
7171
// [END speech_quickstart]

0 commit comments

Comments
 (0)