Last active
December 22, 2022 15:00
-
-
Save madskjeldgaard/dabe89a2564c2b02c83375ba2fdc891e to your computer and use it in GitHub Desktop.
Simple buffer playback in Rust using the rodio crate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rodio::Sink; | |
use std::fs::File; | |
use std::io::BufReader; | |
fn main() { | |
// Sound output | |
let device = rodio::default_output_device().unwrap(); | |
let sink = Sink::new(&device); | |
// Buffer playback | |
let file_path: String = "/home/mads/testsound/plastic1.wav".to_string(); | |
let file = File::open(file_path).unwrap(); | |
let source = rodio::Decoder::new(BufReader::new(file)).unwrap(); | |
// Add sound to the sink | |
sink.append(source); | |
// Volume | |
sink.set_volume(0.25); | |
// Keep the sink alive until sound stops playing | |
sink.sleep_until_end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment