feat: ✨ unidirectional voice transmission
This commit is contained in:
parent
88c1b2517c
commit
8de799f5be
6 changed files with 660 additions and 49 deletions
|
@ -1,9 +1,15 @@
|
|||
use std::{net::SocketAddr, path::Path};
|
||||
|
||||
use s2n_quic::{Client, client::Connect};
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::{
|
||||
io::AsyncWriteExt,
|
||||
sync::{broadcast, oneshot},
|
||||
};
|
||||
|
||||
use crate::ClientConfig;
|
||||
use crate::{
|
||||
BUFFER_LENGTH, ClientConfig,
|
||||
voice::{play, record},
|
||||
};
|
||||
|
||||
pub async fn run<'a>(client_config: ClientConfig<'a>) {
|
||||
let client = Client::builder()
|
||||
|
@ -26,14 +32,20 @@ pub async fn run<'a>(client_config: ClientConfig<'a>) {
|
|||
};
|
||||
connection.keep_alive(true).unwrap();
|
||||
|
||||
let (microphone_sender, mut microphone_receiver) = broadcast::channel::<f32>(BUFFER_LENGTH);
|
||||
let (stop_signal_sender, stop_signal_receiver) = oneshot::channel::<bool>();
|
||||
|
||||
let stream = connection.open_bidirectional_stream().await.unwrap();
|
||||
let (mut receive_stream, mut send_stream) = stream.split();
|
||||
send_stream
|
||||
.send("Hi from Tahinli".as_bytes().into())
|
||||
.await
|
||||
.unwrap();
|
||||
let received = receive_stream.receive().await.unwrap().unwrap();
|
||||
println!("{}", String::from_utf8(received.to_vec()).unwrap());
|
||||
|
||||
tokio::spawn(record(microphone_sender, stop_signal_receiver));
|
||||
|
||||
let (receive_stream, mut send_stream) = stream.split();
|
||||
while let Ok(sample) = microphone_receiver.recv().await {
|
||||
send_stream
|
||||
.send(sample.to_le_bytes().to_vec().into())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if let Err(err_val) = send_stream.close().await {
|
||||
eprintln!("Error: Stream Close | {}", err_val);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue