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

2023-12-27

我正在尝试做SpeechRecognition 3.8.1 https://pypi.org/project/SpeechRecognition/听我的声音四天了。我已经在互联网上看到过以下内容:

  1. https://github.com/Uberi/speech_recognition/issues/20 https://github.com/Uberi/speech_recognition/issues/20
  2. https://www.geeksforgeeks.org/voice-assistant-using-python/ https://www.geeksforgeeks.org/voice-assistant-using-python/
  3. https://pythonrepo.com/repo/Uberi-speech_recognition-python-audio https://pythonrepo.com/repo/Uberi-speech_recognition-python-audio
    • sudo apt-get install python-pyaudio python3-pyaudio对我不起作用。
  4. 语音识别Python代码不起作用 https://stackoverflow.com/questions/32005310/speech-recognition-python-code-not-working
  5. Visual Studio 代码 Python 上的 PyAudio 出现错误 https://stackoverflow.com/questions/61256699/errors-on-pyaudio-on-visual-studio-code-python
  6. 我无法在 Windows 上安装 pyaudio?如何解决“错误:需要 Microsoft Visual C++ 14.0”? https://stackoverflow.com/questions/52283840/i-cant-install-pyaudio-on-windows-how-to-solve-error-microsoft-visual-c-14
  7. https://newbedev.com/speech-recognition-python-code-not-working-code-example https://newbedev.com/speech-recognition-python-code-not-working-code-example
  8. https://www.py4u.net/discuss/22062 https://www.py4u.net/discuss/22062

我经历了更多的讨论,一切都是徒劳.
到目前为止,没有任何解决方案对我有用。请帮忙!!
经过多次失败的尝试,我至少成功安装了pyaudio用命令pipwin install pyaudio


我的Python代码:

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...。之后什么也没有发生。

更多信息:

  1. 我在用Windows 10 Home
  2. 代码编辑器-vs code
  3. 我没有使用virtual env在这个这个节目中。
  4. 我也检查过Chrome 语音搜索工作没有任何问题。
  5. python3 -m speech_recognition result of the python3 -m speech_recognition command

你尝试过使用python3 -m speech_recognition?您应该看到类似以下内容:

...
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/ https://onlinehardwaretest.com/microphone-test/)并考虑重新启动系统。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法通过任何方法通过speech_recognition python获取音频? 的相关文章

随机推荐

  • SQL查询查找ID不在另一个表中的记录

    我在数据库中有两个具有绑定主键的表 我想在它们之间找到一个不相交的集合 例如 Table1 ID Name 1 John 2 Peter 3 Mary Table2 ID Address 1 address2 2 address2 那么我如
  • 异常断点 - LLDB 结果与 GDB

    我专门搜索了这个问题的主题 但没有找到任何与我的经历相近的内容 如果我忽略了答案 请原谅我 我熟悉 GDB 和异常点 断点等 但是下面的 GDB 与 LDB 调试测试让我没有得到合理的回应 全局测试值 Xcode 4 2 1 新的单一窗口项
  • Android推送通知-如何获取设备ID

    我陷入了使用 Google 云通知创建推送通知的过程 我正在做的是我应该获取设备的设备 ID 的部分 以便稍后当我需要发送推送通知时可以使用该设备 ID 所以我有这个代码 GCMRegistrar checkDevice this GCMR
  • 在 Android 中创建选项菜单

    我正在尝试在我的 Android 程序中创建选项菜单 我正在使用以下代码来扩展选项菜单 Override public boolean onCreateOptionsMenu Menu menu super onCreateOptionsM
  • 如何保存单选按钮的状态

    我制作了 4 个单选按钮 并希望在单击其中任何一个按钮时保存状态 然后希望在应用程序中使用该保存的状态 我该怎么做 myOption1 setChecked true myOption2 setChecked true myOption3
  • 将 char 数组转换为字符串

    如何使用 Arduino 将字符数组转换为字符串 char charArray String string String charArray This doesn t work String 类型的初始化与 C 构造函数类似 String
  • 您如何说服您的经理您的项目需要大规模重构? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我作为承包商加入了一个铁路项目 该项目已经进行了一年多 该代码由大约 10 名不同的开发人员编写 其中大多数也是承包商 他们有不同的代码风格 其
  • 将 `do` 表示法 `addStuff` 转换为 `>>=`

    向你学习 Haskell http learnyouahaskell com for a few monads more reader提出了addStuff功能 import Control Monad Instances addStuff
  • 确定红宝石的位置

    如何确定红宝石的位置 你可以试试 gem which rails 获取特定宝石的位置 或者 echo GEM HOME 获取您的宝石的主目录
  • 计算 JavaScript 对象中 true 的数量

    假设我有以下对象 items 1 true 2 false 3 true 4 true 我如何计算正确的数量 在本例中 这是一个返回数字 3 的简单函数 You can reduce物体的values 胁迫trues to 1并将它们添加到
  • Python elasticsearch.helpers.scan 示例

    有人可以提供 python elasticsearch helpers 客户端的扫描 API 示例吗 res elasticsearch helpers scan 如何使用 res 对象获取 elasticsearch 的所有结果 The
  • JavaScript 版本如何与 ECMAScript 版本关联?

    例如 map https developer mozilla org en JavaScript Reference Global Objects Array map是 在 JavaScript 1 6 中实现的 这是 ES5 方法吗 1
  • 如何使 JMX 自定义身份验证起作用?

    我在 JMX 上使用基于密码和访问文件的身份验证 在构建 JMXConnectorServer 时 我使用属性名称并且工作正常 Map
  • 如何在C#中获取HTTP Post数据?

    我正在使用 Mailgun API 有一个部分我需要向他们提供一个 URL 然后他们将通过 HTTP Post 一些数据给我 我提供这个网址 http test com MailGun Webhook aspx http test com
  • Android FM 信号强度

    我想知道 Android 中的 FM 收音机信号强度 为此我是否必须与硬件交互 或者有没有什么API可以直接给出信号强度的值 某些手机 提供 FM 收音机 不管怎样 你必须有一个内置的 FM 调谐器 收音机 为此我必须与 硬件与否 是的 当
  • Matlab OOP 从对象数组访问属性

    Matlab 新手来自 C C 我有一个对象数组 我试图访问数组中每个对象的值并将它们连接到一个变量中 Class sample properties GetAccess public SetAccess public ID Value e
  • 如果存在特定 cookie,则绕过 Akamai 的特定 URL

    如果存在指定的 cookie 即 如果用户登录到特定页面 我希望 Akamai 不缓存某些 URL 我们可以与 Akamai 合作吗 好消息是 我过去曾在 Top Gear 网站 www topgear com uk 上这样做过 其逻辑是
  • 缓存 [n async] 工厂方法的结果,前提是它不会抛出异常

    更新 在 usr 指出我错误地假设后进行了重大修改Lazy
  • 非锚定子字符串搜索:索引与正则表达式?

    我正在编写一些 Perl 脚本 需要进行大量字符串匹配 例如 my str1 this is a test string my str2 test 要查看 str1 是否包含 str2 我发现有两种方法 方法一 使用索引函数 if inde
  • 无法通过任何方法通过speech_recognition python获取音频?

    我正在尝试做SpeechRecognition 3 8 1 https pypi org project SpeechRecognition 听我的声音四天了 我已经在互联网上看到过以下内容 https github com Uberi s