This commit is contained in:
2025-09-09 10:40:19 +02:00
commit 90b6cb5506
3 changed files with 107 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/target
/sounds
/custom_sounds
Cargo.lock

9
Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "interruptsfx"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.47", features = ["derive"] }
rand = "0.9.2"
rodio = "0.21.1"

94
src/main.rs Normal file
View File

@@ -0,0 +1,94 @@
use clap::Parser;
use rodio::Decoder;
use std::{io::Cursor, path::Path, time::Duration};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short, long, default_value_t = false)]
dynamic_sounds: bool,
#[arg(long, default_value_t = 60 * 4)]
min_time_interval_seconds: u64,
#[arg(long, default_value_t = 60 * 15)]
max_time_interval_seconds: u64,
#[arg(long, default_value_t = String::from("./custom_sounds"))]
custom_sounds_directory: String,
}
fn main() {
let args = Args::parse();
play_audio(&args);
}
fn play_audio(args: &Args) {
use rand::prelude::*;
let mut rng = rand::rng();
let stream_handle =
rodio::OutputStreamBuilder::open_default_stream().expect("open default audio stream");
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
let mut data = vec![
Cursor::new(
include_bytes!("../sounds/35-roblox-death-sound-variations-in-60-seconds-pt.mp3")
.to_vec(),
),
Cursor::new(include_bytes!("../sounds/attack1.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/burn1.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/burn4.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/call_BsqlQcP.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/carry1.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/clock_Q4ZLaIZ.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/cry4.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/death2.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/drown1.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/electrocute.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/fall1.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/fall2.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/hm5.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/hm10.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/louie.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/moo2.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/mwah3.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/nectar.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/olimar.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pellet-posy.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin-anger.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin-boss-reveal.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin-death-sound-effect.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin-gcn.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin-tiktok-sound.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pikmin_hHLwh2y.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pluck6.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pluck7.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/pluck10.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/rock-pikmin-throw.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/sigh2.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/throw.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/wet_EI1zxTE.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/whistle_ERpCrMR.mp3").to_vec()),
Cursor::new(include_bytes!("../sounds/whistle_RjClohy.mp3").to_vec()),
];
if args.dynamic_sounds {
let path = Path::new(&args.custom_sounds_directory);
for item in path.read_dir().unwrap() {
let item = item.unwrap();
let file_type = item.file_type().unwrap();
if file_type.is_dir() {
continue;
}
let file_path = item.path();
data.push(Cursor::new(std::fs::read(file_path).unwrap()));
}
}
loop {
let i = rng.random_range(0..data.len());
let source = Decoder::try_from(data[i].clone()).unwrap();
sink.append(source);
sink.sleep_until_end();
std::thread::sleep(Duration::from_secs(rng.random_range(
args.min_time_interval_seconds..args.max_time_interval_seconds,
)));
}
}