【问题标题】:Python Speech_Recognition hung up on mic listeningPython Speech_Recognition 挂断了麦克风收听
【发布时间】:2020-03-28 23:53:08
【问题描述】:

如果有人知道这里发生了什么,我将不胜感激。所以我试图识别通过麦克风输入的语音(设备索引为 1),而我的程序正在挂断聆听。我已经针对环境噪音进行了调整,但我仍然没有取得任何进展。

这是我的代码:

import pyaudio
import speech_recognition as sr

r = sr.Recognizer()
mic = sr.Microphone(1)
with mic as source:
     r.adjust_for_ambient_noise(source)
     print("Please Speak :")
     audio = r.listen(source)
     print("Stop Talking")

     try:
         text = r.recognize_google(audio)
         print("You said : " + r. recognize_google(text))
     except:
         print("Sorry, I could not recognize what you said")

这就是程序运行时我得到的全部内容:

Please Speak :

然后没有别的了。我在 python 控制台中运行了它,但从未得到控制台提示。

r = sr.Recognizer()
with mic as source:
 r.adjust_for_ambient_noise(source)
 print("Please Speak :")
 audio = r.listen(source)

Please Speak :

我不确定我可以在这里做什么或出了什么问题。 我在跑步:

    Mac OS Mojave 10.14.6
    Python 3.8
    Pycharm IDLE

现在我做了一些改变:

import speech_recognition as sr

r = sr.Recognizer()
print(sr.Microphone.list_microphone_names())
mic = sr.Microphone(device_index=1)
with mic as source:
    r.adjust_for_ambient_noise(source, duration=5)
    print("Please Speak :")
    audio = r.listen(source, timeout=5)
    print("Stop Talking")

try:
    text = r.recognize_google(audio)
    print("You said : " + text)
except:
    print("Sorry, I could not recognize what you said.")

这是我的错误:

eTraceback (most recent call last):
File "/Users/cameronclarke/PycharmProjects/SpeechRecog/Speech 
Recog.py", line 13, in <module>
audio = r.listen(source, timeout=5)
File 
Users/cameronclarke/opt/anaconda3/envs/SpeechRecog/lib/python3.7/site- 
packages/speech_recognition/__init__.py", line 544, in listen
raise WaitTimeoutError("listening timed out while waiting for phrase 
to start")
speech_recognition.WaitTimeoutError: listening timed out while waiting 
for phrase to start.

为什么会这样? 干杯!感谢所有帮助:)

【问题讨论】:

标签: speech-recognition microphone python-3.8 hung


【解决方案1】:

问题是操作系统不允许您的 IDE 访问麦克风。 如果您在操作系统本机“终端”中运行您的 python 代码,则会提示您是否允许终端访问麦克风,然后允许它,代码将起作用。

【讨论】:

    猜你喜欢
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    相关资源
    最近更新 更多