Wednesday, January 2, 2019

Raspberry Pi Index Page

Configure and test audio on the Pi



  • Please follow prior steps to install Raspbian.
  • Connect the USB microphone and 3.5mm jack speaker
  • Go to the UI and 
    • Click on the Raspberry icon > Preferences> Audio Device settings 
    • Select "USB PnP Sound Device (Alsa Mixer)
    • Click "Select Controls", select Microphone and make the Microphone audio to its highest.



  • Run "sudo raspi-config" on the terminal
  • Select "Advanced Options"
  • Select "Audio"
  • Select "Force 3.5mm headphone jack"
  • Select "Finish"








Setting Mic and Audio controls:

  • Run the command "aplay -l" (its -L lowercase) in the terminal
  • Copy the card # and device # (for speaker)
  • Run the command "arecord -l" (its -L lowercase) in the terminal
  • Copy the card # and device # (for Mic)
  • Open a new file under /home/pi
  • vi .asoundrc
  • Copy paste the below

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}
pcm.mic {
  type plug
  slave {
    pcm "hw:1,0"
  }
}
pcm.speaker {
  type plug
  slave {
    pcm "hw:0,0"
  }
}

In the above

pcm "hw:1,0" under pcm.mic is hw:<card#>,<device#>

Please use the correct one from aplay (Speaker) and arecord (Mic) as mentioned above.


Test Audio:
  • ssh to the Pi (or run the commands directly on a terminal on the pi)
  • Run the command "speaker-test -t wav"
  • You should hear voice from the speaker
  • Our speaker is configured.
Test Mic:
  • ssh to the Pi (or run the commands directly on a terminal on the pi)
  • Run the command
    arecord --format=S16_LE --duration=10 --rate=16000 --file-type=raw out2.wav
  • Say something near the microphone for 10 sec [Note duration above is in seconds]
  • To replay, run the command
  • aplay --format=S16_LE --rate=16000 out2.wav
Your Mic and speaker are now configured.