Pulseaudio support for sound output


#1

Dear all, I asked this question in the Archive, but seems nobody is looking at it. Sorry for duble posting.

I desperately try to send the output over puseaudio to a remote-sink. Seems that Snips insists to play through a native ALSA device.

I managed it to send the audio via snd-aloop, but pulseaudio would be more stabel, better quality and more flexible. Any hint, how I manage to play sound over pulseaudio on raspbian?


PulseAudio support
Sattelite for audio output only
#2

Hello,

You have to configure2 files. /etc/asound.conf for a general config and .asoundrc in each profile user.
Put this inside :

pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
pcm.default pulse
ctl.default pulse

After, you need to configure pulseuadio with /etc/pulseaudio/default.pa
Don’t forget that pulseaudio daemon is started with user account (who open the session in gdm)

You can use pacmd or pactl command for testing your sink.

Ced


#3

Hi, many thanks for the hint! I am using Raspbian Stretch Lite without Desktop. Do I have to configure something special, that pulseaudio starts and snips can use it?


#4

If you d’ont use the desktop, you have to use pulseaudio as sytemwide.
I did not use this type of pulseaudio configuration yet. So i can’t tell you more.
But, if snips uses asound.conf for his audio configuration, there is no reason that does not work :slight_smile:


#5

With asound.conf I never managed to play the audio via pulseaudio.

speaker-test -c2 -twav

Was playing correctly on the remote sink, snips was ignoring any pulse setup and playing on the ALSA device.

It sems that snips is using only the device when specified with the ‘!’.

pcm.!default

But pulseaudio needs this setting as far as I understand. Hence snips is playing directly to the ALSA device.


#6

i quickly did the test and it works for me.
Maybe try this asound.conf :

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

I quickly configure pulseaudio in systemwide and i can switch audio from my bluetooth speaker to usb speaker with pactl set-default-sink. Don’t forget to give correct right to user _snips, root etc…

You can do this and check the log :
sudo -u _snips snips-audio-server

Ced


[idea] set up a satellite without audio-hardware by using voip or a sip phone
#7

This was the key!! Many many thanks! It works perfectly without modifying asound.conf. I will post a guide how to do this setup, it took me at the end many hours… But this is a good step forward for me.


#8

Happy for you !!! :wink:


#9

As promized a guide on how to setup pulseaudio system wide. It includes optional steps to connect to a remote pulseaudio in order to play the sound somewhere else. This was the reason why I setup pulsoudio.

The guide was tested on Raspbian Stretch Lite

Comments start with #

# check if sound works before starting installing pulesaudio
arecord -L
# this microphone(s) should be listet

aplay -L
# the sound output device should be listet

# check volumes are not muted and above 50 %
alsamixer

# test sound output
speaker-test -c2 -twav

#--------------------------------------------------------------
# start only, if everthing works till here

# install pulse audio
sudo apt install -y pulseaudio
pactl list short sinks
# the sound output device should be listet
 
pactl list short sources
# this microphone(s) should be listet

#--------------------------------------------------------------
# setup pulseaudio  system wide

# create service file
#--------------------------------------------
sudo cat <<EOF >>/etc/systemd/system/pulseaudio.service
[Unit]
Description=PulseAudio system-wide server
# network only required for remote sinks
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/pulse/pid
ExecStart=/usr/bin/pulseaudio --daemonize --system --realtime --log-target=journal
ExecStop=/usr/bin/pulseaudio -k

[Install]
WantedBy=multi-user.target

EOF
#--------------------------------------------
# check if the file exist otherwise use: sudo nano /etc/systemd/system/pulseaudio.service
cat /etc/systemd/system/pulseaudio.service

# disable pulseaudio in user modes
sudo systemctl --global disable pulseaudio.service pulseaudio.socket

# enable system mode
sudo systemctl enable pulseaudio
sudo systemctl start pulseaudio
systemctl --system status pulseaudio.service

# grant access to pi user
sudo usermod -G pulse-access -a pi

# grant access to snips user if installed already
# otherwise you need to do this after snips setup
sudo usermod -G pulse-access -a _snips
# restart snips-audio-server
sudo systemctl restart snips-audio-server

# check divices
pactl list short sinks
pactl list short sources

# set default microphone
pactl list short sources
# 0       alsa_output.platform-soc_audio.analog-stereo.monitor    module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
# 1       alsa_output.platform-soc_sound.seeed-2ch.monitor        module-alsa-card.c      s32le 8ch 48000Hz       SUSPENDED
# 2       alsa_input.platform-soc_sound.seeed-8ch module-alsa-card.c      s32le 8ch 48000Hz       SUSPENDED

# make last microphone as default
pactl set-default-source 2

# set default output
pactl list short sinks
# example
# 0       alsa_output.platform-soc_audio.analog-stereo    module-alsa-card.c      s16le 2ch 48000Hz       SUSPENDED
# 1       alsa_output.platform-soc_sound.seeed-2ch        module-alsa-card.c      s32le 8ch 48000Hz       SUSPENDED

# make first card as default
pactl set-default-sink 0

# test output
speaker-test -c2 -twav

Now we can configure the remote sink via pulseaudio in order to play onanother pi for example

# configure the pulseaudio server where the sound should be played also in systemwide
# in additon add at the end of system.pa
sudo nano /etc/pulse/system.pa

load-module module-native-protocol-tcp auth-anonymous=1
# attention the option auth-anonymous=1 allows to connect any source, there are options to limit on IP and/or cookie

 #-------------------------------------------------------------
# configure the pulseaudio client where the sound should come from

# try manual config first
pactl load-module module-tunnel-sink server=your_pulse_server_ip_or_host sink_name=you_choose_a_name
pactl list short sinks
# your remote-sink should be listed now
# set it a default
pactl set-default-sink 2
# test output
speaker-test -c2 -twav

# if all works, we are going now to configure this permanently in system.pa
# add at the end
sudo nano /etc/pulse/system.pa
load-module module-tunnel-sink server=your_pulse_server_ip_or_host sink_name=you_choose_a_name

# set it to the name you have choosen above
set-default-sink you_choose_a_name

sudo systemctl restart pulseaudio
speaker-test -c2 -twav
# the sound should be played on the remote sink

After the setup you do not need to do sam setup audio. This assistent is overwriting ALSA config which might have bad impact to pulseaudio. I try to avoid to use sam setup audio at all.

Before I managed to setup pulsoudio I had a working configuration with snd-aloop. But I think pulse audio is much more stable.