Skip to content

Commit

Permalink
samples: refactor quickstart to use a gcs file (#378)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
b-loved-dreamer committed Dec 14, 2020
1 parent 42c0f42 commit 5e3e78e
Showing 1 changed file with 2 additions and 7 deletions.
Expand Up @@ -39,12 +39,7 @@ public static void main(String... args) throws Exception {
try (SpeechClient speechClient = SpeechClient.create()) {

// The path to the audio file to transcribe
String fileName = "./resources/audio.raw";

// Reads the audio file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString audioBytes = ByteString.copyFrom(data);
String gcsUri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw";

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

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

0 comments on commit 5e3e78e

Please sign in to comment.