Ms Azure cognitive quick start Speech to Text (adding phrases for accuracy)

Viewed 310

I want some added accuracy in the text File converted from audio (.wav) as mentioned above, I wrote the following code.

phrase_list_grammar = speechsdk.PhraseListGrammar.from_recognizer(reco)
PhraseListGrammar(impl_phraseListGrammar)
phrase_list_grammar.addPhrase("PHRASE1")
phrase_list_grammar.addPhrase("PHRASE2")
#from_recognizer(recognizer: azure.cognitiveservices.speech.Recognizer)
NameError                                 Traceback (most recent call last)
<ipython-input-15-d3d53bae877d> in <module>
----> 1 phrase_list_grammar = speechsdk.PhraseListGrammar.from_recognizer(reco)
      2 PhraseListGrammar(impl_phraseListGrammar)
      3 phrase_list_grammar.addPhrase("PHRASE1")
      4 phrase_list_grammar.addPhrase("PHRASE2")
      5 #from_recognizer(recognizer: azure.cognitiveservices.speech.Recognizer)

NameError: name 'reco' is not defined

The codes are taken from the Ms Azure Add phrase documentations. However it is resulting into an error as can be seen above.

Can someone suggest how I can overcome this error?

2 Answers

The error you are getting is because the recognizer is not initialized. Try initializing the recognizer and passing it to the PhraseListGrammar.

import azure.cognitiveservices.speech as speechsdk

speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

reco = speechsdk.SpeechRecognizer(speech_config=speech_config)
phrase_list_grammar = speechsdk.PhraseListGrammar.from_recognizer(reco) PhraseListGrammar(impl_phraseListGrammar)
phrase_list_grammar.addPhrase("PHRASE1")
phrase_list_grammar.addPhrase("PHRASE2")

Related