@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (getAlternativesCount() > 0) { hash = (37 * hash) + ALTERNATIVES_FIELD_NUMBER; hash = (53 * hash) + getAlternativesList().hashCode(); } hash = (37 * hash) + IS_FINAL_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(getIsFinal()); hash = (37 * hash) + STABILITY_FIELD_NUMBER; hash = (53 * hash) + java.lang.Float.floatToIntBits(getStability()); hash = (37 * hash) + CHANNEL_TAG_FIELD_NUMBER; hash = (53 * hash) + getChannelTag(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public com.google.cloud.speech.v1.StreamingRecognitionResult buildPartial() { com.google.cloud.speech.v1.StreamingRecognitionResult result = new com.google.cloud.speech.v1.StreamingRecognitionResult(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (alternativesBuilder_ == null) { if (((bitField0_ & 0x00000001) == 0x00000001)) { alternatives_ = java.util.Collections.unmodifiableList(alternatives_); bitField0_ = (bitField0_ & ~0x00000001); } result.alternatives_ = alternatives_; } else { result.alternatives_ = alternativesBuilder_.build(); } result.isFinal_ = isFinal_; result.stability_ = stability_; result.channelTag_ = channelTag_; result.bitField0_ = to_bitField0_; onBuilt(); return result; }
public Builder mergeFrom(com.google.cloud.speech.v1.StreamingRecognitionResult other) { if (other == com.google.cloud.speech.v1.StreamingRecognitionResult.getDefaultInstance()) return this; if (alternativesBuilder_ == null) { if (other.getIsFinal() != false) { setIsFinal(other.getIsFinal()); if (other.getStability() != 0F) { setStability(other.getStability()); if (other.getChannelTag() != 0) { setChannelTag(other.getChannelTag());
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.speech.v1.StreamingRecognitionResult)) { return super.equals(obj); } com.google.cloud.speech.v1.StreamingRecognitionResult other = (com.google.cloud.speech.v1.StreamingRecognitionResult) obj; boolean result = true; result = result && getAlternativesList().equals(other.getAlternativesList()); result = result && (getIsFinal() == other.getIsFinal()); result = result && (java.lang.Float.floatToIntBits(getStability()) == java.lang.Float.floatToIntBits(other.getStability())); result = result && (getChannelTag() == other.getChannelTag()); result = result && unknownFields.equals(other.unknownFields); return result; }
@Override public void onNext(StreamingRecognizeResponse response) { String text = null; boolean isFinal = false; if (response.getResultsCount() > 0) { final StreamingRecognitionResult result = response.getResults(0); isFinal = result.getIsFinal(); if (result.getAlternativesCount() > 0) { final SpeechRecognitionAlternative alternative = result.getAlternatives(0); text = alternative.getTranscript(); } } if (text != null) { for (Listener listener : mListeners) { listener.onSpeechRecognized(text, isFinal); } } }
/** * Handle a single {@link StreamingRecognitionResult} by creating * a {@link TranscriptionResult} based on the result and notifying all * all registered {@link TranscriptionListener}s * * @param result the result to handle */ private void handleResult(StreamingRecognitionResult result) { List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList(); if(alternatives.isEmpty()) { return; } TranscriptionResult transcriptionResult = new TranscriptionResult( null, this.messageID, !result.getIsFinal(), this.languageTag, result.getStability()); for(SpeechRecognitionAlternative alternative : alternatives) { transcriptionResult.addAlternative( new TranscriptionAlternative( alternative.getTranscript(), alternative.getConfidence())); } sent(transcriptionResult); }
public void onResponse(StreamingRecognizeResponse response) { responses.add(response); StreamingRecognitionResult result = response.getResultsList().get(0); // 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("Transcript : %s\n", alternative.getTranscript()); }
if(!finalResult.getIsFinal()) = finalResult.getAlternativesList();
@Test public void streamingRecognize() throws Exception { byte[] audioBytes = Resources.toByteArray(new URL("https://storage.googleapis.com/gapic-toolkit/hello.flac")); StreamingRecognitionConfig streamingConfig = StreamingRecognitionConfig.newBuilder().setConfig(config()).build(); ResponseApiStreamingObserver<StreamingRecognizeResponse> responseObserver = new ResponseApiStreamingObserver<>(); ApiStreamObserver<StreamingRecognizeRequest> requestObserver = speechClient.streamingRecognizeCallable().bidiStreamingCall(responseObserver); // The first request must **only** contain the audio configuration: requestObserver.onNext( StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingConfig).build()); // Subsequent requests must **only** contain the audio data. requestObserver.onNext( StreamingRecognizeRequest.newBuilder() .setAudioContent(ByteString.copyFrom(audioBytes)) .build()); // Mark transmission as completed after sending the data. requestObserver.onCompleted(); List<StreamingRecognizeResponse> responses = responseObserver.future().get(); Truth.assertThat(responses.size()).isGreaterThan(0); Truth.assertThat(responses.get(0).getResultsCount()).isGreaterThan(0); Truth.assertThat(responses.get(0).getResults(0).getAlternativesCount()).isGreaterThan(0); String text = responses.get(0).getResults(0).getAlternatives(0).getTranscript(); Truth.assertThat(text).isEqualTo("hello"); }
@java.lang.Override public com.google.cloud.speech.v1.StreamingRecognitionResult getDefaultInstanceForType() { return com.google.cloud.speech.v1.StreamingRecognitionResult.getDefaultInstance(); }
public void onComplete() { for (StreamingRecognizeResponse response : responses) { StreamingRecognitionResult result = response.getResultsList().get(0); SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcript : %s\n", alternative.getTranscript()); } }
/** * * * <pre> * Output only. This repeated list contains zero or more results that * correspond to consecutive portions of the audio currently being processed. * It contains zero or one `is_final=true` result (the newly settled portion), * followed by zero or more `is_final=false` results (the interim results). * </pre> * * <code>repeated .google.cloud.speech.v1.StreamingRecognitionResult results = 2;</code> */ public com.google.cloud.speech.v1.StreamingRecognitionResult.Builder addResultsBuilder() { return getResultsFieldBuilder() .addBuilder(com.google.cloud.speech.v1.StreamingRecognitionResult.getDefaultInstance()); } /**
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcript : %s\n", alternative.getTranscript());
/** * * * <pre> * Output only. This repeated list contains zero or more results that * correspond to consecutive portions of the audio currently being processed. * It contains zero or one `is_final=true` result (the newly settled portion), * followed by zero or more `is_final=false` results (the interim results). * </pre> * * <code>repeated .google.cloud.speech.v1.StreamingRecognitionResult results = 2;</code> */ public com.google.cloud.speech.v1.StreamingRecognitionResult.Builder addResultsBuilder( int index) { return getResultsFieldBuilder() .addBuilder( index, com.google.cloud.speech.v1.StreamingRecognitionResult.getDefaultInstance()); } /**
SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); System.out.printf("Transcript : %s\n", alternative.getTranscript());