diff --git a/speech/generated/resources/brooklyn_bridge.flac b/speech/generated/resources/brooklyn_bridge.flac deleted file mode 100644 index 0e101a55df7..00000000000 Binary files a/speech/generated/resources/brooklyn_bridge.flac and /dev/null differ diff --git a/speech/generated/resources/brooklyn_bridge.mp3 b/speech/generated/resources/brooklyn_bridge.mp3 deleted file mode 100644 index 97f9955c6f8..00000000000 Binary files a/speech/generated/resources/brooklyn_bridge.mp3 and /dev/null differ diff --git a/speech/generated/resources/brooklyn_bridge.raw b/speech/generated/resources/brooklyn_bridge.raw deleted file mode 100644 index 5ebf79d3c9c..00000000000 Binary files a/speech/generated/resources/brooklyn_bridge.raw and /dev/null differ diff --git a/speech/generated/resources/brooklyn_bridge.wav b/speech/generated/resources/brooklyn_bridge.wav deleted file mode 100644 index 044086e9141..00000000000 Binary files a/speech/generated/resources/brooklyn_bridge.wav and /dev/null differ diff --git a/speech/generated/resources/commercial_mono.wav b/speech/generated/resources/commercial_mono.wav deleted file mode 100644 index e6b9ed434f9..00000000000 Binary files a/speech/generated/resources/commercial_mono.wav and /dev/null differ diff --git a/speech/generated/resources/hello.raw b/speech/generated/resources/hello.raw deleted file mode 100644 index b5b46450082..00000000000 Binary files a/speech/generated/resources/hello.raw and /dev/null differ diff --git a/speech/generated/resources/hello.wav b/speech/generated/resources/hello.wav deleted file mode 100644 index 69b506936a3..00000000000 Binary files a/speech/generated/resources/hello.wav and /dev/null differ diff --git a/speech/generated/resources/multi.flac b/speech/generated/resources/multi.flac deleted file mode 100644 index c550e0f42a1..00000000000 Binary files a/speech/generated/resources/multi.flac and /dev/null differ diff --git a/speech/generated/resources/multi.wav b/speech/generated/resources/multi.wav deleted file mode 100644 index 7f71d74b951..00000000000 Binary files a/speech/generated/resources/multi.wav and /dev/null differ diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsync.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsync.java deleted file mode 100644 index ffe52f0185e..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsync.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "speech_transcribe_async") -// sample-metadata: -// title: Transcribe Audio File using Long Running Operation (Local File) (LRO) -// description: Transcribe a long audio file using asynchronous speech recognition -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeAsync [--args='[--local_file_path "resources/brooklyn_bridge.raw"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; -import com.google.cloud.speech.v1.LongRunningRecognizeRequest; -import com.google.cloud.speech.v1.LongRunningRecognizeResponse; -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeAsync { - // [START speech_transcribe_async] - /* - * Please include the following imports to run this sample. - * - * import com.google.api.gax.longrunning.OperationFuture; - * import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; - * import com.google.cloud.speech.v1.LongRunningRecognizeRequest; - * import com.google.cloud.speech.v1.LongRunningRecognizeResponse; - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleLongRunningRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/brooklyn_bridge.raw"; - sampleLongRunningRecognize(localFilePath); - } - - /** - * Transcribe a long audio file using asynchronous speech recognition - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleLongRunningRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio - String languageCode = "en-US"; - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 16000; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.LINEAR16; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setLanguageCode(languageCode) - .setSampleRateHertz(sampleRateHertz) - .setEncoding(encoding) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - LongRunningRecognizeRequest request = - LongRunningRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - OperationFuture future = - speechClient.longRunningRecognizeAsync(request); - - System.out.println("Waiting for operation to complete..."); - LongRunningRecognizeResponse response = future.get(); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_async] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/brooklyn_bridge.raw"); - - sampleLongRunningRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncGcs.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncGcs.java deleted file mode 100644 index 519c7626658..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncGcs.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "speech_transcribe_async_gcs") -// sample-metadata: -// title: Transcript Audio File using Long Running Operation (Cloud Storage) (LRO) -// description: Transcribe long audio file from Cloud Storage using asynchronous speech recognition -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeAsyncGcs [--args='[--storage_uri "gs://cloud-samples-data/speech/brooklyn_bridge.raw"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; -import com.google.cloud.speech.v1.LongRunningRecognizeRequest; -import com.google.cloud.speech.v1.LongRunningRecognizeResponse; -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeAsyncGcs { - // [START speech_transcribe_async_gcs] - /* - * Please include the following imports to run this sample. - * - * import com.google.api.gax.longrunning.OperationFuture; - * import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; - * import com.google.cloud.speech.v1.LongRunningRecognizeRequest; - * import com.google.cloud.speech.v1.LongRunningRecognizeResponse; - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - */ - - public static void sampleLongRunningRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"; - sampleLongRunningRecognize(storageUri); - } - - /** - * Transcribe long audio file from Cloud Storage using asynchronous speech recognition - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - */ - public static void sampleLongRunningRecognize(String storageUri) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 16000; - - // The language of the supplied audio - String languageCode = "en-US"; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.LINEAR16; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setSampleRateHertz(sampleRateHertz) - .setLanguageCode(languageCode) - .setEncoding(encoding) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - LongRunningRecognizeRequest request = - LongRunningRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - OperationFuture future = - speechClient.longRunningRecognizeAsync(request); - - System.out.println("Waiting for operation to complete..."); - LongRunningRecognizeResponse response = future.get(); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_async_gcs] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/brooklyn_bridge.raw"); - - sampleLongRunningRecognize(storageUri); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncWordTimeOffsetsGcs.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncWordTimeOffsetsGcs.java deleted file mode 100644 index 02196b3751f..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeAsyncWordTimeOffsetsGcs.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "speech_transcribe_async_word_time_offsets_gcs") -// sample-metadata: -// title: Getting word timestamps (Cloud Storage) (LRO) -// description: Print start and end time of each word spoken in audio file from Cloud Storage -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeAsyncWordTimeOffsetsGcs [--args='[--storage_uri "gs://cloud-samples-data/speech/brooklyn_bridge.flac"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; -import com.google.cloud.speech.v1.LongRunningRecognizeRequest; -import com.google.cloud.speech.v1.LongRunningRecognizeResponse; -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.cloud.speech.v1.WordInfo; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeAsyncWordTimeOffsetsGcs { - // [START speech_transcribe_async_word_time_offsets_gcs] - /* - * Please include the following imports to run this sample. - * - * import com.google.api.gax.longrunning.OperationFuture; - * import com.google.cloud.speech.v1.LongRunningRecognizeMetadata; - * import com.google.cloud.speech.v1.LongRunningRecognizeRequest; - * import com.google.cloud.speech.v1.LongRunningRecognizeResponse; - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.cloud.speech.v1.WordInfo; - */ - - public static void sampleLongRunningRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/brooklyn_bridge.flac"; - sampleLongRunningRecognize(storageUri); - } - - /** - * Print start and end time of each word spoken in audio file from Cloud Storage - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - */ - public static void sampleLongRunningRecognize(String storageUri) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // When enabled, the first result returned by the API will include a list - // of words and the start and end time offsets (timestamps) for those words. - boolean enableWordTimeOffsets = true; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEnableWordTimeOffsets(enableWordTimeOffsets) - .setLanguageCode(languageCode) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - LongRunningRecognizeRequest request = - LongRunningRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - OperationFuture future = - speechClient.longRunningRecognizeAsync(request); - - System.out.println("Waiting for operation to complete..."); - LongRunningRecognizeResponse response = future.get(); - // The first result includes start and end time word offsets - SpeechRecognitionResult result = response.getResultsList().get(0); - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - // Print the start and end time of each word - for (WordInfo word : alternative.getWordsList()) { - System.out.printf("Word: %s\n", word.getWord()); - System.out.printf( - "Start time: %s seconds %s nanos\n", - word.getStartTime().getSeconds(), word.getStartTime().getNanos()); - System.out.printf( - "End time: %s seconds %s nanos\n", - word.getEndTime().getSeconds(), word.getEndTime().getNanos()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_async_word_time_offsets_gcs] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/brooklyn_bridge.flac"); - - sampleLongRunningRecognize(storageUri); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeEnhancedModel.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeEnhancedModel.java deleted file mode 100644 index 2bc23ff378d..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeEnhancedModel.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_enhanced_model") -// sample-metadata: -// title: Using Enhanced Models (Local File) -// description: Transcribe a short audio file using an enhanced model -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeEnhancedModel [--args='[--local_file_path "resources/hello.wav"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeEnhancedModel { - // [START speech_transcribe_enhanced_model] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/hello.wav"; - sampleRecognize(localFilePath); - } - - /** - * Transcribe a short audio file using an enhanced model - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The enhanced model to use, e.g. phone_call - String model = "phone_call"; - - // Use an enhanced model for speech recognition (when set to true). - // Project must be eligible for requesting enhanced models. - // Enhanced speech models require that you opt-in to data logging. - boolean useEnhanced = true; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setModel(model) - .setUseEnhanced(useEnhanced) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_enhanced_model] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/hello.wav"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelection.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelection.java deleted file mode 100644 index 435f296d6bc..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelection.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_model_selection") -// sample-metadata: -// title: Selecting a Transcription Model (Local File) -// description: Transcribe a short audio file using a specified transcription model -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeModelSelection [--args='[--local_file_path "resources/hello.wav"] [--model "phone_call"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeModelSelection { - // [START speech_transcribe_model_selection] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/hello.wav"; - String model = "phone_call"; - sampleRecognize(localFilePath, model); - } - - /** - * Transcribe a short audio file using a specified transcription model - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - * @param model The transcription model to use, e.g. video, phone_call, default For a list of - * available transcription models, see: - * https://cloud.google.com/speech-to-text/docs/transcription-model#transcription_models - */ - public static void sampleRecognize(String localFilePath, String model) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder().setModel(model).setLanguageCode(languageCode).build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_model_selection] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - options.addOption(Option.builder("").required(false).hasArg(true).longOpt("model").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/hello.wav"); - String model = cl.getOptionValue("model", "phone_call"); - - sampleRecognize(localFilePath, model); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelectionGcs.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelectionGcs.java deleted file mode 100644 index 93e81906b61..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeModelSelectionGcs.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_model_selection_gcs") -// sample-metadata: -// title: Selecting a Transcription Model (Cloud Storage) -// description: Transcribe a short audio file from Cloud Storage using a specified transcription model -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeModelSelectionGcs [--args='[--storage_uri "gs://cloud-samples-data/speech/hello.wav"] [--model "phone_call"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeModelSelectionGcs { - // [START speech_transcribe_model_selection_gcs] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/hello.wav"; - String model = "phone_call"; - sampleRecognize(storageUri, model); - } - - /** - * Transcribe a short audio file from Cloud Storage using a specified transcription model - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - * @param model The transcription model to use, e.g. video, phone_call, default For a list of - * available transcription models, see: - * https://cloud.google.com/speech-to-text/docs/transcription-model#transcription_models - */ - public static void sampleRecognize(String storageUri, String model) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder().setModel(model).setLanguageCode(languageCode).build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_model_selection_gcs] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - options.addOption(Option.builder("").required(false).hasArg(true).longOpt("model").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/hello.wav"); - String model = cl.getOptionValue("model", "phone_call"); - - sampleRecognize(storageUri, model); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannel.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannel.java deleted file mode 100644 index 5eb75c0173c..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannel.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_multichannel") -// sample-metadata: -// title: Multi-Channel Audio Transcription (Local File) -// description: Transcribe a short audio file with multiple channels -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeMultichannel [--args='[--local_file_path "resources/multi.wav"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeMultichannel { - // [START speech_transcribe_multichannel] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/multi.wav"; - sampleRecognize(localFilePath); - } - - /** - * Transcribe a short audio file with multiple channels - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The number of channels in the input audio file (optional) - int audioChannelCount = 2; - - // When set to true, each audio channel will be recognized separately. - // The recognition result will contain a channel_tag field to state which - // channel that result belongs to - boolean enableSeparateRecognitionPerChannel = true; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setAudioChannelCount(audioChannelCount) - .setEnableSeparateRecognitionPerChannel(enableSeparateRecognitionPerChannel) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // channelTag to recognize which audio channel this result is for - System.out.printf("Channel tag: %s\n", result.getChannelTag()); - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_multichannel] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/multi.wav"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannelGcs.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannelGcs.java deleted file mode 100644 index f45c78739d2..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeMultichannelGcs.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_multichannel_gcs") -// sample-metadata: -// title: Multi-Channel Audio Transcription (Cloud Storage) -// description: Transcribe a short audio file from Cloud Storage with multiple channels -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeMultichannelGcs [--args='[--storage_uri "gs://cloud-samples-data/speech/multi.wav"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeMultichannelGcs { - // [START speech_transcribe_multichannel_gcs] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/multi.wav"; - sampleRecognize(storageUri); - } - - /** - * Transcribe a short audio file from Cloud Storage with multiple channels - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - */ - public static void sampleRecognize(String storageUri) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The number of channels in the input audio file (optional) - int audioChannelCount = 2; - - // When set to true, each audio channel will be recognized separately. - // The recognition result will contain a channel_tag field to state which - // channel that result belongs to - boolean enableSeparateRecognitionPerChannel = true; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setAudioChannelCount(audioChannelCount) - .setEnableSeparateRecognitionPerChannel(enableSeparateRecognitionPerChannel) - .setLanguageCode(languageCode) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // channelTag to recognize which audio channel this result is for - System.out.printf("Channel tag: %s\n", result.getChannelTag()); - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_multichannel_gcs] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/multi.wav"); - - sampleRecognize(storageUri); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSync.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSync.java deleted file mode 100644 index a58d9cb422d..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSync.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_sync") -// sample-metadata: -// title: Transcribe Audio File (Local File) -// description: Transcribe a short audio file using synchronous speech recognition -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeSync [--args='[--local_file_path "resources/brooklyn_bridge.raw"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeSync { - // [START speech_transcribe_sync] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/brooklyn_bridge.raw"; - sampleRecognize(localFilePath); - } - - /** - * Transcribe a short audio file using synchronous speech recognition - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio - String languageCode = "en-US"; - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 16000; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.LINEAR16; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setLanguageCode(languageCode) - .setSampleRateHertz(sampleRateHertz) - .setEncoding(encoding) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_sync] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/brooklyn_bridge.raw"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSyncGcs.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSyncGcs.java deleted file mode 100644 index d4b821f28b8..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/SpeechTranscribeSyncGcs.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_sync_gcs") -// sample-metadata: -// title: Transcript Audio File (Cloud Storage) -// description: Transcribe short audio file from Cloud Storage using synchronous speech recognition -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1.SpeechTranscribeSyncGcs [--args='[--storage_uri "gs://cloud-samples-data/speech/brooklyn_bridge.raw"]'] - -package com.google.cloud.examples.speech.v1; - -import com.google.cloud.speech.v1.RecognitionAudio; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.RecognizeRequest; -import com.google.cloud.speech.v1.RecognizeResponse; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.SpeechRecognitionResult; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeSyncGcs { - // [START speech_transcribe_sync_gcs] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1.RecognitionAudio; - * import com.google.cloud.speech.v1.RecognitionConfig; - * import com.google.cloud.speech.v1.RecognizeRequest; - * import com.google.cloud.speech.v1.RecognizeResponse; - * import com.google.cloud.speech.v1.SpeechClient; - * import com.google.cloud.speech.v1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1.SpeechRecognitionResult; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"; - sampleRecognize(storageUri); - } - - /** - * Transcribe short audio file from Cloud Storage using synchronous speech recognition - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - */ - public static void sampleRecognize(String storageUri) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 16000; - - // The language of the supplied audio - String languageCode = "en-US"; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.LINEAR16; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setSampleRateHertz(sampleRateHertz) - .setLanguageCode(languageCode) - .setEncoding(encoding) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_sync_gcs] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/brooklyn_bridge.raw"); - - sampleRecognize(storageUri); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/speech.v1.java.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/speech.v1.java.yaml deleted file mode 100644 index a82089734b2..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/speech.v1.java.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -type: manifest/samples -schema_version: 3 -java: &java - environment: "java" - bin: "mvn exec:java" - base_path: "samples/src/main/java/com/google/cloud/examples/speech/v1" - package: "com.google.cloud.examples.speech.v1" - invocation: "{bin} -Dexec.mainClass={class} -Dexec.args='@args'" -samples: -- <<: *java - sample: "speech_transcribe_model_selection_gcs" - path: "{base_path}/SpeechTranscribeModelSelectionGcs.java" - class: "{package}.SpeechTranscribeModelSelectionGcs" - region_tag: "speech_transcribe_model_selection_gcs" -- <<: *java - sample: "speech_transcribe_model_selection" - path: "{base_path}/SpeechTranscribeModelSelection.java" - class: "{package}.SpeechTranscribeModelSelection" - region_tag: "speech_transcribe_model_selection" -- <<: *java - sample: "speech_transcribe_multichannel_gcs" - path: "{base_path}/SpeechTranscribeMultichannelGcs.java" - class: "{package}.SpeechTranscribeMultichannelGcs" - region_tag: "speech_transcribe_multichannel_gcs" -- <<: *java - sample: "speech_transcribe_sync_gcs" - path: "{base_path}/SpeechTranscribeSyncGcs.java" - class: "{package}.SpeechTranscribeSyncGcs" - region_tag: "speech_transcribe_sync_gcs" -- <<: *java - sample: "speech_transcribe_enhanced_model" - path: "{base_path}/SpeechTranscribeEnhancedModel.java" - class: "{package}.SpeechTranscribeEnhancedModel" - region_tag: "speech_transcribe_enhanced_model" -- <<: *java - sample: "speech_transcribe_multichannel" - path: "{base_path}/SpeechTranscribeMultichannel.java" - class: "{package}.SpeechTranscribeMultichannel" - region_tag: "speech_transcribe_multichannel" -- <<: *java - sample: "speech_transcribe_sync" - path: "{base_path}/SpeechTranscribeSync.java" - class: "{package}.SpeechTranscribeSync" - region_tag: "speech_transcribe_sync" -- <<: *java - sample: "speech_transcribe_async" - path: "{base_path}/SpeechTranscribeAsync.java" - class: "{package}.SpeechTranscribeAsync" - region_tag: "speech_transcribe_async" -- <<: *java - sample: "speech_transcribe_async_gcs" - path: "{base_path}/SpeechTranscribeAsyncGcs.java" - class: "{package}.SpeechTranscribeAsyncGcs" - region_tag: "speech_transcribe_async_gcs" -- <<: *java - sample: "speech_transcribe_async_word_time_offsets_gcs" - path: "{base_path}/SpeechTranscribeAsyncWordTimeOffsetsGcs.java" - class: "{package}.SpeechTranscribeAsyncWordTimeOffsetsGcs" - region_tag: "speech_transcribe_async_word_time_offsets_gcs" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async.test.yaml deleted file mode 100644 index f26cfbabc53..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async.test.yaml +++ /dev/null @@ -1,28 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Transcribe Audio File using Long Running Operation (Local File) (LRO) - cases: - - # This sample should default to using brooklyn_bridge.raw - # with explicitly configured sample_rate_hertz and encoding - - name: speech_transcribe_async (no arguments) - spec: - - call: - sample: speech_transcribe_async - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - # Confirm that another file can be transcribed (use another .raw PCM file) - - name: speech_transcribe_async (--local_file_path) - spec: - - call: - sample: speech_transcribe_async - params: - local_file_path: - literal: "resources/hello.raw" - - assert_contains: - - literal: "hello" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_gcs.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_gcs.test.yaml deleted file mode 100644 index d3d83133e78..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_gcs.test.yaml +++ /dev/null @@ -1,28 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Transcript Audio File using Long Running Operation (Cloud Storage) (LRO) - cases: - - # This sample should default to using gs://cloud-samples-data/brooklyn_bridge.raw - # with explicitly configured sample_rate_hertz and encoding - - name: speech_transcribe_async_gcs (no arguments) - spec: - - call: - sample: speech_transcribe_async_gcs - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - # Confirm that another file can be transcribed (use another .raw PCM file) - - name: speech_transcribe_async_gcs (--storage_uri) - spec: - - call: - sample: speech_transcribe_async_gcs - params: - storage_uri: - literal: "gs://cloud-samples-data/speech/hello.raw" - - assert_contains: - - literal: "hello" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_word_time_offsets_gcs.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_word_time_offsets_gcs.test.yaml deleted file mode 100644 index 11784726db7..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_async_word_time_offsets_gcs.test.yaml +++ /dev/null @@ -1,37 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Getting word timestamps (Cloud Storage) (LRO) - cases: - - # This sample should default to using gs://cloud-samples-data/speech/brooklyn_bridge.flac - - name: speech_transcribe_async_word_time_offsets_gcs (no arguments) - spec: - - call: - sample: speech_transcribe_async_word_time_offsets_gcs - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - literal: "Word: how" - - literal: "Word: old" - - literal: "Word: is" - - literal: "Start time: 0 seconds" - - literal: "End time: 1 seconds" - - # Confirm that another file can be transcribed (use another file) - - name: speech_transcribe_async_word_time_offsets_gcs (--storage_uri) - spec: - - call: - sample: speech_transcribe_async_word_time_offsets_gcs - params: - storage_uri: - literal: "gs://cloud-samples-data/speech/multi.flac" - - assert_contains: - - literal: "how are you doing" - - literal: "Word: how" - - literal: "Word: are" - - literal: "Word: you" - - literal: "Start time: 0 seconds" - - literal: "End time: 1 seconds" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_enhanced_model.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_enhanced_model.test.yaml deleted file mode 100644 index 6eab33b5279..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_enhanced_model.test.yaml +++ /dev/null @@ -1,29 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Using Enhanced Models (Local File) - cases: - - # This sample should default to using hello.wav - # and the phone_call model (only currently available enhanced model) - # - # Note: if the project used to run these tests isn't eligible for - # enhanced models, you will receive an error. - - name: speech_transcribe_enhanced_model (no arguments) - spec: - - call: - sample: speech_transcribe_enhanced_model - - assert_contains: - - literal: "hello" - - # Confirm that another file can be transcribed (use another .wav file) - - name: speech_transcribe_enhanced_model (--local_file_path) - spec: - - call: - sample: speech_transcribe_enhanced_model - params: - local_file_path: - literal: "resources/commercial_mono.wav" - - assert_contains: - - literal: "Chrome" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection.test.yaml deleted file mode 100644 index b5ec2d90290..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection.test.yaml +++ /dev/null @@ -1,52 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Selecting a Transcription Model (Local File) - cases: - - # This sample should default to using hello.wav - # and the phone_call model - - name: speech_transcribe_model_selection (no arguments) - spec: - - call: - sample: speech_transcribe_model_selection - - assert_contains: - - literal: "Hello" - - # Confirm that another file can be transcribed (use another .wav file) - - name: speech_transcribe_model_selection (--local_file_path) - spec: - - call: - sample: speech_transcribe_model_selection - params: - local_file_path: - literal: "resources/commercial_mono.wav" - - assert_contains: - - literal: "Chrome" - - # Confirm that --model can be specified and the sample does not blow up - # - # Note: we are not using example audio files which result in deterministically - # different results when using different models. so we simply test - # that regular transcription continues to work. - - name: speech_transcribe_model_selection (--model) - spec: - - call: - sample: speech_transcribe_model_selection - params: - model: - literal: video - - assert_contains: - - literal: "hello" - - # Confirm that --model is being passed through by providing an invalid model - - name: speech_transcribe_model_selection (invalid --model) - spec: - - call_may_fail: - sample: speech_transcribe_model_selection - params: - model: - literal: I_DONT_EXIST - - assert_contains: - - literal: "Incorrect model specified" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection_gcs.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection_gcs.test.yaml deleted file mode 100644 index 60c45c975d7..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_model_selection_gcs.test.yaml +++ /dev/null @@ -1,52 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Selecting a Transcription Model (Cloud Storage) - cases: - - # This sample should default to using gs://cloud-samples-data/speech/hello.wav - # and the phone_call model - - name: speech_transcribe_model_selection_gcs (no arguments) - spec: - - call: - sample: speech_transcribe_model_selection_gcs - - assert_contains: - - literal: "Hello" - - # Confirm that another file can be transcribed (use another .wav file) - - name: speech_transcribe_model_selection_gcs (--local_file_path) - spec: - - call: - sample: speech_transcribe_model_selection_gcs - params: - storage_uri: - literal: "gs://cloud-samples-data/speech/commercial_mono.wav" - - assert_contains: - - literal: "Chrome" - - # Confirm that --model can be specified and the sample does not blow up - # - # Note: we are not using example audio files which result in deterministically - # different results when using different models. so we simply test - # that regular transcription continues to work. - - name: speech_transcribe_model_selection_gcs (--model) - spec: - - call: - sample: speech_transcribe_model_selection_gcs - params: - model: - literal: video - - assert_contains: - - literal: "hello" - - # Confirm that --model is being passed through by providing an invalid model - - name: speech_transcribe_model_selection_gcs (invalid --model) - spec: - - call_may_fail: - sample: speech_transcribe_model_selection_gcs - params: - model: - literal: I_DONT_EXIST - - assert_contains: - - literal: "Incorrect model specified" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel.test.yaml deleted file mode 100644 index 9d5379dc99c..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel.test.yaml +++ /dev/null @@ -1,31 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Multi-Channel Audio Transcription (Local File) - cases: - - # This sample should default to using multi.wav (2 channels) - - name: speech_transcribe_multichannel (no arguments) - spec: - - call: - sample: speech_transcribe_multichannel - - assert_contains: - - literal: "Channel tag: 1" - - literal: "Channel tag: 2" - - literal: "how are you doing" - - # Confirm that another file can be transcribed (use another 2 channel .wav file) - - name: speech_transcribe_multichannel (--local_file_path) - spec: - - call: - sample: speech_transcribe_multichannel - params: - local_file_path: - literal: "resources/brooklyn_bridge.wav" - - assert_contains: - # Only one channel of data is present in brooklyn_bridge.wav - - literal: "Channel tag:" - - literal: "how old is the Brooklyn Bridge" - - assert_not_contains: - - literal: "how are you doing" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel_gcs.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel_gcs.test.yaml deleted file mode 100644 index 64c9340ce0e..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_multichannel_gcs.test.yaml +++ /dev/null @@ -1,32 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Multi-Channel Audio Transcription (Cloud Storage) - cases: - - # This sample should default to using gs://cloud-samples-data/speech/multi.wav - # with 2 audio channels of data - - name: speech_transcribe_multichannel_gcs (no arguments) - spec: - - call: - sample: speech_transcribe_multichannel_gcs - - assert_contains: - - literal: "Channel tag: 1" - - literal: "Channel tag: 2" - - literal: "how are you doing" - - # Confirm that another file can be transcribed (use another 2 channel .wav file) - - name: speech_transcribe_multichannel_gcs (--storage_uri) - spec: - - call: - sample: speech_transcribe_multichannel_gcs - params: - storage_uri: - literal: "gs://cloud-samples-data/speech/brooklyn_bridge.wav" - - assert_contains: - # Only one channel of data is present in brooklyn_bridge.wav - - literal: "Channel tag:" - - literal: "how old is the Brooklyn Bridge" - - assert_not_contains: - - literal: "how are you doing" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync.test.yaml deleted file mode 100644 index 47cc8c1a48e..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync.test.yaml +++ /dev/null @@ -1,28 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Transcribe Audio File (Local File) - cases: - - # This sample should default to using brooklyn_bridge.raw - # with explicitly configured sample_rate_hertz and encoding - - name: speech_transcribe_sync (no arguments) - spec: - - call: - sample: speech_transcribe_sync - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - # Confirm that another file can be transcribed (use another .raw PCM file) - - name: speech_transcribe_sync (--local_file_path) - spec: - - call: - sample: speech_transcribe_sync - params: - local_file_path: - literal: "resources/hello.raw" - - assert_contains: - - literal: "hello" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync_gcs.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync_gcs.test.yaml deleted file mode 100644 index 3defdf28930..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1/test/speech_transcribe_sync_gcs.test.yaml +++ /dev/null @@ -1,28 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Transcript Audio File (Cloud Storage) - cases: - - # This sample should default to using gs://cloud-samples-data/speech/brooklyn_bridge.raw - # with explicitly configured sample_rate_hertz and encoding - - name: speech_transcribe_sync_gcs (no arguments) - spec: - - call: - sample: speech_transcribe_sync_gcs - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - # Confirm that another file can be transcribed (use another .raw PCM file) - - name: speech_transcribe_sync_gcs (--storage_uri) - spec: - - call: - sample: speech_transcribe_sync_gcs - params: - storage_uri: - literal: "gs://cloud-samples-data/speech/hello.raw" - - assert_contains: - - literal: "hello" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechAdaptationBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechAdaptationBeta.java deleted file mode 100644 index 9ebda210efe..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechAdaptationBeta.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_adaptation_beta") -// sample-metadata: -// title: Speech Adaptation (Cloud Storage) -// description: Transcribe a short audio file with speech adaptation. -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechAdaptationBeta [--args='[--storage_uri "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"] [--phrase "Brooklyn Bridge"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechContext; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechAdaptationBeta { - // [START speech_adaptation_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechContext; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import java.util.Arrays; - * import java.util.List; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"; - String phrase = "Brooklyn Bridge"; - sampleRecognize(storageUri, phrase); - } - - /** - * Transcribe a short audio file with speech adaptation. - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - * @param phrase Phrase "hints" help recognize the specified phrases from your audio. - */ - public static void sampleRecognize(String storageUri, String phrase) { - try (SpeechClient speechClient = SpeechClient.create()) { - List phrases = Arrays.asList(phrase); - - // Hint Boost. This value increases the probability that a specific - // phrase will be recognized over other similar sounding phrases. - // The higher the boost, the higher the chance of false positive - // recognition as well. Can accept wide range of positive values. - // Most use cases are best served with values between 0 and 20. - // Using a binary search happroach may help you find the optimal value. - float boost = 20.0F; - SpeechContext speechContextsElement = - SpeechContext.newBuilder().addAllPhrases(phrases).setBoost(boost).build(); - List speechContexts = Arrays.asList(speechContextsElement); - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 44100; - - // The language of the supplied audio - String languageCode = "en-US"; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.MP3; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .addAllSpeechContexts(speechContexts) - .setSampleRateHertz(sampleRateHertz) - .setLanguageCode(languageCode) - .setEncoding(encoding) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_adaptation_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - options.addOption(Option.builder("").required(false).hasArg(true).longOpt("phrase").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"); - String phrase = cl.getOptionValue("phrase", "Brooklyn Bridge"); - - sampleRecognize(storageUri, phrase); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechContextsClassesBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechContextsClassesBeta.java deleted file mode 100644 index f42742c2444..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechContextsClassesBeta.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_contexts_classes_beta") -// sample-metadata: -// title: Using Context Classes (Cloud Storage) -// description: Transcribe a short audio file with static context classes. -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechContextsClassesBeta [--args='[--storage_uri "gs://cloud-samples-data/speech/time.mp3"] [--phrase "$TIME"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechContext; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechContextsClassesBeta { - // [START speech_contexts_classes_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechContext; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import java.util.Arrays; - * import java.util.List; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/time.mp3"; - String phrase = "$TIME"; - sampleRecognize(storageUri, phrase); - } - - /** - * Transcribe a short audio file with static context classes. - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - * @param phrase Phrase "hints" help recognize the specified phrases from your audio. In this - * sample we are using a static class phrase ($TIME). Classes represent groups of words that - * represent common concepts that occur in natural language. - */ - public static void sampleRecognize(String storageUri, String phrase) { - try (SpeechClient speechClient = SpeechClient.create()) { - List phrases = Arrays.asList(phrase); - SpeechContext speechContextsElement = - SpeechContext.newBuilder().addAllPhrases(phrases).build(); - List speechContexts = Arrays.asList(speechContextsElement); - - // The language of the supplied audio - String languageCode = "en-US"; - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 24000; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.MP3; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .addAllSpeechContexts(speechContexts) - .setLanguageCode(languageCode) - .setSampleRateHertz(sampleRateHertz) - .setEncoding(encoding) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_contexts_classes_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - options.addOption(Option.builder("").required(false).hasArg(true).longOpt("phrase").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/time.mp3"); - String phrase = cl.getOptionValue("phrase", "$TIME"); - - sampleRecognize(storageUri, phrase); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechQuickstartBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechQuickstartBeta.java deleted file mode 100644 index ebeebb61923..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechQuickstartBeta.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_quickstart_beta") -// sample-metadata: -// title: Quickstart Beta -// description: Performs synchronous speech recognition on an audio file -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechQuickstartBeta [--args='[--storage_uri "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechQuickstartBeta { - // [START speech_quickstart_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String storageUri = "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"; - sampleRecognize(storageUri); - } - - /** - * Performs synchronous speech recognition on an audio file - * - * @param storageUri URI for audio file in Cloud Storage, e.g. gs://[BUCKET]/[FILE] - */ - public static void sampleRecognize(String storageUri) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio - String languageCode = "en-US"; - - // Sample rate in Hertz of the audio data sent - int sampleRateHertz = 44100; - - // Encoding of audio data sent. This sample sets this explicitly. - // This field is optional for FLAC and WAV audio formats. - RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.MP3; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setLanguageCode(languageCode) - .setSampleRateHertz(sampleRateHertz) - .setEncoding(encoding) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(storageUri).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_quickstart_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("storage_uri").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String storageUri = - cl.getOptionValue("storage_uri", "gs://cloud-samples-data/speech/brooklyn_bridge.mp3"); - - sampleRecognize(storageUri); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeAutoPunctuationBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeAutoPunctuationBeta.java deleted file mode 100644 index f09386703ce..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeAutoPunctuationBeta.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_auto_punctuation_beta") -// sample-metadata: -// title: Getting punctuation in results (Local File) (Beta) -// description: Transcribe a short audio file with punctuation -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechTranscribeAutoPunctuationBeta [--args='[--local_file_path "resources/commercial_mono.wav"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeAutoPunctuationBeta { - // [START speech_transcribe_auto_punctuation_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/commercial_mono.wav"; - sampleRecognize(localFilePath); - } - - /** - * Transcribe a short audio file with punctuation - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // When enabled, trascription results may include punctuation - // (available for select languages). - boolean enableAutomaticPunctuation = true; - - // The language of the supplied audio. Even though additional languages are - // provided by alternative_language_codes, a primary language is still required. - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEnableAutomaticPunctuation(enableAutomaticPunctuation) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_auto_punctuation_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/commercial_mono.wav"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeDiarizationBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeDiarizationBeta.java deleted file mode 100644 index 5608ca26315..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeDiarizationBeta.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("LongRunningRequestAsync", "speech_transcribe_diarization_beta") -// sample-metadata: -// title: Separating different speakers (Local File) (LRO) (Beta) -// description: Print confidence level for individual words in a transcription of a short audio file -// Separating different speakers in an audio file recording -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechTranscribeDiarizationBeta [--args='[--local_file_path "resources/commercial_mono.wav"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata; -import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest; -import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse; -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import com.google.cloud.speech.v1p1beta1.WordInfo; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeDiarizationBeta { - // [START speech_transcribe_diarization_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.api.gax.longrunning.OperationFuture; - * import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata; - * import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import com.google.cloud.speech.v1p1beta1.WordInfo; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleLongRunningRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/commercial_mono.wav"; - sampleLongRunningRecognize(localFilePath); - } - - /** - * Print confidence level for individual words in a transcription of a short audio file Separating - * different speakers in an audio file recording - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleLongRunningRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // If enabled, each word in the first alternative of each result will be - // tagged with a speaker tag to identify the speaker. - boolean enableSpeakerDiarization = true; - - // Optional. Specifies the estimated number of speakers in the conversation. - int diarizationSpeakerCount = 2; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEnableSpeakerDiarization(enableSpeakerDiarization) - .setDiarizationSpeakerCount(diarizationSpeakerCount) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - LongRunningRecognizeRequest request = - LongRunningRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - OperationFuture future = - speechClient.longRunningRecognizeAsync(request); - - System.out.println("Waiting for operation to complete..."); - LongRunningRecognizeResponse response = future.get(); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative has words tagged with speakers - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - // Print the speakerTag of each word - for (WordInfo word : alternative.getWordsList()) { - System.out.printf("Word: %s\n", word.getWord()); - System.out.printf("Speaker tag: %s\n", word.getSpeakerTag()); - } - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_diarization_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/commercial_mono.wav"); - - sampleLongRunningRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeMultilanguageBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeMultilanguageBeta.java deleted file mode 100644 index 31f4f0052d1..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeMultilanguageBeta.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_multilanguage_beta") -// sample-metadata: -// title: Detecting language spoken automatically (Local File) (Beta) -// description: Transcribe a short audio file with language detected from a list of possible languages -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechTranscribeMultilanguageBeta [--args='[--local_file_path "resources/brooklyn_bridge.flac"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeMultilanguageBeta { - // [START speech_transcribe_multilanguage_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - * import java.util.Arrays; - * import java.util.List; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/brooklyn_bridge.flac"; - sampleRecognize(localFilePath); - } - - /** - * Transcribe a short audio file with language detected from a list of possible languages - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The language of the supplied audio. Even though additional languages are - // provided by alternative_language_codes, a primary language is still required. - String languageCode = "fr"; - - // Specify up to 3 additional languages as possible alternative languages - // of the supplied audio. - String alternativeLanguageCodesElement = "es"; - String alternativeLanguageCodesElement2 = "en"; - List alternativeLanguageCodes = - Arrays.asList(alternativeLanguageCodesElement, alternativeLanguageCodesElement2); - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setLanguageCode(languageCode) - .addAllAlternativeLanguageCodes(alternativeLanguageCodes) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // The languageCode which was detected as the most likely being spoken in the audio - System.out.printf("Detected language: %s\n", result.getLanguageCode()); - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_multilanguage_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/brooklyn_bridge.flac"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeRecognitionMetadataBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeRecognitionMetadataBeta.java deleted file mode 100644 index 09602395172..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeRecognitionMetadataBeta.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_recognition_metadata_beta") -// sample-metadata: -// title: Adding recognition metadata (Local File) (Beta) -// description: Adds additional details short audio file included in this recognition request -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechTranscribeRecognitionMetadataBeta [--args='[--local_file_path "resources/commercial_mono.wav"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognitionMetadata; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeRecognitionMetadataBeta { - // [START speech_transcribe_recognition_metadata_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognitionMetadata; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/commercial_mono.wav"; - sampleRecognize(localFilePath); - } - - /** - * Adds additional details short audio file included in this recognition request - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // The use case of the audio, e.g. PHONE_CALL, DISCUSSION, PRESENTATION, et al. - RecognitionMetadata.InteractionType interactionType = - RecognitionMetadata.InteractionType.VOICE_SEARCH; - - // The kind of device used to capture the audio - RecognitionMetadata.RecordingDeviceType recordingDeviceType = - RecognitionMetadata.RecordingDeviceType.SMARTPHONE; - - // The device used to make the recording. - // Arbitrary string, e.g. 'Pixel XL', 'VoIP', 'Cardioid Microphone', or other value. - String recordingDeviceName = "Pixel 3"; - RecognitionMetadata metadata = - RecognitionMetadata.newBuilder() - .setInteractionType(interactionType) - .setRecordingDeviceType(recordingDeviceType) - .setRecordingDeviceName(recordingDeviceName) - .build(); - - // The language of the supplied audio. Even though additional languages are - // provided by alternative_language_codes, a primary language is still required. - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setMetadata(metadata) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - for (SpeechRecognitionResult result : response.getResultsList()) { - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_recognition_metadata_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/commercial_mono.wav"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeWordLevelConfidenceBeta.java b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeWordLevelConfidenceBeta.java deleted file mode 100644 index 6f174df79a0..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/SpeechTranscribeWordLevelConfidenceBeta.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// DO NOT EDIT! This is a generated sample ("Request", "speech_transcribe_word_level_confidence_beta") -// sample-metadata: -// title: Enabling word-level confidence (Local File) (Beta) -// description: Print confidence level for individual words in a transcription of a short audio file. -// usage: gradle run -PmainClass=com.google.cloud.examples.speech.v1p1beta1.SpeechTranscribeWordLevelConfidenceBeta [--args='[--local_file_path "resources/brooklyn_bridge.flac"]'] - -package com.google.cloud.examples.speech.v1p1beta1; - -import com.google.cloud.speech.v1p1beta1.RecognitionAudio; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.RecognizeRequest; -import com.google.cloud.speech.v1p1beta1.RecognizeResponse; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; -import com.google.cloud.speech.v1p1beta1.WordInfo; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -public class SpeechTranscribeWordLevelConfidenceBeta { - // [START speech_transcribe_word_level_confidence_beta] - /* - * Please include the following imports to run this sample. - * - * import com.google.cloud.speech.v1p1beta1.RecognitionAudio; - * import com.google.cloud.speech.v1p1beta1.RecognitionConfig; - * import com.google.cloud.speech.v1p1beta1.RecognizeRequest; - * import com.google.cloud.speech.v1p1beta1.RecognizeResponse; - * import com.google.cloud.speech.v1p1beta1.SpeechClient; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; - * import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult; - * import com.google.cloud.speech.v1p1beta1.WordInfo; - * import com.google.protobuf.ByteString; - * import java.nio.file.Files; - * import java.nio.file.Path; - * import java.nio.file.Paths; - */ - - public static void sampleRecognize() { - // TODO(developer): Replace these variables before running the sample. - String localFilePath = "resources/brooklyn_bridge.flac"; - sampleRecognize(localFilePath); - } - - /** - * Print confidence level for individual words in a transcription of a short audio file. - * - * @param localFilePath Path to local audio file, e.g. /path/audio.wav - */ - public static void sampleRecognize(String localFilePath) { - try (SpeechClient speechClient = SpeechClient.create()) { - - // When enabled, the first result returned by the API will include a list - // of words and the confidence level for each of those words. - boolean enableWordConfidence = true; - - // The language of the supplied audio - String languageCode = "en-US"; - RecognitionConfig config = - RecognitionConfig.newBuilder() - .setEnableWordConfidence(enableWordConfidence) - .setLanguageCode(languageCode) - .build(); - Path path = Paths.get(localFilePath); - byte[] data = Files.readAllBytes(path); - ByteString content = ByteString.copyFrom(data); - RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); - RecognizeRequest request = - RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - RecognizeResponse response = speechClient.recognize(request); - // The first result includes confidence levels per word - SpeechRecognitionResult result = response.getResultsList().get(0); - // First alternative is the most probable result - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - System.out.printf("Transcript: %s\n", alternative.getTranscript()); - // Print the confidence level of each word - for (WordInfo word : alternative.getWordsList()) { - System.out.printf("Word: %s\n", word.getWord()); - System.out.printf("Confidence: %s\n", word.getConfidence()); - } - } catch (Exception exception) { - System.err.println("Failed to create the client due to: " + exception); - } - } - // [END speech_transcribe_word_level_confidence_beta] - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption( - Option.builder("").required(false).hasArg(true).longOpt("local_file_path").build()); - - CommandLine cl = (new DefaultParser()).parse(options, args); - String localFilePath = cl.getOptionValue("local_file_path", "resources/brooklyn_bridge.flac"); - - sampleRecognize(localFilePath); - } -} diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/speech.v1p1beta1.java.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/speech.v1p1beta1.java.yaml deleted file mode 100644 index d03cc3ac625..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/speech.v1p1beta1.java.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -type: manifest/samples -schema_version: 3 -java: &java - environment: "java" - bin: "mvn exec:java" - base_path: "samples/src/main/java/com/google/cloud/examples/speech/v1p1beta1" - package: "com.google.cloud.examples.speech.v1p1beta1" - invocation: "{bin} -Dexec.mainClass={class} -Dexec.args='@args'" -samples: -- <<: *java - sample: "speech_contexts_classes_beta" - path: "{base_path}/SpeechContextsClassesBeta.java" - class: "{package}.SpeechContextsClassesBeta" - region_tag: "speech_contexts_classes_beta" -- <<: *java - sample: "speech_transcribe_auto_punctuation_beta" - path: "{base_path}/SpeechTranscribeAutoPunctuationBeta.java" - class: "{package}.SpeechTranscribeAutoPunctuationBeta" - region_tag: "speech_transcribe_auto_punctuation_beta" -- <<: *java - sample: "speech_quickstart_beta" - path: "{base_path}/SpeechQuickstartBeta.java" - class: "{package}.SpeechQuickstartBeta" - region_tag: "speech_quickstart_beta" -- <<: *java - sample: "speech_transcribe_word_level_confidence_beta" - path: "{base_path}/SpeechTranscribeWordLevelConfidenceBeta.java" - class: "{package}.SpeechTranscribeWordLevelConfidenceBeta" - region_tag: "speech_transcribe_word_level_confidence_beta" -- <<: *java - sample: "speech_adaptation_beta" - path: "{base_path}/SpeechAdaptationBeta.java" - class: "{package}.SpeechAdaptationBeta" - region_tag: "speech_adaptation_beta" -- <<: *java - sample: "speech_transcribe_multilanguage_beta" - path: "{base_path}/SpeechTranscribeMultilanguageBeta.java" - class: "{package}.SpeechTranscribeMultilanguageBeta" - region_tag: "speech_transcribe_multilanguage_beta" -- <<: *java - sample: "speech_transcribe_recognition_metadata_beta" - path: "{base_path}/SpeechTranscribeRecognitionMetadataBeta.java" - class: "{package}.SpeechTranscribeRecognitionMetadataBeta" - region_tag: "speech_transcribe_recognition_metadata_beta" -- <<: *java - sample: "speech_transcribe_diarization_beta" - path: "{base_path}/SpeechTranscribeDiarizationBeta.java" - class: "{package}.SpeechTranscribeDiarizationBeta" - region_tag: "speech_transcribe_diarization_beta" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_adaptation_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_adaptation_beta.test.yaml deleted file mode 100644 index 4efe8e83fc3..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_adaptation_beta.test.yaml +++ /dev/null @@ -1,11 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Speech-to-Text Sample Tests For Speech Adaptation - cases: - - name: speech_adaptation_beta - spec: - - call: {sample: speech_adaptation_beta} - - assert_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_contexts_classes_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_contexts_classes_beta.test.yaml deleted file mode 100644 index b6dccfc71ff..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_contexts_classes_beta.test.yaml +++ /dev/null @@ -1,11 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Speech-to-Text Sample Tests For Speech Contexts Static Classes - cases: - - name: speech_contexts_classes_beta - spec: - - call: {sample: speech_contexts_classes_beta} - - assert_contains: - - literal: "the time is 5:45 p.m." diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_quickstart_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_quickstart_beta.test.yaml deleted file mode 100644 index bd5bf6700a8..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_quickstart_beta.test.yaml +++ /dev/null @@ -1,11 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Speech-to-Text Sample Tests For Quickstart - cases: - - name: speech_quickstart_beta - spec: - - call: {sample: speech_quickstart_beta} - - assert_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_auto_punctuation_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_auto_punctuation_beta.test.yaml deleted file mode 100644 index 1ab5f79a0f4..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_auto_punctuation_beta.test.yaml +++ /dev/null @@ -1,28 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Getting punctuation in results (Local File) (Beta) - cases: - - # This sample should default to using commercial_mono.wav - - name: speech_transcribe_auto_punctuation_beta (no arguments) - spec: - - call: - sample: speech_transcribe_auto_punctuation_beta - - assert_contains: - # Simply assert that actual punctuation is present from commercial_mono.wav - - literal: "?" - - literal: "," - - literal: "" - - # Confirm that another file can be transcribed (use another file) - - name: speech_transcribe_auto_punctuation_beta (--local_file_path) - spec: - - call: - sample: speech_transcribe_auto_punctuation_beta - params: - local_file_path: - literal: "resources/brooklyn_bridge.flac" - - assert_contains: - - literal: "How old is the Brooklyn Bridge?" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_diarization_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_diarization_beta.test.yaml deleted file mode 100644 index 409e4b54b66..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_diarization_beta.test.yaml +++ /dev/null @@ -1,40 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Separating different speakers (Local File) (LRO) (Beta) - cases: - - # This sample should default to using commercial_mono.wav - - name: speech_transcribe_diarization_beta (no arguments) - spec: - - call: - sample: speech_transcribe_diarization_beta - - assert_contains: - - literal: "Word: Chrome" - # The identifier given to each speaker is non-deterministic. - # For two speakers, it can be 0 and 1, 0 and 2, or other variations. - # - # The example audio file has two speakers, but this test is - # not verifying that greater than one speaker is detected. - - literal: "Speaker tag:" - - # Confirm that another file can be transcribed (use another .flac file) - - name: speech_transcribe_diarization_beta (--local_file_path) - spec: - - call: - sample: speech_transcribe_diarization_beta - params: - local_file_path: - literal: "resources/multi.flac" - - assert_contains: - - literal: "how are you doing" - - literal: "Word: doing" - # The identifier given to each speaker is non-deterministic. - # For two speakers, it can be 0 and 1, 0 and 2, or other variations. - # - # The example audio file has two speakers, but this test is - # not verifying that greater than one speaker is detected. - - literal: "Speaker tag:" - - assert_not_contains: - - literal: "Chrome" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_multilanguage_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_multilanguage_beta.test.yaml deleted file mode 100644 index d9f2d71093c..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_multilanguage_beta.test.yaml +++ /dev/null @@ -1,33 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Detecting language spoken automatically (Local File) (Beta) - cases: - - # This sample should default to using brooklyn_bridge.flac - - name: speech_transcribe_multilanguage_beta (no arguments) - spec: - - call: - sample: speech_transcribe_multilanguage_beta - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - # Note: the primary language_code given was not English, but - # English was provided in the list of alternative_language_codes - - literal: "Detected language: en-us" - - # Confirm that another file can be transcribed (use another .flac file) - - name: speech_transcribe_multilanguage_beta (--local_file_path) - spec: - - call: - sample: speech_transcribe_multilanguage_beta - params: - local_file_path: - literal: "resources/multi.flac" - - assert_contains: - - literal: "how are you doing" - # Note: the primary language_code given was not English, but - # English was provided in the list of alternative_language_codes - - literal: "Detected language: en-us" - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_recognition_metadata_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_recognition_metadata_beta.test.yaml deleted file mode 100644 index 57cf24a1d26..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_recognition_metadata_beta.test.yaml +++ /dev/null @@ -1,27 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Adding recognition metadata (Local File) (Beta) - cases: - - # This sample should default to using commercial_mono.wav - - name: speech_transcribe_recognition_metadata_beta (no arguments) - spec: - - call: - sample: speech_transcribe_recognition_metadata_beta - - assert_contains: - - literal: "Chrome" - - # Confirm that another file can be transcribed (use another file) - - name: speech_transcribe_recognition_metadata_beta (--local_file_path) - spec: - - call: - sample: speech_transcribe_recognition_metadata_beta - params: - local_file_path: - literal: "resources/brooklyn_bridge.flac" - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - assert_not_contains: - - literal: "Chrome" diff --git a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_word_level_confidence_beta.test.yaml b/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_word_level_confidence_beta.test.yaml deleted file mode 100644 index 0d7d60570a0..00000000000 --- a/speech/generated/src/main/java/com/google/cloud/examples/speech/v1p1beta1/test/speech_transcribe_word_level_confidence_beta.test.yaml +++ /dev/null @@ -1,35 +0,0 @@ -type: test/samples -schema_version: 1 -test: - suites: - - name: Enabling word-level confidence (Local File) (Beta) - cases: - - # This sample should default to using brooklyn_bridge.flac - - name: speech_transcribe_word_level_confidence_beta (no arguments) - spec: - - call: - sample: speech_transcribe_word_level_confidence_beta - - assert_contains: - - literal: "how old is the Brooklyn Bridge" - - literal: "Word: how" - - literal: "Word: old" - - literal: "Word: is" - - literal: "Confidence: 0." - - # Confirm that another file can be transcribed (use another .flac file) - - name: speech_transcribe_word_level_confidence_beta (--local_file_path) - spec: - - call: - sample: speech_transcribe_word_level_confidence_beta - params: - local_file_path: - literal: "resources/multi.flac" - - assert_contains: - - literal: "how are you doing" - - literal: "Word: how" - - literal: "Word: are" - - literal: "Word: you" - - literal: "Confidence: 0." - - assert_not_contains: - - literal: "how old is the Brooklyn Bridge" diff --git a/speech/snippets/src/main/java/com/example/speech/ExportToStorageBeta.java b/speech/snippets/src/main/java/com/example/speech/ExportToStorageBeta.java index 7c60725924b..70e1c07af7c 100644 --- a/speech/snippets/src/main/java/com/example/speech/ExportToStorageBeta.java +++ b/speech/snippets/src/main/java/com/example/speech/ExportToStorageBeta.java @@ -44,7 +44,10 @@ public static void main(String[] args) throws Exception { // Exports the recognized output to specified GCS destination. public static void exportToStorage( - String inputUri, String outputStorageUri, String encoding, int sampleRateHertz, + String inputUri, + String outputStorageUri, + String encoding, + int sampleRateHertz, String languageCode) throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created @@ -56,14 +59,15 @@ public static void exportToStorage( AudioEncoding audioEncoding = AudioEncoding.valueOf(encoding); // Pass in the URI of the Cloud Storage bucket to hold the transcription - TranscriptOutputConfig outputConfig = TranscriptOutputConfig.newBuilder() - .setGcsUri(outputStorageUri).build(); + TranscriptOutputConfig outputConfig = + TranscriptOutputConfig.newBuilder().setGcsUri(outputStorageUri).build(); - RecognitionConfig config = RecognitionConfig.newBuilder() - .setEncoding(audioEncoding) - .setSampleRateHertz(sampleRateHertz) - .setLanguageCode(languageCode) - .build(); + RecognitionConfig config = + RecognitionConfig.newBuilder() + .setEncoding(audioEncoding) + .setSampleRateHertz(sampleRateHertz) + .setLanguageCode(languageCode) + .build(); LongRunningRecognizeRequest request = LongRunningRecognizeRequest.newBuilder() @@ -80,9 +84,10 @@ public static void exportToStorage( System.out.println("Results saved to specified output Cloud Storage bucket."); - String output = response.getResultsList().stream().map( - result -> String.valueOf(result.getAlternatives(0).getTranscript())) - .collect(Collectors.joining("\n")); + String output = + response.getResultsList().stream() + .map(result -> String.valueOf(result.getAlternatives(0).getTranscript())) + .collect(Collectors.joining("\n")); System.out.printf("Transcription: %s", output); } } diff --git a/speech/snippets/src/main/java/com/example/speech/QuickstartSample.java b/speech/snippets/src/main/java/com/example/speech/QuickstartSample.java index 5d01eeae90a..245d0d0b812 100644 --- a/speech/snippets/src/main/java/com/example/speech/QuickstartSample.java +++ b/speech/snippets/src/main/java/com/example/speech/QuickstartSample.java @@ -25,10 +25,6 @@ import com.google.cloud.speech.v1.SpeechClient; import com.google.cloud.speech.v1.SpeechRecognitionAlternative; import com.google.cloud.speech.v1.SpeechRecognitionResult; -import com.google.protobuf.ByteString; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; public class QuickstartSample { diff --git a/speech/snippets/src/main/java/com/example/speech/SpeechProfanityFilter.java b/speech/snippets/src/main/java/com/example/speech/SpeechProfanityFilter.java index b37298388a8..b8ee99215d5 100644 --- a/speech/snippets/src/main/java/com/example/speech/SpeechProfanityFilter.java +++ b/speech/snippets/src/main/java/com/example/speech/SpeechProfanityFilter.java @@ -24,7 +24,6 @@ import com.google.cloud.speech.v1.SpeechClient; import com.google.cloud.speech.v1.SpeechRecognitionAlternative; import com.google.cloud.speech.v1.SpeechRecognitionResult; -import java.io.IOException; import java.util.List; public class SpeechProfanityFilter { @@ -43,7 +42,7 @@ public static void speechProfanityFilter(String gcsUri) throws Exception { // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS try (SpeechClient speech = SpeechClient.create()) { - // Configure remote file request + // Configure remote file request RecognitionConfig config = RecognitionConfig.newBuilder() .setEncoding(AudioEncoding.FLAC) @@ -65,7 +64,7 @@ public static void speechProfanityFilter(String gcsUri) throws Exception { SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcription: %s\n", alternative.getTranscript()); } - } + } } } -// [END speech_transcribe_with_profanity_filter_gcs] \ No newline at end of file +// [END speech_transcribe_with_profanity_filter_gcs] diff --git a/speech/snippets/src/main/java/com/example/speech/SpeechTranscribeMultiRegion.java b/speech/snippets/src/main/java/com/example/speech/SpeechTranscribeMultiRegion.java index d6524c5adde..f1da71f51d0 100644 --- a/speech/snippets/src/main/java/com/example/speech/SpeechTranscribeMultiRegion.java +++ b/speech/snippets/src/main/java/com/example/speech/SpeechTranscribeMultiRegion.java @@ -26,7 +26,6 @@ import com.google.cloud.speech.v1.SpeechRecognitionAlternative; import com.google.cloud.speech.v1.SpeechRecognitionResult; import com.google.cloud.speech.v1.SpeechSettings; -import java.io.IOException; import java.util.List; public class SpeechTranscribeMultiRegion { @@ -44,21 +43,18 @@ public void speechTranscribeMultiRegion() throws Exception { public static void speechTranscribeMultiRegion(String gcsUri) throws Exception { // Use the SpeechSettings to initialize the SpeechClient with the new endpoint. String endPoint = "eu-speech.googleapis.com:443"; - SpeechSettings speechSettings = - SpeechSettings.newBuilder() - .setEndpoint(endPoint) - .build(); + SpeechSettings speechSettings = SpeechSettings.newBuilder().setEndpoint(endPoint).build(); // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS try (SpeechClient speech = SpeechClient.create(speechSettings)) { - // Configure remote file request + // Configure remote file request RecognitionConfig config = RecognitionConfig.newBuilder() - .setEncoding(AudioEncoding.FLAC) - .setLanguageCode("en-US") - .setSampleRateHertz(16000) - .build(); + .setEncoding(AudioEncoding.FLAC) + .setLanguageCode("en-US") + .setSampleRateHertz(16000) + .build(); // Set the remote path for the audio file RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build(); diff --git a/speech/snippets/src/test/java/com/example/speech/SpeechProfanityFilterTest.java b/speech/snippets/src/test/java/com/example/speech/SpeechProfanityFilterTest.java index d49eb0a4f70..ddf1ccaeecb 100644 --- a/speech/snippets/src/test/java/com/example/speech/SpeechProfanityFilterTest.java +++ b/speech/snippets/src/test/java/com/example/speech/SpeechProfanityFilterTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.PrintStream; import org.junit.After; import org.junit.Before; diff --git a/speech/snippets/src/test/java/com/example/speech/SpeechTranscribeMultiRegionTest.java b/speech/snippets/src/test/java/com/example/speech/SpeechTranscribeMultiRegionTest.java index e91258523f5..3a8aa317d53 100644 --- a/speech/snippets/src/test/java/com/example/speech/SpeechTranscribeMultiRegionTest.java +++ b/speech/snippets/src/test/java/com/example/speech/SpeechTranscribeMultiRegionTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.PrintStream; import org.junit.After; import org.junit.Before;