code: README, .env support

This commit is contained in:
Gabor Körber 2024-01-20 22:54:48 +01:00
parent 7277ca0cfa
commit 478bdbc59a
5 changed files with 47 additions and 7 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
DIRECTORY="E:/sounds/soundboard/all"
DEVICE_PATTERN=".*VB-Audio Virtual Cable.*"

7
Cargo.lock generated
View File

@ -317,6 +317,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.32" version = "0.8.32"
@ -1151,6 +1157,7 @@ dependencies = [
"axum", "axum",
"axum-template", "axum-template",
"cpal", "cpal",
"dotenvy",
"log", "log",
"minijinja", "minijinja",
"minimp3", "minimp3",

View File

@ -10,6 +10,7 @@ default-run = "soundboard"
axum = "0.6.18" axum = "0.6.18"
axum-template = { version = "0.19.0", features = ["minijinja"] } axum-template = { version = "0.19.0", features = ["minijinja"] }
cpal = "0.15.2" cpal = "0.15.2"
dotenvy = "0.15.7"
log = "0.4.20" log = "0.4.20"
minijinja = { version = "1.0.3", features = ["loader"] } minijinja = { version = "1.0.3", features = ["loader"] }
minimp3 = "0.5.1" minimp3 = "0.5.1"

26
README.md Normal file
View File

@ -0,0 +1,26 @@
# Soundboard
The idea is to run a web server that serves a sound board app to your devices, so you can play sounds on your computer from a second device.
## Features
- [x] play mp3
- [x] play ogg
- [x] play wav
- [x] play flac
- [x] read mp3 duration
- [ ] read ogg duration
- [ ] read wav duration
- [x] block buttons
- [x] fullscreen
- [x] portrait/landscape
- [ ] static css
- [ ] categories
- [ ] set folders per env
- [ ] set output device per env
- [ ] endpoint for setting devices
- [ ] endpoint for setting folders
- [ ] auth
- [ ] multi-device support
- [ ] press button while playing

View File

@ -5,10 +5,12 @@ use minijinja::{path_loader, Environment};
use state::{AppState, TemplateEngine}; use state::{AppState, TemplateEngine};
use std::net::SocketAddr; use std::net::SocketAddr;
use log::{debug, info}; use log::info;
use serde::Serialize; use serde::Serialize;
use std::env;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use dotenvy::dotenv;
use vbplay::{AudioThread, DeviceSelection, SoundDecoder}; use vbplay::{AudioThread, DeviceSelection, SoundDecoder};
mod soundclips; mod soundclips;
@ -17,22 +19,24 @@ mod vbplay;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
dotenv().ok();
let device_pattern = env::var("DEVICE_PATTERN").expect("Need a device pattern");
let folder = env::var("DIRECTORY").expect("Need a directory in env file.");
let mut jinja = Environment::new(); let mut jinja = Environment::new();
jinja.set_loader(path_loader("templates")); jinja.set_loader(path_loader("templates"));
let template_engine = Engine::from(jinja); let template_engine = Engine::from(jinja);
let audio = vbplay::audio_thread( let audio = vbplay::audio_thread(
DeviceSelection::FindByPattern(".*VB-Audio Virtual Cable.*".to_owned()), DeviceSelection::FindByPattern(device_pattern),
SoundDecoder::Detect, SoundDecoder::Detect,
); );
let audio: Arc<Mutex<AudioThread>> = Arc::new(Mutex::new(audio)); let audio: Arc<Mutex<AudioThread>> = Arc::new(Mutex::new(audio));
let app_state = AppState { let app_state = AppState {
engine: template_engine, engine: template_engine,
clips: soundclips::scan_directory_for_clips( clips: soundclips::scan_directory_for_clips(&folder, &["mp3", "ogg", "wav", "flac"])
"E:/sounds/soundboard/all",
&["mp3", "ogg", "wav", "flac"],
)
.expect("No Soundclips found."), .expect("No Soundclips found."),
player: audio, player: audio,
playback: None, playback: None,