use rodio::Source;
use std::sync::{Mutex, atomic::AtomicBool};
use tokio::sync::mpsc::Receiver;
pub struct TTSQueueInput<T>
where
T: Source + Send + Clone,
{
pub sounds: Mutex<Vec<(T, super::Signal)>>,
pub is_finished: AtomicBool,
}
impl<T> TTSQueueInput<T>
where
T: Source + Send + Clone,
{
pub fn append(&self, source: T) {
self.sounds.lock().unwrap().push((source, None));
}
pub fn append_with_signal(&self, source: T) -> Receiver<bool> {
let (tx, rx) = tokio::sync::mpsc::channel(1);
self.sounds.lock().unwrap().push((source, Some(tx)));
rx
}
pub fn set_is_finished(&self, is_finished: bool) {
self.is_finished
.store(is_finished, std::sync::atomic::Ordering::Release);
}
pub fn is_finished(&self) -> bool {
self.is_finished.load(std::sync::atomic::Ordering::Acquire)
}
}