audio2pipe is a set of utilities to pipe sound towards other software
audio2pipe is a set of scripts and services to better handle pipe creation for audio streamers leveraging cpiped under the hood. Recommended in conjunction with OwnTone
- systemd service to manage cpiped instances supporting different sample rates
- Multiple input device supported with dedicated configuration
- Interlock to avoid out of sequence triggering of per device script
- Automatic OwnTone output selection on sound detection
audio2pipe requires
-
Clone the repository
git clone https://github.com/ale275/audio2pipe.git
-
Install scripts in audio2pipe base dir defined by A2P_HOME env variable and setup needed symlink
cd audio2pipe export A2P_HOME=/home/user install -m 755 -D scripts/* -t "${A2P_HOME}/bin" ln -s "${A2P_HOME}/bin/A2PSourceProcess.sh" "${A2P_HOME}/bin/A2PSourceProcessPre" ln -s "${A2P_HOME}/bin/A2PSourceProcess.sh" "${A2P_HOME}/bin/A2PSourceProcessDetect" ln -s "${A2P_HOME}/bin/A2PSourceProcess.sh" "${A2P_HOME}/bin/A2PSourceProcessSilence" ln -s "${A2P_HOME}/bin/A2PSourceProcess.sh" "${A2P_HOME}/bin/A2PSourceProcessStop" ln -s "${A2P_HOME}/bin/A2PToggle.sh" "${A2P_HOME}/bin/A2PToggle"
To configure autmatic output selection on sound detect please refer to scripts/A2POutputselector.py section.
-
Create per device systemd service file starting from template. More details in configuration section
export A2P_HOME=/home/user export A2P_DEVNAME=Test_Device cp "service/cpiped_Template.service" "service/cpiped_${A2P_DEVNAME}.service" nano "service/cpiped_${A2P_DEVNAME}.service"
-
Install and activate the service
export A2P_HOME=/home/user export A2P_DEVNAME=Test_Device sudo cp "service/cpiped_${A2P_DEVNAME}.service" "/lib/systemd/system/" sudo systemctl daemon-reload sudo systemctl enable cpiped_${A2P_DEVNAME}.service sudo systemctl start cpiped_${A2P_DEVNAME}
audio2pipe scripts functionality description
Main bash script taking various ENV variable as configuration to make, monitor and clean-up audio pipes, pid monitoring and output selection via callback function.
Script has three execution phases from now on <A2P_ExecPhase>
- Pre: running all the preparatory check before
cpipedis started. Executed only once at service start - Detect: Section run at sound detect. It runs python output selector callback script. Script can be replaced at user discretion by replacing the symlinked script
- Silence: Performs all the files clean-up when audio source is stopped
Lockfile and pipe filling PID checks prevent parallel command execution and multiple pipe fillings resulting in unpleasant white noise blasting from speakers. These features are especially useful when audio is sourced from record players.
On sound detect a python callback script is used, in the repository an OwnTone output selection script is provided.
Python script using OwnTone http API(s) to select the output(s) defined in ENV variable at sound detect phase. It's usage is not mandatory
To be invoked script must be located in <A2P_HOME>/bin and named A2P_OT_OUT_SEL_<A2P_DEVNAME>
export A2P_HOME=/home/user
export A2P_DEVNAME=Test_Device
ln -s "${A2P_HOME}/bin/A2POutputSelector.py" "${A2P_HOME}/bin/A2P_OT_OUT_SEL_${A2P_DEVNAME}"Script to toggle the various cpiped services. Must be run as sudo
Systemd service
Script configuration are mainly managed though ENV variables
| Variable name |
Description | Type | Default | Range/Format | Required? |
|---|---|---|---|---|---|
A2P_HOME |
audio2pipe basedir Folder structure:
|
string |
$HOME |
No | |
A2P_DEVNAME |
Device input name Mnemonic that will define all the specialized file name
|
string |
Yes | ||
A2P_CP_SF |
Audio device sample rate to be passed to cpiped in hzcpiped will then set env variables CPIPED_SR, CPIPED_SS, CPIPED_CC, respectively for sample rate, sample size and capture channel directly
|
integer |
44100 |
16000 - 192000 |
No |
A2P_CP_SOUNDCARD |
Audio capture soundcard to be passed to cpiped in ALSA format |
string |
'default' |
hw:<card>,<device> |
No |
A2P_CP_SL |
cpiped silence level |
integer |
100 |
1 - 32767 |
No |
A2P_OT_LIB |
OwnTone library folder. Where the audio pipe will be created and filled on sound detection | string |
No | ||
A2P_OT_HOST |
OwnTone server hostname | string |
localhost |
No | |
A2P_OT_OUT_LIST |
OwnTone output(s) label to be selected at sound detect | stringcomma separated list |
No | ||
A2P_DEBUG |
Make log more verbose. Accepts True or False values | string |
False |
True - False |
No |
Usage of following variable is not recommended
| Variable name |
Description | Type | Default | Range/Format | Required? |
|---|---|---|---|---|---|
A2P_DEVFORMAT |
Concatenation of sample format and sample frequency separated by two underscores Example: sample format 16bit Little Endian and sample frequency 48kHz will be S16_LE__48000 Default sample rate 41000Hz Default sample size 16bit Default capture channel 2 **Preferred** approach is to read cpiped env variables CPIPED_SR, CPIPED_SS, CPIPED_CC, respectively for sample rate, sample size and capture channel directly
|
string |
<Sample format>__<Sample rate> |
Not recomended |
- Sysvinit scripts
- Move ENV variable setup from Service file to EnvironFile to define monitoring pipe in pre stage. Under evaluation
- Rework detect pipe section that is prone to config error
- Create install script
- Add command line parameters to scripts/A2POutputselector.py
- Add command line parameters to scripts/A2PToggle.sh
- Change detect pipe extension from .pipe to .detectpipe
- Add cpiped existence check in <A2P_ExecPhase>==Pre
- Improve systemd service ExecStop section of script to stop the device specific instance of cpiped and not all of them
- Fix systemd service KillMode warning
See the open issues for a full list of proposed features (and known issues).
Based on Making an Analog In to Airplay RPi-Transmitter from ownTone wiki
Created to be used with OwnTone