我相对较新的Python(以及一般的编程),我正在尝试使用语音识别库。但是,在使用Mac OSX在Python 3.3上运行一个非常简单的程序时。
import speech_recognition as sr
r = sr.Recognizer()
sr.adjust_for_ambient_noise(source, duration = 1)
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source) # listen for the first phrase and extract it into audio data
try:
print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
except LookupError: # speech is unintelligible
print("Could not understand audio")
即使我以大音量对着麦克风说话并且确保所有环境噪音都降到最低,代码仍然会说“无法理解音频”。如何让麦克风和语音识别在Mac OSX上运行?
是否有其他库可以更好地在Python上进行语音识别并且可以在GUI中成功使用?
感谢。
答案 0 :(得分:-1)
以下是使用带有Python的speech_recognition的一些代码的工作示例。
import speech_recognition as sr
#obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
print(r.recognize_google(audio))