简体   繁体   中英

Google speech to text Java SDK how to add speech context to speech recognition config

I am using Google cloud speech to text and following is my recognition config object:

RecognitionConfig config = RecognitionConfig.newBuilder().setLanguageCode("en-US").setModel("default").build();

I want to add speech context to this so that I can add custom phrases which are often said in the audio's, there is the setSpeechContext method for the RecognitionConfig but how to add some custom words on to the config using this method. An example to add some keywords to the above config object would help me.

I think the correct way to accomplish this is as follows:

                SpeechContext sc = SpeechContext.newBuilder()
                    .addPhrases("hello")
                    .build();

And then you can just add that to your RecognitionConfig

                RecognitionConfig recognitionConfig =
                        RecognitionConfig.newBuilder()
                        .setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
                        .setLanguageCode("en-US")
                        .setSampleRateHertz(16000)
                        .addSpeechContexts(sc)
                        .build();

Similar issue also answered here: Google Cloud Speech API add SpeechContext

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM