/** Constructs an instance of SpeechClient with default settings. */ public static final SpeechClient create() throws IOException { return create(SpeechSettings.newBuilder().build()); }
@BeforeClass public static void setupClass() throws Exception { speechClient = SpeechClient.create(); }
public static void main(String... args) throws Exception { SpeechClient speech = SpeechClient.create();
@Before public void setUp() throws IOException { serviceHelper.reset(); channelProvider = serviceHelper.createChannelProvider(); SpeechSettings settings = SpeechSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build(); client = SpeechClient.create(settings); }
public static void executeNoCatch() throws Exception { try (SpeechClient client = SpeechClient.create()) { String languageCode = "en-US"; int sampleRateHertz = 44100; RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC; RecognitionConfig config = RecognitionConfig.newBuilder() .setLanguageCode(languageCode) .setSampleRateHertz(sampleRateHertz) .setEncoding(encoding) .build(); String uri = "gs://gapic-toolkit/hello.flac"; RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build(); RecognizeResponse response = client.recognize(config, audio); } }
byte[] content = Files.readAllBytes(path); try (SpeechClient speech = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {
byte[] content = Files.readAllBytes(path); try (SpeechClient speechClient = SpeechClient.create()) {
/** * Performs speech recognition on raw PCM audio and prints the transcription. * * @param fileName the path to a PCM audio file to transcribe. */ public static void syncRecognizeFile(String fileName) throws Exception { try (SpeechClient speech = SpeechClient.create()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); ByteString audioBytes = ByteString.copyFrom(data); // Configure request with local raw PCM audio RecognitionConfig config = RecognitionConfig.newBuilder() .setEncoding(AudioEncoding.LINEAR16) .setLanguageCode("en-US") .setSampleRateHertz(16000) .build(); RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(audioBytes).build(); // Use blocking call to get audio transcript RecognizeResponse response = speech.recognize(config, audio); List<SpeechRecognitionResult> results = response.getResultsList(); for (SpeechRecognitionResult result : results) { // There can be several alternative transcripts for a given chunk of speech. Just use the // first (most likely) one here. SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcription: %s%n", alternative.getTranscript()); } } } // [END speech_transcribe_sync]
try (SpeechClient speechClient = SpeechClient.create()) {
try (SpeechClient speechClient = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {
byte[] content = Files.readAllBytes(path); try (SpeechClient speechClient = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {
/** * Performs speech recognition on remote FLAC file and prints the transcription. * * @param gcsUri the path to the remote FLAC audio file to transcribe. */ public static void syncRecognizeGcs(String gcsUri) throws Exception { // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS try (SpeechClient speech = SpeechClient.create()) { // Builds the request for remote FLAC file RecognitionConfig config = RecognitionConfig.newBuilder() .setEncoding(AudioEncoding.FLAC) .setLanguageCode("en-US") .setSampleRateHertz(16000) .build(); RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build(); // Use blocking call for getting audio transcript RecognizeResponse response = speech.recognize(config, audio); List<SpeechRecognitionResult> results = response.getResultsList(); for (SpeechRecognitionResult result : results) { // There can be several alternative transcripts for a given chunk of speech. Just use the // first (most likely) one here. SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcription: %s%n", alternative.getTranscript()); } } } // [END speech_transcribe_sync_gcs]
try (SpeechClient speech = SpeechClient.create()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path);
try (SpeechClient client = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {
try (SpeechClient speech = SpeechClient.create()) {