HomeLabContactFor HireCodeArticles/Blog /0/0 18.208.187.128
< >

Asterisk ALSA notes for Dial(CONSOLE/ALSA...

2022-03-10 by: meuon
On Asterisk 16.2 on a small ARM SoC computer using a very generic USB to 3.5mm audio out simply recognized as "USB PnP Sound Device". Some notes:

Alsa Configuration

in /etc/asound.conf
pcm.!default {
    type hw
    card 1
}
ctl.!default {
    type hw           
    card 1
}

Asterisk Config

In /etc/asterisk/alsa.conf
[general]
autoanswer=yes
context=local
extension=s
input_device=plughw:1,0
output_device=plughw:1,0
noaudiocapture=true
;above turns off mic/input 
The magic is plughw because aplay -L lists
plughw:CARD=Device,DEV=0
    USB PnP Sound Device, USB Audio
    Hardware device with all software conversions

This solves the problem/errors with 8000hz and 44100hz conversions. like
chan_alsa.c: Rate not correct, requested 8000, got 44100
as Alsa will do some magic conversions. Also solved Stereo to Mono

This post exists because I could not find anyone using this to solve that problem, but lots of people are having that problem with an insane amount of bad "assistance" out there.,

You also need to put this in /etc/asterisk/modules.conf

noload = chan_oss.so
load = chan_alsa.so

Asterisk Usage

Lots of variations of how to get here, but the important part is:
    same => n,Dial(CONSOLE/ALSA,20,A(beep))

And file system perms

I have a script on boot up that does chown -R asterisk:audio /dev/snd/* to fix the perms. Note that they get reset on boot and on USB audio device insertion and this causes asterisk's ALSA load to blow chunks. You can also set asterisk to be part of the audio group and and.. other ways. Just gotta make sure Asterisk can use that /dev/snd/*
#ls -al /dev/snd

drwxr-xr-x  4 asterisk audio     220 Mar 10 15:35 .
drwxr-xr-x 20 root     root     4420 Mar 10 15:35 ..
drwxr-xr-x  2 asterisk audio      60 Mar 10 15:35 by-id
drwxr-xr-x  2 asterisk audio      80 Mar 10 15:35 by-path
crw-rw----  1 asterisk audio 116,  6 Mar 10 15:35 controlC0
crw-rw----  1 asterisk audio 116,  4 Mar 10 15:35 controlC1
crw-rw----  1 asterisk audio 116,  5 Mar 10 15:35 pcmC0D0p
crw-rw----  1 asterisk audio 116,  3 Mar 10 15:35 pcmC1D0c
crw-rw----  1 asterisk audio 116,  2 Mar 10 15:37 pcmC1D0p
crw-rw----  1 asterisk audio 116,  1 Mar 10 15:35 seq
crw-rw----  1 asterisk audio 116, 33 Mar 10 15:35 timer

Finally

So now, on more modern Asterisk systems using bare ALSA (No pulseaudio, no JackD, etc.. ) you can use that 3.5mm audio jack, or in this case, a USB to 3.5mm audio socket to feed a PA system, overhead speakers, etc..

Disclaimer: This has worked for me, using Allwinner H6's running Armbian on exactly 2 boxen. YMMV, Good Luck!