Konubinix' opinionated web of thoughts

Pulseaudio

Fleeting

pulseaudio

Using Ubuntu PC as a Bluetooth headset for receiving calls: A Setup Guide

This is what I tried.

Install ofono1

sai ofono

Connect to my phone

bluetoothctl
$ scan on
$ connect [MYPHONE]

I can indeed hear the music but calling my answering machine, I don’t get the sound.

Load the bluetooth discover module with ofono support2

module_number=$(pactl list modules short |gi module-bluetooth-discover|cut -f1)
pactl unload-module ${module_number}
pactl load-module module-bluetooth-discover headset=ofono

Note that now, when connecting with my phone, I have to accept some authorization again at each connection.

Add

<policy user="sam">
  <allow send_destination="org.ofono"/>
</policy>

into /etc/dbus-1/system.d/ofono.conf3

Then, calling works. I don’t know whether the /etc/dbus-1/system.d/ofono.conf did anything, but I could check that restarting pulseaudio without ofono make it disappear again.

To persist the configuration, I put this in ~/.config/pulse/default.pa

.include /etc/pulse/default.pa
.ifexists module-bluetooth-discover.so
 unload-module module-bluetooth-discover
 load-module module-bluetooth-discover headset=ofono
.endif

mettre le son d’android sur mon pc sur bluetooth

sudo apt-get install pulseaudio-module-bluetooth

bluetoothctl

pactl load-module module-bluetooth-policy pactl load-module module-bluetooth-discover

how to record the sound coming from an application

Say I want to save something that is currently played on my machine.

recording the sound card

Pulseaudio provides a source called monitor for each sound card

pacmd list-sources | grep name: |grep monitor
name: <alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo.monitor>
name: <alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo.monitor>
name: <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>

I can see that I have a monitor source for each card I have.

I only need to run parecord then.

parecord --device=alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo.monitor > output.wav

recording from an application only

Following this instructions4

pacmd list-sink-inputs
2 sink input(s) available.
    index: 131
        driver: <protocol-native.c>
        flags:
        state: RUNNING
        sink: 0 <alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo>
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        muted: no
        current latency: 287.33 ms
        requested latency: 42.67 ms
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        resample method: (null)
        module: 9
        client: 147 <ALSA plug-in [sox]>
        properties:
                media.name = "ALSA Playback"
                application.name = "ALSA plug-in [sox]"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "35"
                application.process.id = "2753496"
                application.process.user = "sam"
                application.process.host = "konixwork"
                application.process.binary = "sox"
                application.language = "C"
                window.x11.display = ":0"
                application.process.machine_id = "21fdcf6901834b06813ffa8423c27210"
                application.process.session_id = "2"
                module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [sox]"
    index: 144
        driver: <protocol-native.c>
        flags:
        state: RUNNING
        sink: 0 <alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo>
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        muted: no
        current latency: 107.98 ms
        requested latency: 30.00 ms
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        resample method: (null)
        module: 19
        client: 189 <ALSA plug-in [snapclient]>
        properties:
                media.name = "ALSA Playback"
                application.name = "ALSA plug-in [snapclient]"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "33"
                application.process.id = "1"
                application.process.user = "sam"
                application.process.host = "konixwork"
                application.process.binary = "snapclient"
                application.language = "C"
                application.process.machine_id = "79372d8564c8545262975c46157f1482"
                module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [snapclient]"

My snapclient is running on sink 144.

I then run

pactl load-module module-null-sink sink_name=steam
pactl move-sink-input 144 steam

And get the sound to stop being heard.

Then

parecord -d steam.monitor > truc.wav

And then vlc truc.wav shows that the file indeed contains the sound.

I don’t know the difference between parecord and parec, but the suggested command works as well.

parec -d steam.monitor | oggenc -b 192 -o steam.ogg --raw -

record only one application while still hearing the sound

I want the sink input to go to the null sink and be recorded to a file while still be streamed.

I can combine two sinks into one with the module-combine-sink.

Provided I already created the null sink.

pactl load-module module-combine-sink sink_name=combined slaves=steam,alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo

Then I can move the application to use the combined sink.

pactl move-sink-input 144 combined

The sound will go to the sound card AND to the null sink, allowing me to hear the sound while recording it with.

parecord -d steam.monitor > truc.wav

doing the same thing without the extra null sink

Actually, what I need is only a proxy sink that will redirect its content to the sound card and record this proxy. This can simply achieved with the same module.

pactl load-module module-combine-sink sink_name=proxy slaves=alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo
parecord -d proxy.monitor > output.wav

set device for program

linux - Set device for program in PulseAudio? - Super User

I don’t know if there is a setting or configuration file for this anywhere but it can be done with environment variables. I’ve based my answer on this entry in the PulseAudio FAQ about setting the recording source. I’ve tried this with output (a sink in PulseAudio) but it should work for both input and ouput.

The first step is to get the internal name of the source and sink that you want to use. To do that you need to use the pactl list command. That command will return a pile of data, but the following will list just the source names:

LANG=C pactl list | grep -A2 ‘Source #’ | grep ‘Name: ’ | cut -d" " -f2 That list will probably include the names for both regular sources and PulseAudio’s monitor sources (which on my system have “monitor” in the name). You’ll want to use the regular source name of the device you want to target.

You can do the same thing to get the sink names:

LANG=C pactl list | grep -A2 ‘Sink #’ | grep ‘Name: ’ | cut -d" " -f2 Once you’ve got the names you can run something like the following from your terminal:

PULSE_SINK=<sink_name> PULSE_SOURCE=<source_name> <command_to_run_skype> Of course, if you want to run this from a menu you’ll probably need to create a shell script and use that instead of the default command. Something like this should work:

#!/bin/sh set PULSE_SINK <sink_name> set PULSE_SOURCE <source_name> <command_to_run_skype>

where are the config files

where is located the pulse audio conf file

strace pulseaudio 2>&1|gi conf|gv alsa|gv font
openat(AT_FDCWD, "/home/sam/.pulse//daemon.conf", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/sam/.config/pulse//daemon.conf", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[...]

It does not honor XDG_CONFIG_HOME…

FILES ~/.config/pulse/daemon.conf, /etc/pulse/daemon.conf: configuration settings for the PulseAudio daemon. If the version in the user’s home directory does not exist the global configuration file is loaded. See pulse- daemon.conf(5) for more information.

~/.config/pulse/default.pa, /etc/pulse/default.pa: the default configuration script to execute when the PulseAudio daemon is started. If the version in the user’s home directory does not exist the global configu‐ ration script is loaded. See default.pa(5) for more information.

~/.config/pulse/client.conf, /etc/pulse/client.conf: configuration settings for PulseAudio client applica‐ tions. If the version in the user’s home directory does not exist the global configuration file is loaded. See pulse-client.conf(5) for more information.

Manpage for pulseaudio

Notes linking here


  1. seems that by utilizing Bluez 5 and adding " ofono “, achieving this is feasible

    https://copyprogramming.com/howto/how-to-set-up-ubuntu-pc-as-bluetooth-headset-to-attend-calls

     ↩︎
  2. load-module module-bluetooth-discover headset=ofono

    https://copyprogramming.com/howto/how-to-set-up-ubuntu-pc-as-bluetooth-headset-to-attend-calls

     ↩︎
  3. in order to provide authorization, the following must be included in the /etc/dbus-1/system.d/ofono.conf file (prior to <code> &lt;/busconfig&gt; </code> ;-) :

    <policy user=“pulse”> <allow send_destination=“org.ofono”/> </policy>

    https://copyprogramming.com/howto/how-to-set-up-ubuntu-pc-as-bluetooth-headset-to-attend-calls

     ↩︎
  4. Try something like this:

    In a terminal enter

    pacmd (this is the CLI of the PulseAudio-Server) then use

    list-sink-inputs (where you get the indices of the running inputs) Now find the index of your input. Now referred to as $INDEX

    the scriptable part is:

    1. pactl load-module module-null-sink sink_name=steam
    2. pactl move-sink-input $INDEX steam
    3. parec -d steam.monitor | oggenc -b 192 -o steam.ogg –raw -

    Explanations:

    1. The first command will add a null-sink as you already knew.
    2. The second command moves the sink-input from your standard-audio-sink to steam
    3. The third command records the monitor of the device steam (-d) and puts the output (raw-wave-stream) into oggenc, which encodes this wave-stream to an oga-file. (for mp3 use lame)

    https://askubuntu.com/questions/60837/record-a-programs-output-with-pulseaudio

     ↩︎