Skip to content

Commit

Permalink
replace darkice with pulseaudio, remove fade and mixer, update rust a…
Browse files Browse the repository at this point in the history
…nd ubuntu docker versions
  • Loading branch information
waveplate committed Sep 23, 2023
1 parent 1d818d8 commit 0c16a20
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 121 deletions.
32 changes: 1 addition & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,36 +212,6 @@ all above return (example):
}
```

### `GET /mixer/music/fade?start=<START>&end=<END>&duration=<DURATION>`
`START` is the volume percentage to start the fade at, e.g. `100`

`END` is the volume percentage to end the fade at, e.g. `50`

`DURATION` is the duration, in milliseconds, over which to conduct the fade, e.g. `3000`

it returns:
```
{
"done": true
}
```

### `GET /mixer/announce/volume?vol=<VOLUME>`
`VOLUME` is the volume to set the announcements to, examples of acceptable values are

`120%` - will set the volume to 120%

`+10%` - this will increase the volume by 10%

`140` - this will set the volume to 140dB

it returns:
```
{
"volume": <VOLUME>
}
```

### `GET /espeak?text=<TEXT>`
### `GET /elevenlabs?text=<TEXT>`
this will use espeak, or the elevenlabs API to speak your `TEXT`
Expand All @@ -251,4 +221,4 @@ it will return:
{
"text": <TEXT>
}
```
```
14 changes: 10 additions & 4 deletions docker/ircbot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ var radioBase = 'http://icecast2:8000';
let configData = fs.readFileSync('/etc/ircbot.json');
let config = JSON.parse(configData);


bot.connect({
host: config.server,
port: config.port,
nick: config.nick
nick: config.nick,
ssl: config.port == 6697 ? true : false,
rejectUnauthorized: false
});

bot.on('registered', function() {
Expand All @@ -22,6 +23,10 @@ bot.on('registered', function() {
});
});

bot.on('debug', function(event) {
console.log(event);
});

bot.on('message', function(event) {
var args = event.message.split(' ');
var text = args.slice(1).join(' ');
Expand All @@ -35,13 +40,12 @@ bot.on('message', function(event) {
});
}

if (event.message.match(/^!skip/)) {
if (event.message.match(/^!skip/)) {
spotifyApi('/skip', event, data => {
return _nowPlaying(data, event);
});
}


if (event.message.match(/^!np/)) {
return _nowPlaying(false, event);
}
Expand Down Expand Up @@ -82,6 +86,8 @@ function _nowPlaying(data, event){
if(data)
return event.reply(makeSpotifyMessage(data, listeners));
spotifyApi("/np", event, data => {
console.log("sending reply with");
console.log(data);
event.reply(makeSpotifyMessage(data, listeners));
});
});
Expand Down
2 changes: 1 addition & 1 deletion docker/streamer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

RUN apt-get update && apt-get -y install pulseaudio alsa-utils liquidsoap curl sox espeak

Expand Down
11 changes: 1 addition & 10 deletions docker/streamer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ echo "Starting pulseaudio ..."
pulseaudio -D --exit-idle-time=-1
sleep 2

pactl load-module module-null-sink sink_name=spotifm_music sink_properties=device.description=spotifm_music
pactl load-module module-null-sink sink_name=spotifm_announce sink_properties=device.description=spotifm_announce
pactl load-module module-null-sink sink_name=spotifm_master sink_properties=device.description=spotifm_master
sleep 1
pactl load-module module-loopback source=spotifm_music.monitor sink=spotifm_master
pactl load-module module-loopback source=spotifm_announce.monitor sink=spotifm_master

pactl set-default-source spotifm_master.monitor

echo "Starting liquidsoap ..."
liquidsoap /etc/liquidsoap/pulse.liq --daemon
sleep 2
Expand All @@ -23,5 +14,5 @@ echo "Starting keepalive ..."
/keepalive.sh &

echo "Starting spotifm ..."
PULSE_SINK=spotifm_music spotifm /etc/spotifm.json

spotifm /etc/spotifm.json
2 changes: 1 addition & 1 deletion docker/streamer/keepalive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# if more than 5 seconds of silence, send SIGALRM to spotifm so it renews the session
while true; do
PULSE_SOURCE=spotifm_music.monitor sox -d -n silence 1 1 0% 1 15.0 0%
PULSE_SOURCE=auto_null.monitor sox -d -n silence 1 1 0% 1 15.0 0%
pkill -SIGALRM spotifm
touch /tmp/silence_$(date +%s)
sleep 5
Expand Down
2 changes: 1 addition & 1 deletion etc/pulse.liq
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Define the PulseAudio input
input = input.pulseaudio(
device="spotifm_master.monitor"
device="auto_null.monitor"
)

# Define the Icecast2 output
Expand Down
6 changes: 2 additions & 4 deletions src/announce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::process::{Command};
use std::process::Command;
use std::sync::{Arc, Mutex};
use crate::db::{SpotifyTrack};
use crate::db::SpotifyTrack;
use crate::config::{SpotifmConfig, SpotifmEspeakCfg, SpotifmElevenLabsCfg};

pub fn announcements(_config: Arc<Mutex<SpotifmConfig>>, track: &SpotifyTrack, tracks_played: usize) {
Expand All @@ -24,7 +24,6 @@ pub fn announcements(_config: Arc<Mutex<SpotifmConfig>>, track: &SpotifyTrack, t

pub fn espeak(text: String, config: SpotifmEspeakCfg){
Command::new("espeak")
.env("PULSE_SINK", "spotifm_announce")
.arg("-s")
.arg(config.speed.to_string())
.arg("-a")
Expand All @@ -51,7 +50,6 @@ pub fn get_elevenlabs_tts(text: &str, config: SpotifmElevenLabsCfg) {

pub fn play_elevenlabs(){
Command::new("mplayer")
.env("PULSE_SINK", "spotifm_announce")
.arg("/tmp/output.mp3")
.output()
.unwrap();
Expand Down
14 changes: 5 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use librespot::playback::audio_backend;
use librespot::playback::config::{AudioFormat, PlayerConfig};
use librespot::playback::mixer::{NoOpVolume};
use librespot::playback::mixer::NoOpVolume;
use librespot::playback::player::{Player,PlayerEvent};

mod db;
mod rest;
mod signals;
mod config;
mod announce;
mod mixer;

use config::SpotifmConfig;

Expand All @@ -28,7 +27,6 @@ async fn main() {

let mut tracks_played = 0;

// get the first argument
let args: Vec<String> = std::env::args().collect();

let db = db::SpotifyDatabase::new();
Expand All @@ -42,19 +40,17 @@ async fn main() {
rest::start(rest_tx.clone(), config.clone(), session.clone(), db.clone());
db::populate(config.lock().unwrap().uris.clone(), session.clone(), db.clone());

eprintln!("waiting for playlist...");
eprintln!("Waiting for playlist...");

// wait until at least one track in playlist
while db.len() == 0 {
thread::sleep(time::Duration::from_millis(10));
}

eprintln!("playlist ready, starting playback...");
eprintln!("Playlist partially loaded, starting playback...");

'track_list: loop {

tracks_played += 1;

db.advance_track();

match db.current_track() {
Expand All @@ -73,7 +69,7 @@ async fn main() {
player.load(track.spotify_id(), true, 0);

match db.next_track() {
Err(err) => eprintln!("preload error: {}", err),
Err(err) => eprintln!("Preload error: {}", err),
Ok(track) => player.preload(track.spotify_id()),
}

Expand Down Expand Up @@ -133,7 +129,7 @@ pub async fn create_session(config: &Arc<Mutex<SpotifmConfig>>) -> Session {
let credentials = Credentials::with_password(config.user.clone(), config.pass.clone());

let (session, _) = Session::connect(session_config, credentials, None, false).await
.map_err(|err| { panic!("{}", err.to_string())} )
.map_err(|err| { eprintln!("Error creating session: {}", err.to_string())} )
.unwrap();

return session;
Expand Down
33 changes: 0 additions & 33 deletions src/mixer.rs

This file was deleted.

30 changes: 3 additions & 27 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ use std::iter::FromIterator;
use std::{sync::mpsc::SyncSender, thread};

use crate::db::{SpotifyDatabase, SpotifyTrack};
use crate::config::{SpotifmConfig};
use crate::config::SpotifmConfig;
use crate::announce::{espeak, get_elevenlabs_tts, play_elevenlabs};
use crate::mixer::{volume_fade, announce_volume};

const CLIENT_ID: &str = "65b708073fc0480ea92a077233ca87bd";
const SCOPES: &str =
Expand Down Expand Up @@ -50,27 +49,6 @@ pub struct AnnounceSong {
pub gap: Option<u32>,
}

#[get("/mixer/music/fade")]
pub async fn set_mixer_music_fade(
req: HttpRequest
) -> HttpResponse {
let query = web::Query::<HashMap<String, String>>::from_query(req.query_string()).unwrap();
let start = query.get("start").unwrap().parse::<u32>().unwrap();
let end = query.get("end").unwrap().parse::<u32>().unwrap();
let duration = query.get("duration").unwrap().parse::<u64>().unwrap();
volume_fade(start, end, duration);
return HttpResponse::Ok().json(HashMap::from([("done", true)]));
}

#[get("/mixer/announce/volume")]
pub async fn set_mixer_announce_volume(
req: HttpRequest
) -> HttpResponse {
let query = web::Query::<HashMap<String, String>>::from_query(req.query_string()).unwrap();
announce_volume(query.get("vol").unwrap().clone());
return HttpResponse::Ok().json(HashMap::from([("volume", query.get("vol").unwrap())]));
}

#[get("/elevenlabs")]
pub async fn do_elevenlabs_say(
req: HttpRequest,
Expand All @@ -87,7 +65,7 @@ pub async fn do_elevenlabs_say(
}

#[get("/espeak")]
pub async fn do_announce_say(
pub async fn do_espeak_say(
req: HttpRequest,
config: Data<Arc<Mutex<SpotifmConfig>>>,
) -> HttpResponse {
Expand Down Expand Up @@ -457,10 +435,8 @@ pub async fn start(tx: SyncSender<PlayerEvent>, config: Arc<Mutex<SpotifmConfig>
.service(search)
.service(show_playlist)
.service(shuffle)
.service(set_mixer_music_fade)
.service(set_mixer_announce_volume)
.service(get_announce)
.service(do_announce_say)
.service(do_espeak_say)
.service(do_elevenlabs_say)
.service(edit_announce_song)
.service(edit_announce_bumper)
Expand Down

0 comments on commit 0c16a20

Please sign in to comment.