rodio icon indicating copy to clipboard operation
rodio copied to clipboard

Play sound on system output device, even if the system output device changes

Open sloganking opened this issue 11 months ago • 0 comments

I want sound to play on whatever the operating system's default audio output device is, and switch to the new default audio device if the system changes which one is default. Below is an image showing where the default audio device is chosen on Windows 10.

image

let (_stream, stream_handle) = rodio::OutputStream::try_default().unwrap();
let sink = rodio::Sink::try_new(&stream_handle).unwrap();

Currently sounds played on the above sink via

let file = std::fs::File::open(ai_speech_segment.path()).unwrap();
sink.stop();
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap());
//sink.play()
sink.sleep_until_end();

Don't ever switch which audio device they are outputting sound to if the operating system's default audio device changes. This behavior is different than all other applications on my device that I know of.

I could re-create a sink every time I want to play a sound. but that's annoying and doesn't change audio devices until the current sound ends and the next one is played. Is there a better solution, or can we make one?

===

edit: as a side note. I am not sure why sounds play when you append them and you don't need to do sink.play(). Let me know if that is expected behavior!

sloganking avatar Feb 25 '24 06:02 sloganking