/** * * * <pre> * *Optional* array of [SpeechContext][google.cloud.speech.v1.SpeechContext]. * A means to provide context to assist the speech recognition. For more * information, see [Phrase Hints](/speech-to-text/docs/basics#phrase-hints). * </pre> * * <code>repeated .google.cloud.speech.v1.SpeechContext speech_contexts = 6;</code> */ public Builder addSpeechContexts( int index, com.google.cloud.speech.v1.SpeechContext.Builder builderForValue) { if (speechContextsBuilder_ == null) { ensureSpeechContextsIsMutable(); speechContexts_.add(index, builderForValue.build()); onChanged(); } else { speechContextsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * *Optional* array of [SpeechContext][google.cloud.speech.v1.SpeechContext]. * A means to provide context to assist the speech recognition. For more * information, see [Phrase Hints](/speech-to-text/docs/basics#phrase-hints). * </pre> * * <code>repeated .google.cloud.speech.v1.SpeechContext speech_contexts = 6;</code> */ public Builder setSpeechContexts( int index, com.google.cloud.speech.v1.SpeechContext.Builder builderForValue) { if (speechContextsBuilder_ == null) { ensureSpeechContextsIsMutable(); speechContexts_.set(index, builderForValue.build()); onChanged(); } else { speechContextsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * *Optional* array of [SpeechContext][google.cloud.speech.v1.SpeechContext]. * A means to provide context to assist the speech recognition. For more * information, see [Phrase Hints](/speech-to-text/docs/basics#phrase-hints). * </pre> * * <code>repeated .google.cloud.speech.v1.SpeechContext speech_contexts = 6;</code> */ public Builder addSpeechContexts( com.google.cloud.speech.v1.SpeechContext.Builder builderForValue) { if (speechContextsBuilder_ == null) { ensureSpeechContextsIsMutable(); speechContexts_.add(builderForValue.build()); onChanged(); } else { speechContextsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * Initialize speechContexts if needed, by getting all the phrases used * by the action handlers to detect commands to handle. * Inserts all speechContexts to the <tt>RecognitionConfig.Builder</tt>. * @param builder the builder where to add speech contexts. */ private void addSpeechContexts(RecognitionConfig.Builder builder) { if (speechContexts == null) { speechContexts = new ArrayList<>(); ActionServicesHandler.getInstance().getPhrases() .stream().map(ph -> speechContexts.add( SpeechContext.newBuilder().addPhrases(ph).build())); } speechContexts.stream().map(ctx -> builder.addSpeechContexts(ctx)); }