Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

python 3.x - Ms Azure cognitive quick start Speech to Text (adding phrases for accuracy)

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?

question from:https://stackoverflow.com/questions/65866587/ms-azure-cognitive-quick-start-speech-to-text-adding-phrases-for-accuracy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...