7

I'm looking for some help in configuring the audio on a Raspberry Pi as all my Googling efforts have fallen short so far!

My setup:

  • Raspberry PI 3 (running Debian Jessie)
  • USB WebCam (Logitech) which I'm using to capture audio
  • External speaker in 3.5mm audio jack which is used for playback

So far I've managed to configure ALSA to, by default, capture via the USB Webcam and playback via the 3.5mm jack. For example, the following works fine:

# Capture from Webcam
arecord test.wav

# Playback through 3.5mm jack
aplay test.wav

By default this captures audio in 8-bit, 8KHz, Mono. However, I'd like the default capture process to use 16-bit, 16KHz, Mono settings, and this is where I'm stuck.

Here's my working ~/.asoundrc file:

pcm.!default {

        type asym

        playback.pcm {
                type hw
                card 1
                device 0
        }

        capture.pcm {
                type plug
                slave {
                        pcm {
                                type hw
                                card 0
                                device 0
                        }
                }
        }
}

And my /etc/modprobe.d/alsa-base.conf:

options snd_usb_audio index=0
options snd_bcm2835 index=1

options snd slots=snd-usb-audio,snd-bcm2835

And the output of cat /etc/asound/cards:

 0 [U0x46d0x825    ]: USB-Audio - USB Device 0x46d:0x825
                      USB Device 0x46d:0x825 at usb-3f980000.usb-1.4, high speed
 1 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA

I've followed various guides to set the format, rate and channels attributes without any success. For example, this didn't work:

pcm.!default {

        type asym

        playback.pcm {
                type hw
                card 1
                device 0
        }

        capture.pcm {
                type plug
                slave {
                        pcm {
                                type hw
                                card 0
                                device 0
                        }
                        format S16_LE
                        rate 16000
                        channels 1
                }
        }
}

(I've also tried moving those attribute inside the pcm block in one of many desperate attempts!)

In truth I have no experience with audio on Linux at all, and am utterly lost and any guidance would be hugely appreciated!

jgauld
  • 639
  • 5
  • 10

1 Answers1

0

aplay uses whatever sample format the file actually has, but arecord creates a new file, so you have to specify the sample format if you do not want the silly defaults:

arecord -f S16_LE -r 16000 -c 1 test.wav
CL.
  • 173,858
  • 17
  • 217
  • 259
  • Yeh, I've got recording working by specifying arguments, but I'm trying to understand how to configure things so I don't need to specify any command line args when recording. I thought the `format`, `rate` and `channels` parameters in the `~/.asoundrc` file would do this (and maybe they do and I've just used them incorrectly), but so far I've fallen short! – jgauld Mar 30 '16 at 18:59
  • 1
    Those parameters in the configuration file can restrict the device, but that does not work unless the application also uses the same values. (Some applications ask the device what it actually supports; `arecord` does not.) – CL. Mar 31 '16 at 06:30
  • Thanks for the clarification, that helps a lot. So I could, perhaps, create a simple shell script that parses `.asoundrc` for the default settings and then calls `arecord` with those arguments. – jgauld Apr 09 '16 at 12:12