Audio in to Python3


#1

I have the USB audio Input / Output dongle -> ADP009 and I can successfully record sound using Audacity. However I want to read in an audio stream into Python3 as shown in this link:-
https://github.com/aubio/aubio/blob/master/python/demos/demo_alsa.py
Basically the code gets this far:-
import alsaaudio
import numpy as np
import aubio

samplerate = 44100
win_s = 2048
hop_s = win_s // 2
framesize = hop_s
recorder = alsaaudio.PCM(type=alsaaudio.PCM_CAPTURE)

And then it bombs out with the error
alsaaudio.ALSAAudioError: No such file or directory [default]
Google seems to show a few errors like this but no solution. Any idea how I can get at the audio input from this dongle into Python?


#2

This is, presumably, because you have no audio device named “default”. See details of the alsaaudio.PCM() constructor here: https://larsimmisch.github.io/pyalsaaudio/libalsaaudio.html#pcm-objects

And this might be useful for finding the right device: https://larsimmisch.github.io/pyalsaaudio/libalsaaudio.html#alsaaudio.pcms


#3

Thanks,
I am not sure I understand the answer however. I did do a
$ arecord -L

null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
default:CARD=Device
USB PnP Sound Device, USB Audio
Default Audio Device
sysdefault:CARD=Device
USB PnP Sound Device, USB Audio
Default Audio Device
front:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Front speakers
surround21:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct sample mixing device
dsnoop:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct sample snooping device
hw:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Direct hardware device without any conversions
plughw:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Hardware device with all software conversions

Is the key in that lot?


#4

Might be worth plugging a few things from there into:

alsaaudio.PCM(type=PCM_CAPTURE, device='<card name goes here>')

Or trying:

alsaaudio.PCM(type=PCM_CAPTURE, cardindex=0)
# or
alsaaudio.PCM(type=PCM_CAPTURE, cardindex=1)