首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法通过任何方法通过speech_recognition python获得音频?

无法通过任何方法通过speech_recognition python获得音频?
EN

Stack Overflow用户
提问于 2021-10-20 12:39:31
回答 1查看 260关注 0票数 0

我试着让SpeechRecognition 3.8.1听我的声音四天。我已经在互联网上看到了以下内容:

  1. https://github.com/Uberi/speech_recognition/issues/20
  2. https://www.geeksforgeeks.org/voice-assistant-using-python/
  3. https://pythonrepo.com/repo/Uberi-speech_recognition-python-audio
    • sudo apt-get install python-pyaudio python3-pyaudio不适用于me.

  1. speech recognition python code not working
  2. Errors on PyAudio on Visual studio code Python
  3. I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."?
  4. https://stackoverflow.com/questions/50424902/speechrecognition-python-package-does-not-listen?r=SearchResults&s=4|89.4428
  5. https://newbedev.com/speech-recognition-python-code-not-working-code-example
  6. https://www.py4u.net/discuss/22062

我经历了更多的讨论,都是徒劳的,

到目前为止我还没找到解决办法。救命啊!!

在多次尝试失败之后,我至少成功地用命令pipwin install pyaudio安装了pipwin install pyaudio

我的python代码:

代码语言:javascript
运行
复制
import os
import pyttsx3, datetime, pyaudio
import speech_recognition as sr

# Initial Setup for pyttsx3 - speaking abilities
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[1].id)  # 0-male voice , 1-female voice
sr.Microphone.list_microphone_names()

# Initial Setup for speech_recognition - listening abilities
# r.energy_threshold = 10
# print(pyaudio.get_device_count() - 1)


def speak(speakable):
    """speak() takes a string and reads it loud"""
    engine.say(str(speakable))
    engine.runAndWait()


def takeCommand():
    pyaudio.PyAudio()
    r = sr.Recognizer()
    """It takes microphone input from the user and returns string output"""
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source, duration=0.9)
        print("Listening...")
        r.pause_threshold = 45
        audio = ""
        try:
            audio = r.listen(source)
            print("Recognizing...")
        except Exception as e:
            print("Listen err: ", e)
        try:
            print("Recognizing...")
            query = r.recognize_google(audio)
            print(f"User said: {query}\n")  # User query will be printed.
        except sr.UnknownValueError as e:
            print("Say that again please...")
            return "None"  # None string will be returned
        except Exception as err:
            print("Check your internet...")
            return "None"
    return query


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour >= 0 and hour < 12:
        speak("Good Morning!")

    elif hour >= 12 and hour < 18:
        speak("Good Afternoon!")

    else:
        speak("Good Evening!")
        speak(
            "Hello Sir, I am Friday, your Artificial intelligence assistant. Please tell me how may I help you"
        )


if __name__ == "__main__":
    os.system("CLS")
    while True:
        command = takeCommand().lower()
        print(f"Command: {command}")
        if "wish" in command:
            wishMe()

输出卡在Listening...上。在那之后什么都不会发生。

更多信息:

我使用的是Windows 10 Home

  • Code编辑器- vs code

  • I不在这个程序中使用virtual env

  • 我还检查了Chrome 是否没有任何trouble.

python3 -m speech_recognition命令的结果

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-20 13:11:17

你试过用python3 -m speech_recognition吗?你应该看到这样的东西:

代码语言:javascript
运行
复制
...
A moment of silence, please...
Set minimum energy threshold to 51.208131879528096
Say something!
Got it! Now to recognize it...
You said hello

如果这样做不起作用,那么您的音频系统可能有问题。确保您可以录制音频(https://onlinehardwaretest.com/microphone-test/),并考虑重新启动系统。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69646142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档