I've got a USB sound card which I'm trying to record from using the standard pyaudio tutorial for recording however I get the following (below). Frustratingly this script actually works on my mac and I can't understand what I have to do in order to get this working on the pi.
> ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition
> 'cards.BRCM bcm2835 AL.pcm.front.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> front ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> cards.pcm.rear ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> cards.pcm.center_lfe ALSA lib pcm.c:2217:(snd_pcm_open_noupdate)
> Unknown PCM cards.pcm.side ALSA lib confmisc.c:1286:(snd_func_refer)
> Unable to find definition 'cards.BRCM bcm2835
> AL.pcm.surround40.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> surround40 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835 AL.pcm.surround51.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> surround41 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835 AL.pcm.surround51.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> surround50 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835 AL.pcm.surround51.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> surround51 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835 AL.pcm.surround71.0:CARD=0' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> surround71 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835
> AL.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> iec958 ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835
> AL.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> spdif ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find
> definition 'cards.BRCM bcm2835
> AL.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2' ALSA lib
> conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned
> error: No such file or directory ALSA lib
> conf.c:4720:(snd_config_expand) Evaluate error: No such file or
> directory ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> spdif ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> cards.pcm.hdmi ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> cards.pcm.hdmi ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM
> cards.pcm.modem ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown
> PCM cards.pcm.modem ALSA lib pcm.c:2217:(snd_pcm_open_noupdate)
> Unknown PCM cards.pcm.phoneline ALSA lib
> pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
> ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports
> only playback stream ALSA lib
> pcm_direct.c:877:(snd1_pcm_direct_initialize_slave) slave plugin does
> not support mmap interleaved or mmap noninterleaved access ALSA lib
> pcm_dmix.c:1030:(snd_pcm_dmix_open) unable to initialize slave Cannot
> connect to server socket err = No such file or directory Cannot
> connect to server request channel jack server is not running or cannot
> be started Expression 'r' failed in
> 'src/hostapi/alsa/pa_linux_alsa.c', line: 2018 Expression
> 'PaAlsaStreamComponent_FinishConfigure( &self->capture,
> hwParamsCapture, inParams, self->primeBuffers, realSr, inputLatency )'
> failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2655 Expression
> 'PaAlsaStream_Configure( stream, inputParameters, outputParameters,
> sampleRate, framesPerBuffer, &inputLatency, &outputLatency,
> &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c',
> line: 2767 Traceback (most recent call last): File "hello-world.py",
> line 17, in <module>
> frames_per_buffer = chunk) File "/usr/lib/pymodules/python2.7/pyaudio.py", line 714, in open
> stream = Stream(self, *args, **kwargs) File "/usr/lib/pymodules/python2.7/pyaudio.py", line 396, in __init__
> self._stream = pa.open(**arguments) IOError: [Errno Unanticipated host error] -9999
edit **
Although I'm still receiving those errors I am able to record from the mic and also play back through the audio out. I found that lowering the number of chunks to 256 and also removed a channel in my pyaudio script worked. I also found that my usb sound card plugged into my usb hub plugged into my pi actually caused the pi to throw I/O exceptions every now probably because of the round about way of connecting the sound card. Therefore I've added a try catch block around my read code and just skip over lost samples.
CHUNK = 256
FORMAT = pyaudio.paInt16
SHORT_NORMALIZE = (1.0/(2**15)) #(1.0/32768.0)
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5