Raspberry ALSA sound output / input slave
Asked Answered
E

2

5

I'm trying to set one device for playback and another one for capture, my nano /etc/asound.conf has this:

pcm.!default {
        type asym
        playback.pcm "plughw:1,1"
        capture.pcm  "plughw:1,0"
}

ctl.!default {
        type hw
        card 0
}

I can play sound perfectly, but I cannot record sound, my python code is throwing this errors:

ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) 
unable to open slave
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 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_dmix.c:1018:(snd_pcm_dmix_open) 
unable to open slave

This is a part of the code I'm running:

import pyaudio
class Microphone(AudioSource):
    def __init__(self, device_index = None):
        self.device_index = device_index
        self.format = pyaudio.paInt16 # 16-bit int sampling
        self.SAMPLE_WIDTH = pyaudio.get_sample_size(self.format)
        self.RATE = 16000 # sampling rate in Hertz
        self.CHANNELS = 1 # mono audio
        self.CHUNK = 1024 # number of frames stored in each buffer

        self.audio = None
        self.stream = None

    def __enter__(self):
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(
            input_device_index = self.device_index,
            format = self.format, rate = self.RATE, channels = self.CHANNELS, frames_per_buffer = self.CHUNK,
            input = True, # stream is an input stream
        )
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        self.stream.stop_stream()
        self.stream.close()
        self.stream = None
        self.audio.terminate()

How am I supposed to fix this error?

Thank you in advance.

Eboat answered 21/11, 2014 at 2:54 Comment(5)
What program generates this output?Corbel
@Corbel Just posted a bit of the code, I'ts pyaudio.Eboat
What is device_index?Corbel
@Corbel I'm setting as None|0, if I set it as 1 it throws me a compilation error, if I set it as 0 it throws me the error I posted.Eboat
@Corbel I don't know if alsa-base has something to do with this, but it has this options snd-usb-audio index=0 and that's the one I want to use, that's why I'm setting 0.Eboat
C
7

pyaudio is based on PortAudio; all those silly messages are because of PortAudio's attempts to enumerate audio devices.

pyaudio device indexes are not necessarily the same as ALSA card indexes. Use get_device_count() and get_device_info_by_index() to find the input device to use.

Corbel answered 22/11, 2014 at 11:4 Comment(0)
T
2

The only answer I have is to buy an audio card with both input and output facility and make that the default "card." I am trying to do the same thing. I have even tried modifying the source code of PyAudio, without success. So the hardware route is currently the solution.

Titer answered 16/4, 2015 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.