首页 文章

Pyaudio:没办法'get_device_count'

提问于
浏览
0

我正在使用Python Speech Recognition library识别来自麦克风的语音输入 .

这适用于我的默认麦克风 . 这是我正在使用的代码 . 根据我对文档的理解

创建一个新的Microphone实例,它表示计算机上的物理麦克风 . AudioSource的子类 . 如果未指定device_index或None,则默认麦克风用作音频源 . 否则,device_index应该是用于音频输入的设备的索引 . https://pypi.python.org/pypi/SpeechRecognition/

问题是当我想用pyaudio.get_device_count()得到节点时 - 1.我收到了这个错误 .

AttributeError:'module'对象没有属性'get_device_count'

所以我不确定如何配置麦克风使用USB麦克风

import pyaudio
import speech_recognition as sr

index = pyaudio.get_device_count() - 1
print index

r = sr.Recognizer()

with sr.Microphone(index) as source: 
    audio = r.listen(source) 

try:
    print("You said " + r.recognize(audio))   
except LookupError:                           
    print("Could not understand audio")

2 回答

  • 0
    myPyAudio=pyaudio.PyAudio()
    print "Seeing pyaudio devices:",myPyAudio.get_device_count()
    
  • 0

    这是图书馆里的一个错误 . 我刚刚在1.3.1中推出了一个修复程序,所以现在应该修复了!

    版本1.3.1保留与先前版本的完全向后兼容性 .

相关问题