Diego
Diego

Reputation: 964

Pyaudio: no method 'get_device_count'

I'm using the Python Speech Recognition library to recognize speech input from the microphone.

This works fine with my default microphone. This is the code I'm using. According to what I understood of the documentation

Creates a new Microphone instance, which represents a physical microphone on the computer. Subclass of AudioSource.

If device_index is unspecified or None, the default microphone is used as the audio source. Otherwise, device_index should be the index of the device to use for audio input. https://pypi.python.org/pypi/SpeechRecognition/

The problem is that when I want to get the node with pyaudio.get_device_count() - 1. I'm getting this error.

AttributeError: 'module' object has no attribute 'get_device_count'

So I'm not sure how to configure the microphone to use a usb microphone

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")

Upvotes: 0

Views: 1959

Answers (2)

Anthony Zhang
Anthony Zhang

Reputation: 86

That's a bug in the library. I just pushed out a fix in 1.3.1, so this should now be fixed!

Version 1.3.1 retains full backwards compatibility with previous versions.

Upvotes: 1

ralphie boy
ralphie boy

Reputation: 69

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

Upvotes: 2

Related Questions