tts: start splitting out tts into its own module, to grow later with more features

This commit is contained in:
2026-06-03 19:21:00 +02:00
parent f1e6684d9c
commit 1e50c7222f
2 changed files with 19 additions and 12 deletions
+3 -12
View File
@@ -11,7 +11,6 @@ use throbber_widgets_tui::{Throbber, ThrobberState};
use crossterm::{event::{self, EventStream, KeyCode, KeyModifiers}}; use crossterm::{event::{self, EventStream, KeyCode, KeyModifiers}};
use tokio::{sync::{mpsc, watch}, time::Instant}; use tokio::{sync::{mpsc, watch}, time::Instant};
use tui_input::{Input, backend::crossterm::EventHandler}; use tui_input::{Input, backend::crossterm::EventHandler};
use std::process::Command ;
use futures::{StreamExt, future::FutureExt}; 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 // 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 ratatui::prelude::*;
use crate::{events::AudioRecordRequest, scene::{ConversationEntry, PlaylistEntry, Scene}}; use crate::{events::AudioRecordRequest, scene::{ConversationEntry, PlaylistEntry, Scene}, tts::start_tts};
mod scene; mod scene;
mod events; mod events;
mod transcription; mod transcription;
mod tts;
#[derive(JsonSchema, Deserialize, Serialize, Debug, Clone)] #[derive(JsonSchema, Deserialize, Serialize, Debug, Clone)]
struct PossibleResponse { struct PossibleResponse {
@@ -534,8 +534,7 @@ async fn main() {
let mut terminal: Terminal<CrosstermBackend<std::io::Stdout>> = ratatui::init(); let mut terminal: Terminal<CrosstermBackend<std::io::Stdout>> = ratatui::init();
let (sys_message_sender, mut sys_message_receiver) = tokio::sync::mpsc::channel(5); let (sys_message_sender, mut sys_message_receiver) = tokio::sync::mpsc::channel(5);
let tts_request_sender = start_tts().await;
let (tts_request_sender, mut tts_request_receiver) = tokio::sync::mpsc::channel(3);
let (prediction_in, mut prediction_out) = tokio::sync::watch::channel(None); 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()); 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); let mut app = App::new(prediction_request_in, audio_control_in, tts_request_sender);
app.load(); 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 { tokio::spawn(async move {
let client: Client<OpenAIConfig> = Client::default(); let client: Client<OpenAIConfig> = Client::default();
loop { loop {
+16
View File
@@ -0,0 +1,16 @@
use std::process::Command;
pub async fn start_tts() -> tokio::sync::mpsc::Sender<String> {
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
}