mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 00:55:14 -07:00
The cpal Stream was created and play() called but then immediately dropped when play_to_device() returned. When a cpal Stream is dropped, audio output stops immediately. This caused silent playback. Fix: add a spin-wait loop that holds the Stream in scope until all samples have been consumed (or stop_flag is set).
This commit is contained in:
@@ -404,6 +404,22 @@ impl AudioOutputState {
|
|||||||
|
|
||||||
eprintln!("play_to_device: Stream started successfully");
|
eprintln!("play_to_device: Stream started successfully");
|
||||||
|
|
||||||
|
// Keep the stream alive until playback finishes.
|
||||||
|
// Previously the stream was dropped immediately on function return,
|
||||||
|
// causing silent playback (cpal stops output when its Stream is dropped).
|
||||||
|
let total_samples = {
|
||||||
|
buffer.lock().unwrap().len()
|
||||||
|
};
|
||||||
|
loop {
|
||||||
|
let pos = position.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
|
if pos >= total_samples || stop_flag.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
// stream is dropped here, after audio has finished playing
|
||||||
|
drop(stream);
|
||||||
eprintln!("play_to_device: Function completed successfully");
|
eprintln!("play_to_device: Function completed successfully");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user