mirror of
https://github.com/storytold/realtime-voice-conversion.git
synced 2026-10-17 00:23:13 +00:00
realtime-voice-conversion based on last year's work
This is based on the work I did in (July - October)ish 2019 to get real time voice conversion working. I've removed it from the `voder` library and made it into an isolable program. I'll work on extending the capabilities.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
use zmq;
|
||||
use zmq::{Error, Socket};
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{RwLock, PoisonError};
|
||||
|
||||
pub struct AudioQueue {
|
||||
queue: RwLock<VecDeque<f32>>,
|
||||
}
|
||||
|
||||
impl AudioQueue {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
queue: RwLock::new(VecDeque::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_back(&self, val: f32) {
|
||||
match self.queue.write() {
|
||||
Ok(mut queue) => {
|
||||
queue.push_back(val);
|
||||
},
|
||||
Err(_) => {
|
||||
unreachable!("This shouldn't happen (push_back)");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extend(&self, buf: Vec<f32>) {
|
||||
match self.queue.write() {
|
||||
Ok(mut queue) => {
|
||||
queue.extend(buf);
|
||||
},
|
||||
Err(_) => {
|
||||
unreachable!("This shouldn't happen (extend)");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drain(&self) -> Vec<f32> {
|
||||
match self.queue.write() {
|
||||
Ok(mut queue) => {
|
||||
return queue.drain(..)
|
||||
.collect::<Vec<_>>();
|
||||
},
|
||||
Err(_) => {
|
||||
unreachable!("This shouldn't happen (drain)");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drain_size(&self, size: usize) -> Option<Vec<f32>> {
|
||||
match self.queue.write() {
|
||||
Ok(mut queue) => {
|
||||
if queue.len() < size {
|
||||
return None;
|
||||
}
|
||||
let vec = queue.drain(0..size)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
return Some(vec);
|
||||
},
|
||||
Err(_) => {
|
||||
unreachable!("This shouldn't happen (drain_size)");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
match self.queue.read() {
|
||||
Ok(mut queue) => {
|
||||
return queue.len();
|
||||
},
|
||||
Err(_) => {
|
||||
unreachable!("This shouldn't happen (len)");
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user