Skip to content

Commit 5e3e78e

Browse files
samples: refactor quickstart to use a gcs file (#378)
* feat: added a new sample * fix: fixed region tag * fix: fixed indentation * fix: renamed test duplicate * fix: fixed consecutive capital letter style error * feat: relocated newly added sample and respective test * feat: added missing imports * feat: added another missing imports * fix: harmonized exception handling * fix: harmonized exception handling * refactor: quickstart now uses a gcs resource file * fix: fixed errors
1 parent 42c0f42 commit 5e3e78e

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public static void main(String... args) throws Exception {
3939
try (SpeechClient speechClient = SpeechClient.create()) {
4040

4141
// The path to the audio file to transcribe
42-
String fileName = "./resources/audio.raw";
43-
44-
// Reads the audio file into memory
45-
Path path = Paths.get(fileName);
46-
byte[] data = Files.readAllBytes(path);
47-
ByteString audioBytes = ByteString.copyFrom(data);
42+
String gcsUri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw";
4843

4944
// Builds the sync recognize request
5045
RecognitionConfig config =
@@ -53,7 +48,7 @@ public static void main(String... args) throws Exception {
5348
.setSampleRateHertz(16000)
5449
.setLanguageCode("en-US")
5550
.build();
56-
RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(audioBytes).build();
51+
RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();
5752

5853
// Performs speech recognition on the audio file
5954
RecognizeResponse response = speechClient.recognize(config, audio);

0 commit comments

Comments
 (0)