本文整理匯總了Python中speech_recognition.RequestError方法的典型用法代碼示例。如果您正苦於以下問題:Python speech_recognition.RequestError方法的具體用法?Python speech_recognition.RequestError怎麽用?Python speech_recognition.RequestError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類speech_recognition
的用法示例。
在下文中一共展示了speech_recognition.RequestError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sphinx_callback
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def sphinx_callback(self, recognizer, audio):
"""
called from the background thread
"""
try:
captured_audio = recognizer.recognize_sphinx(audio,
language=self.language,
keyword_entries=self.keyword_entries,
grammar=self.grammar_file)
Utils.print_success("Sphinx Speech Recognition thinks you said %s" % captured_audio)
self._analyse_audio(captured_audio)
except sr.UnknownValueError:
Utils.print_warning("Sphinx Speech Recognition could not understand audio")
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except sr.RequestError as e:
Utils.print_danger("Could not request results from Sphinx Speech Recognition service; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except AssertionError:
Utils.print_warning("No audio caught from microphone")
self._analyse_audio(audio_to_text=None)
示例2: sphinx
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def sphinx(audio, vals, i, results_dict, timing):
try:
#print("Sphinx: ")
s = time.time()
vals[i] = text_to_num(r.recognize_sphinx(audio), "sphinx", results_dict)
timing["sphinx"].append(time.time() - s)
print "timing2", timing
except sr.UnknownValueError:
logging.debug("Sphinx could not understand audio")
results_dict["sphinx"] = [DEFAULT]
results_dict["sphinx_fil"] = [DEFAULT]
except sr.RequestError as e:
logging.debug("Sphinx error; {0}".format(e))
results_dict["sphinx"] = [DEFAULT]
results_dict["sphinx_fil"] = [DEFAULT]
#Query Google Cloud
示例3: wit
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def wit(audio, vals, i, results_dict, timing):
# recognize speech using Wit.ai
WIT_AI_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx" # Wit.ai keys are 32-character uppercase alphanumeric strings
try:
s = time.time()
#print("Wit.ai: ")
vals[i] = text_to_num(r.recognize_wit(audio, key=WIT_AI_KEY), "wit", results_dict)
timing["wit"].append(time.time() - s)
#print("Wit " + str(vals[i]))
except sr.UnknownValueError:
logging.debug("Wit.ai could not understand audio")
results_dict["wit"] = [DEFAULT]
results_dict["wit_fil"] = [DEFAULT]
except sr.RequestError as e:
logging.debug("Could not request results from Wit.ai service; {0}".format(e))
results_dict["wit"] = [DEFAULT]
results_dict["wit_fil"] = [DEFAULT]
#Query Bing
示例4: bing
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def bing(audio, vals, i, results_dict, timing):
# recognize speech using Microsoft Bing Voice Recognition
# Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
BING_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
try:
s = time.time()
#print("Microsoft Bing Voice Recognition: ")
vals[i] = text_to_num(r.recognize_bing(audio, key=BING_KEY), "bing", results_dict)
timing["bing"].append(time.time() - s)
except sr.UnknownValueError:
logging.debug("Microsoft Bing Voice Recognition could not understand audio")
results_dict["bing"] = [DEFAULT]
results_dict["bing_fil"] = [DEFAULT]
except sr.RequestError as e:
logging.debug("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
results_dict["bing"] = [DEFAULT]
results_dict["bing_fil"] = [DEFAULT]
# Query IBM
示例5: ibm
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def ibm(audio, vals, i, results_dict, timing, show_all=False):
# recognize speech using IBM Speech to Text
IBM_USERNAME = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
IBM_PASSWORD = "XXXXXXXXXX" # IBM Speech to Text passwords are mixed-case alphanumeric strings
try:
s = time.time()
#print("IBM Speech to Text: ")
vals[i] = text_to_num(r.recognize_ibm(audio, username=IBM_USERNAME, \
password=IBM_PASSWORD, show_all=False), "ibm", results_dict)
timing["ibm"].append(time.time() - s)
except sr.UnknownValueError:
logging.debug("IBM Speech to Text could not understand audio")
results_dict["ibm"] = [DEFAULT]
results_dict["ibm_fil"] = [DEFAULT]
except sr.RequestError as e:
logging.debug("Could not request results from IBM Speech to Text service; {0}".format(e))
results_dict["ibm"] = [DEFAULT]
results_dict["ibm_fil"] = [DEFAULT]
#Query Google Speech-To-Text
示例6: OnClicked
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def OnClicked(self):
"""Recognizes the audio and sends it for display to displayText."""
r = sr.Recognizer()
with sr.Microphone() as source:
speak.say('Hey I am Listening ')
speak.runAndWait()
audio = r.listen(source)
try:
put=r.recognize_google(audio)
self.displayText(put)
self.textBox.insert('1.2',put)
self.textBox.delete('1.2',tk.END)
events(self,put)
except sr.UnknownValueError:
self.displayText("Could not understand audio")
except sr.RequestError as e:
self.displayText("Could not request results; {0}".format(e))
示例7: OnClicked
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def OnClicked(self):
"""Recognizes the audio and sends it for display to displayText."""
r = sr.Recognizer()
with sr.Microphone() as source:
speak.say('Hey I am Listening ')
speak.runAndWait()
audio = r.listen(source)
try:
put=r.recognize_google(audio)
self.displayText(put)
self.textBox.insert('1.2',put)
self.textBox.delete('1.2',tk.END)
events(self,put)
except sr.UnknownValueError:
self.displayText("Could not understand audio")
except sr.RequestError as e:
self.displayText("Could not request results; {0}".format(e))
示例8: OnClicked
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def OnClicked(self):
"""Recognizes the audio and sends it for display to displayText."""
r = sr.Recognizer()
with sr.Microphone() as source:
system('say Hey I am Listening ')
audio = r.listen(source)
try:
put=r.recognize_google(audio)
self.displayText(put)
self.textBox.insert('1.2',put)
put=put.lower()
put = put.strip()
#put = re.sub(r'[?|$|.|!]', r'', put)
link=put.split()
events(self,put,link)
except sr.UnknownValueError:
self.displayText("Could not understand audio")
except sr.RequestError as e:
self.displayText("Could not request results; {0}".format(e))
示例9: listen
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def listen():
#obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
r.adjust_for_ambient_noise(source, duration=0.5)
audio = r.listen(source)
#recognize speech using Google Speech Recognition
try:
var=r.recognize_google(audio)
except sr.UnknownValueError:
var="Groot could not understand audio"
except sr.RequestError:
var=" Looks like, there is some problem with Google Speech Recognition"
return var
#will show all posible text from audio
#print(r.recognize_google(audio, show_all=True))
示例10: voice_input
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def voice_input():
global a2t
r = sr.Recognizer()
with sr.Microphone() as source:
#r.adjust_for_ambient_noise(source)
r.record(source,duration=2)
print("Say something!")
audio = r.listen(source)
try:
a2t=r.recognize_sphinx(audio,keyword_entries=[('forward',1.0),('backward',1.0),('left',1.0),('right',1.0),('stop',1.0),('find line',0.95),('follow',1),('lights on',1),('lights off',1)])
print("Sphinx thinks you said " + a2t)
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
BtnVIN.config(fg=color_text,bg=color_btn)
return a2t
示例11: speechRecognition
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def speechRecognition():
# obtain audio from the microphone
print("Press 'y' to start~")
inputdata = input()
if inputdata == 'y':
inputdata = 0
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
recSuccess = 1
recContent = r.recognize_google(audio)
print("Speech Recognition thinks you said " + recContent)#,language="cmn-Hant-TW")
return recContent
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
開發者ID:a514514772,項目名稱:Real-Time-Facial-Expression-Recognition-with-DeepLearning,代碼行數:25,代碼來源:gen_sentence_with_emoticons.py
示例12: wit_callback
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def wit_callback(self, recognizer, audio):
try:
captured_audio = recognizer.recognize_wit(audio,
key=self.key,
show_all=self.show_all)
Utils.print_success("Wit.ai Speech Recognition thinks you said %s" % captured_audio)
self._analyse_audio(captured_audio)
except sr.UnknownValueError:
Utils.print_warning("Wit.ai Speech Recognition could not understand audio")
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except sr.RequestError as e:
Utils.print_danger("Could not request results from Wit.ai Speech Recognition service; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except AssertionError:
Utils.print_warning("No audio caught from microphone")
self._analyse_audio(audio_to_text=None)
示例13: bing_callback
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def bing_callback(self, recognizer, audio):
"""
called from the background thread
"""
try:
captured_audio = recognizer.recognize_bing(audio,
key=self.key,
language=self.language,
show_all=self.show_all)
Utils.print_success("Bing Speech Recognition thinks you said %s" % captured_audio)
self._analyse_audio(captured_audio)
except sr.UnknownValueError:
Utils.print_warning("Bing Speech Recognition could not understand audio")
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except sr.RequestError as e:
Utils.print_danger("Could not request results from Bing Speech Recognition service; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except AssertionError:
Utils.print_warning("No audio caught from microphone")
self._analyse_audio(audio_to_text=None)
示例14: google_callback
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def google_callback(self, recognizer, audio):
"""
called from the background thread
"""
try:
captured_audio = recognizer.recognize_google(audio,
key=self.key,
language=self.language,
show_all=self.show_all)
Utils.print_success("Google Speech Recognition thinks you said %s" % captured_audio)
self._analyse_audio(audio_to_text=captured_audio)
except sr.UnknownValueError:
Utils.print_warning("Google Speech Recognition could not understand audio")
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except sr.RequestError as e:
Utils.print_danger("Could not request results from Google Speech Recognition service; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except AssertionError:
Utils.print_warning("No audio caught from microphone")
self._analyse_audio(audio_to_text=None)
示例15: speech_to_text
# 需要導入模塊: import speech_recognition [as 別名]
# 或者: from speech_recognition import RequestError [as 別名]
def speech_to_text(self, audio_source):
# Initialize a new recognizer with the audio in memory as source
recognizer = sr.Recognizer()
with sr.AudioFile(audio_source) as source:
audio = recognizer.record(source) # read the entire audio file
audio_output = ""
# recognize speech using Google Speech Recognition
try:
audio_output = recognizer.recognize_google(audio)
print("[{0}] Google Speech Recognition: ".format(self.current_iteration) + audio_output)
# Check if we got harder audio captcha
if any(character.isalpha() for character in audio_output):
# Use Houndify to detect the harder audio captcha
print("[{0}] Fallback to Houndify!".format(self.current_iteration))
audio_output = self.string_to_digits(recognizer.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY))
print("[{0}] Houndify: ".format(self.current_iteration) + audio_output)
except sr.UnknownValueError:
print("[{0}] Google Speech Recognition could not understand audio".format(self.current_iteration))
except sr.RequestError as e:
print("[{0}] Could not request results from Google Speech Recognition service; {1}".format(self.current_iteration).format(e))
return audio_output