Stereo Tool
https://forums.stereotool.com/

integrating stereotool with liquidsoap: it works, but metadata is lost
https://forums.stereotool.com/viewtopic.php?f=4&t=13224
Page 1 of 1

Author:  drein [ Thu Jan 05, 2017 10:48 am ]
Post subject:  integrating stereotool with liquidsoap: it works, but metadata is lost

Hello,
I decided to put down some lines to demonstrate how to use Liquidsoap in conjunction with Stereotool.
This is a sort of collection of info found on the internet and some personal test.
All work thanks to the great work of my friend vincenzo Rubano that solved the metadata issue.
I hope people can find this post useful.


The concept is quite simple:
Liquidsoap make all jobs about scheduling, containing playlist, stream etc. Stereotool process the sound.
I have a webradio on a vps, using Debian Jessie and icecast as stream server.

Use stereo_tool command line version.

You should download a setting preset from the stereotool forum section. It's really easy and there is a good choice.

Then create 2 files:

mkfifo /tmp/audioin.pcm
mkfifo /tmp/audioout.pcm

These are the files that must be read and write by liquidsoap and stereotool.
Liquidsoap generates the pcm audioin.pcm, stereotool reads it, processes, and write audioout.pcm; liquidsoap takes audioout.pcm and stream to icecast.

The stereotool side is really easy, you can give a simple:
./stereo_tool_cmd_64_xxx /tmp/audioin.pcm /tmp/audioout.pcm -s ./mySettings.sts &

where xxx is the version of stereotool.

The liquidsoap section instead:


I have a "radio" object that contain all playlists and scheduling options. So we must generate a wav file that will be read by stereotool, and then take the output file and stream by icecast.
Since manage metadata with liquidsoap seems quite tricky, we decide to pass all to icecast. So, first of all, we must define a function for metadata. Put it before you define your playlist.

The piece of code is follow:

#helper function to format metadata
#todo: evaluate using rewrite_metadata for a more elegant solution
def format_metadata(data)
artist = data["artist"]
title = data["title"]
if title != "" then
if artist != "" then
"#{artist} - #{title} - NV-Radio"
else
"#{title} - NV-Radio"
end
else
"NV-Radio"
end
end

#when using stereotool we loose metadata, so we send them to Icecast manually
def apply_metadata(data)
icy_data = [("song", format_metadata(data))]
icy.update_metadata(mount="/stream",
password = "cipcipcipcipcipcip!",
icy_data)
end

Then, before you send the streaming to icecast, metadata should be handled, so add this for completing the radio object:

#metadata handling
radio = on_metadata(apply_metadata, radio)

output.file(%wav(stereo=true, channels=2, samplesize=16, header=true, duration=1.),
"/home/radio/audioin.pcm",
radio
)

# put all stream processed by stereotool in the s object using the dd command
s = mksafe(input.external("dd if=/home/radio/audioout.pcm 2>/dev/null"))
s = rewrite_metadata([("title", "$(title) - NvRadio")], s)

#enable icecast streaming passing the S object and metadata, converting all strings to iso-8559-1 for avoiding problems with certain song title, I'm not sure you need this conversion on your station so make some try.

output.icecast(%mp3(
samplerate=44100,
stereo=true,
bitrate=128),
mount="/stream",
name="your Radio",
host="127.0.0.1",
port=8000,
password="ciopciopciopciopciopciopciop!",
genre="70's, 80's, 90's, easy listening, oldies, top 40/pop",
url="http://www.yourwebradio.com/",
icy_metadata="true",
encoding="ISO-8859-1",
description = "radio a tema accessibilità !!",
public=true,s)


Remember, start liquidsoap before, you will hear a silent streaming, then start stereo_tool and the magic sound will appear.

I think it is useful to check with monit or similar the stereo_tool process, because if it dies for some reason, you lost the streaming.
So at least it is a good idea to implement a script that notify you by email, put down liquidsoap and start the emergency streaming of icecast.

On some circumstance you should kill also the "dd" process, but in my server it was not necessary.
So if you make:
killall -9 radio.liq

You kill liquidsoap and stereotool goes down automatically because it doesn't find data on audioin.pcm.

Author:  hvz [ Fri Jan 06, 2017 8:11 pm ]
Post subject:  Re: integrating stereotool with liquidsoap: it works, but metadata is lost

The Stereo Tool command line version doesn't contain a full wav file parser, so it's very likely that that's what's causing the loss of info. For now, If possible somehow fetch the data from the input file.

Author:  gef [ Wed Mar 08, 2017 7:21 pm ]
Post subject:  Re: integrating stereotool with liquidsoap: it works, but metadata is lost

Hey Drein,

All makes sense, I will try this soon! I basically want to generate a MPX stream (lossless flac via icecast)... One bit I'm not sure on...
Quote:
I have a "radio" object that contain all playlists and scheduling options. So we must generate a wav file that will be read by stereotool, and then take the output file and stream by icecast. The piece of code is follow:

output.file(%wav(stereo=true, channels=2, samplesize=16, header=true, duration=1.),
"/tmp/audioin.pcm",
radio
)
I've seen your posts on airtime forum, do you know what the airtime object would be called? I can't see any mention of 'radio' in ls_script.liq

Author:  Pascal Kusters [ Sat Jul 18, 2020 4:48 pm ]
Post subject:  Re: integrating stereotool with liquidsoap: it works, but metadata is lost

Is there somebody who can help me to fix Stereotool in Azuracast with liquidsoap?

Author:  sverrips [ Mon Jul 27, 2020 12:54 am ]
Post subject:  Re: integrating stereotool with liquidsoap: it works, but metadata is lost

Another script that's work. I have it running on my delicated linux server.

#!/usr/bin/liquidsoap
set("log.file.path","/tmp/stream.log")
set("frame.size",940)

# Input to Processing
input = input.pulseaudio(clock_safe=false)

# Processing
radio = pipe(process='/usr/bin/stereo_tool_cmd_64 - - -s /opt/optimod8100.sts -q -k "<3f1c........................................9ee>"', input)

# Processing to Output
output.icecast(
%mp3(bitrate = 192),
host = "server.nl",
user = "source",
port = 6830,
password = "************",
mount = "/",
genre = "Prog",
name = "Progressieve Rock",
url = "https://progressieverock.nl",
description = "Progressieve Rock",
mksafe(radio)
)

Pascal, many thanks !

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/