diff --git a/src/main.rs b/src/main.rs index fd7dce7..22499ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,6 @@ use throbber_widgets_tui::{Throbber, ThrobberState}; use crossterm::{event::{self, EventStream, KeyCode, KeyModifiers}}; use tokio::{sync::{mpsc, watch}, time::Instant}; use tui_input::{Input, backend::crossterm::EventHandler}; -use std::process::Command ; use futures::{StreamExt, future::FutureExt}; // TODO: We should have a separate 'state.json' file, which remembers jack connections, and the world time for the show to end. Then we only update the 'time remaining' field in the scene and only deal with relative durations inside the scene data @@ -44,11 +43,12 @@ use futures::{StreamExt, future::FutureExt}; use ratatui::prelude::*; -use crate::{events::AudioRecordRequest, scene::{ConversationEntry, PlaylistEntry, Scene}}; +use crate::{events::AudioRecordRequest, scene::{ConversationEntry, PlaylistEntry, Scene}, tts::start_tts}; mod scene; mod events; mod transcription; +mod tts; #[derive(JsonSchema, Deserialize, Serialize, Debug, Clone)] struct PossibleResponse { @@ -534,8 +534,7 @@ async fn main() { let mut terminal: Terminal> = ratatui::init(); let (sys_message_sender, mut sys_message_receiver) = tokio::sync::mpsc::channel(5); - - let (tts_request_sender, mut tts_request_receiver) = tokio::sync::mpsc::channel(3); + let tts_request_sender = start_tts().await; let (prediction_in, mut prediction_out) = tokio::sync::watch::channel(None); let (prediction_request_in, mut prediction_request_out) = tokio::sync::watch::channel(Scene::default()); @@ -545,14 +544,6 @@ async fn main() { let mut app = App::new(prediction_request_in, audio_control_in, tts_request_sender); app.load(); - // Set up the TTS task - tokio::spawn(async move { - while let Some(text) = tts_request_receiver.recv().await { - // TODO: We should also have espeak pipe out to stdout, then we can apply some audio effects and write to our own jack port. - Command::new("espeak-ng").arg("-v").arg("en-us+f3").arg(text).spawn().unwrap().wait().unwrap(); - } - }); - tokio::spawn(async move { let client: Client = Client::default(); loop { diff --git a/src/tts.rs b/src/tts.rs new file mode 100644 index 0000000..f2c6a45 --- /dev/null +++ b/src/tts.rs @@ -0,0 +1,16 @@ +use std::process::Command; + +pub async fn start_tts() -> tokio::sync::mpsc::Sender { + + let (tts_request_sender, mut tts_request_receiver) = tokio::sync::mpsc::channel(3); + + // Set up the TTS task + tokio::spawn(async move { + while let Some(text) = tts_request_receiver.recv().await { + // TODO: We should also have espeak pipe out to stdout, then we can apply some audio effects and write to our own jack port. + Command::new("espeak-ng").arg("-v").arg("en-us+f3").arg(text).spawn().unwrap().wait().unwrap(); + } + }); + + tts_request_sender +} \ No newline at end of file