yotsclee
Posts: 2
Joined: Fri Oct 07, 2016 10:09 am

Set USB microphone as default capture device

Fri Oct 07, 2016 10:18 am

Hi, I am working on a project which requires voice recognition using Raspberry Pi 3. I would like to capture audio using USB microphone and use 3.5mm jack for playback. I can play and record sound using below code.

Code: Select all

arecord -D hw:1,0 -r 16000 -f S16_LE test.wav

Code: Select all

aplay ./test.wav
But I cannot make the USB microphone to be the default device. Anyone has any clue about it? Thanks in advance!

My ultimate goal is to get the voice recognition working. If anyone has any good tutorial, please enlighten me.
https://pypi.python.org/pypi/SpeechRecognition/

User avatar
flatmax
Posts: 346
Joined: Thu May 26, 2016 10:36 pm

Re: Set USB microphone as default capture device

Fri Oct 07, 2016 12:01 pm

Yep - you can create an asoundrc file which instructs alsa on which device to use as the default (using the default plugin).

Code: Select all

pcm.!default {
	type hw
	card 0
}

ctl.!default {
	type hw           
	card 0
}
Check here for more information :
http://www.alsa-project.org/main/index. ... ult_plugin
Discuss hearing, acoustics, audio injector products, - https://lists.audioinjector.net/mailman/listinfo/people
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

yotsclee
Posts: 2
Joined: Fri Oct 07, 2016 10:09 am

Re: Set USB microphone as default capture device

Sat Oct 08, 2016 6:29 am

Hi FlatMax:

I am sorry that I am new to Raspberry Pi and Linux. Would you please show me an example how to set 3.5mm jack as audio output and USB microphone as capture input? Thanks a lot for your help! I really appreciated it.

:D :D

User avatar
flatmax
Posts: 346
Joined: Thu May 26, 2016 10:36 pm

Re: Set USB microphone as default capture device

Sun Oct 09, 2016 4:35 am

I can try to help you, sure.

Can you show me the device names ? Type the following into a terminal (https://www.raspberrypi.org/documentati ... /terminal/) :
arecord -L
Discuss hearing, acoustics, audio injector products, - https://lists.audioinjector.net/mailman/listinfo/people
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

Karthik N N
Posts: 3
Joined: Thu Mar 29, 2018 11:13 am

Re: Set USB microphone as default capture device

Thu Mar 29, 2018 11:18 am

Code: Select all

pcm.!default {
	type hw
	card 0
}

ctl.!default {
	type hw           
	card 0
}
Even this did not work for me :? :( :( :( :(
please help
thanks in advance

Karthik N N
Posts: 3
Joined: Thu Mar 29, 2018 11:13 am

Re: Set USB microphone as default capture device

Thu Mar 29, 2018 4:56 pm

Traceback (most recent call last):
File "/home/pi/Nandas/stt.py", line 8, in <module>
audio=r.listen(source)
File "/usr/local/lib/python3.4/dist-packages/speech_recognition/__init__.py", line 652, in listen
buffer = source.stream.read(source.CHUNK)
File "/usr/local/lib/python3.4/dist-packages/speech_recognition/__init__.py", line 161, in read
return self.pyaudio_stream.read(size, exception_on_overflow=False)
File "/usr/local/lib/python3.4/dist-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
KeyboardInterrupt

I am getting this error when executing
import speech_recognition as sr
#import urllib2

r=sr.Recognizer()
with sr.Microphone(device_index = 4, sample_rate = 48000) as source:
while True:
print("say")
audio=r.listen(source)
print("Could notdjgh")

BING_KEY = "36fd56ca622648b2bdc19dfbfb922ef7" # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
try:
print("I think you said " + r.recognize_bing(audio, key=BING_KEY))
except sr.UnknownValueError:
print("I could not understand audio")
except sr.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))

Please Help
Thanks in advance

Return to “Beginners”