0

I am writing a code in python which does speech recognition using the pyaudio module. When I first ran the code I got an error saying "no default input device detected" . So I got a USB sound card and a microphone but it still gives me the same error.

How do I get my code to use the usb sound card instead of my comp's inbuilt one? I have Ubuntu 16.04 and Python 3.6.5

This is my python code

import speech_recognition as sr
import pyaudio  #I tried using import pyaudio as well
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)
try:
    print("You said" + r.recognize_sphinx(audio))
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("error; {0}".format(e))

PS- My mic works well with applications like Audacity, so I don't think the mic is broken

this is the screenshot of the pavucontrol

enter image description here enter image description here

RishiC
  • 768
  • 1
  • 10
  • 34
  • what gives `sr.Microphone.list_microphone_names()` ? if you see your mic, you can specify the `device_index` parameter. Check this doc : https://realpython.com/python-speech-recognition/#the-microphone-class – PRMoureu May 20 '18 at 06:40
  • I can't see my mic either, i ran mic = sr.Microphone() and it gave me error of no default input device instead of a list of input devices – RishiC May 20 '18 at 06:46
  • does the mic work outside python ? i don't get the same list of devices with `sr.Microphone()`, i got more devices with `print(sr.Microphone.list_microphone_names())` – PRMoureu May 20 '18 at 07:03
  • Yes the mic works outside of Python – RishiC May 20 '18 at 07:13
  • Tried doing print(sr.Microphone.list_microphone_names()) but it just returned an empty list – RishiC May 20 '18 at 15:21
  • Have you already read [this post](https://github.com/shichao-an/soundmeter/issues/7#issuecomment-223741029) and the links proposed by the author ? – PRMoureu May 20 '18 at 16:58
  • i have added a few screenshots to my question..please have a look at those – RishiC May 21 '18 at 05:17

0 Answers0