0

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")
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
Diego
  • 916
  • 1
  • 13
  • 36

2 Answers2

2
myPyAudio=pyaudio.PyAudio()
print "Seeing pyaudio devices:",myPyAudio.get_device_count()
  • I'm working on the same problem. My line of attack is to find the __init__.py where it creates the Microphone class. I will modify this function: If the input to initialize class Microphone is None, somehow create an AudioSource, corresponding to the card with the microphone, and use that source to iniitialize the Microphone. – ralphie boy Mar 29 '15 at 19:57
  • In my case I am up the creek because on my Raspberry Pi the default sound card HAS NO INPUT ABILITY. So I need the microphone to be associated with the USB sound "card", which is a Logitech C310. – ralphie boy Mar 29 '15 at 20:06
  • I'm trying to do it work with a BBB. Let me know if you can do it work – Diego Mar 31 '15 at 12:52
  • I got it working by calling "arecord" from python. That creates a *.wav audio file which can be processed instead of direct microphone input. – ralphie boy Apr 03 '15 at 14:48
1

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.