Skip to content
Advertisement

Pyaudio does not recognize ReSpeaker usb microphones InputChannels

I have connected an USB microphone (ReSpeaker 4 Mic Array (UAC1.0)) to my Gentoo linux machine. I would like to use that usb microphone for recording with pyaudio. Pyaudio detects the USB device but does not detect its Input Channels.

This is the relevant part of the output from:

import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
     print p.get_device_info_by_index(i)

[…]

‘maxOutputChannels’: 2L, ‘name’: u’HDA Intel PCH: AD198x Analog (hw:0,0)’, ‘defaultHighInputLatency’: -1.0}

{‘defaultSampleRate’: 16000.0, ‘defaultLowOutputLatency’: 0.024, ‘defaultLowInputLatency’: -1.0, ‘maxInputChannels’: 0L, ‘structVersion’: 2L, ‘hostApi’: 0L, ‘index’: 1, ‘defaultHighOutputLatency’: 0.096, ‘maxOutputChannels’: 2L, ‘name’: u’ReSpeaker 4 Mic Array (UAC1.0): USB Audio (hw:1,0)’, ‘defaultHighInputLatency’: -1.0}

{‘defaultSampleRate’: 44100.0, ‘defaultLowOutputLatency’: -1.0, ‘defaultLowInputLatency’: 0.008707482993197279, ‘maxInputChannels’: 2L, ‘structVersion’: 2L, ‘hostApi’: 0L, ‘index’: 2, ‘defaultHighOutputLatency’: -1.0, ‘maxOutputChannels’: 0L, ‘name’: u’PrimeSense Device: USB Audio (hw:2,0)’, ‘defaultHighInputLatency’: 0.034829931972789115}

[…]

wheras

 $ arecord -l

Succesfully detected the mic as input device.

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: AD198x Analog [AD198x Analog]
  Subdevices: 0/2
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
card 1: ArrayUAC10 [ReSpeaker 4 Mic Array (UAC1.0)], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 2: Device [PrimeSense Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: Phone [MT65xx Android Phone], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

I Suppose arecord and pyaudio are indepenedent from each other, but what can i do to have the Microphone recognized by Pyaudio as Mcrophone? Is there some configuration file that has to be adapted?

Any help very much appreciated.

Advertisement

Answer

So in my case pulseaudio was blocking the device. And i found several options to change this:

  1. Check if pulseaudio block the device with lsof | grep "/dev/snd/"

    Set autospawn = no in /etc/pulse/client.conf link

    And call

    pulseaudio --kill
    systemctl --user stop pulseaudio.socket
    systemctl --user stop pulseaudio.service
    

    Afterwards lsof | grep "/dev/snd/" was empty and

    import pyaudio
    p = pyaudio.PyAudio()
    for i in range(p.get_device_count()):
         print p.get_device_info_by_index(i)
    

    yields:

    […] {‘defaultSampleRate’: 16000.0, ‘defaultLowOutputLatency’: 0.024, ‘defaultLowInputLatency’: 0.024, ‘maxInputChannels’: 6L, ‘structVersion’: 2L, ‘hostApi’: 0L, ‘index’: 3, ‘defaultHighOutputLatency’: 0.096, ‘maxOutputChannels’: 2L, ‘name’: u’ReSpeaker 4 Mic Array (UAC1.0): USB Audio (hw:3,0)’, ‘defaultHighInputLatency’: 0.096} […]

  2. If you still want pulseaudio to handle your other devices but ignore your USB device, this can be done using udev. link

  3. Another option is to unload the pulseaudio module index that detected the usb device link.

    call pactl list and find the line of your device e.g.:

    Owner Module: 7

    then call pactl unload-module 7

  4. What also worked for me is to unload the module-udev-detect before plugging in the USB Microphone via

    pactl unload-module module-udev-detect

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement