Python语音识别无法在Mac OS上运行

时间:2015-08-24 05:26:47

标签: python user-interface speech-recognition

我相对较新的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中成功使用?

感谢。

1 个答案:

答案 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))