From 8e868894cbcaf421c263f3555af4d29bef653420 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 5 Sep 2026 19:35:21 +0200 Subject: feat: piper now not a subprocess, cache system for TTS --- src/commands/ai.rs | 5 ++--- src/commands/tts.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/commands') diff --git a/src/commands/ai.rs b/src/commands/ai.rs index 61fb471..5dd98cb 100644 --- a/src/commands/ai.rs +++ b/src/commands/ai.rs @@ -30,15 +30,14 @@ pub async fn senator( }) .ok_or_else(lang::err_not_in_voice)?; - let (audio_data, _) = - crate::tts::synthesize(&ctx.data().config, &ctx.data().http_client, &response).await?; + let audio_data = ctx.data().tts.synthesize(&response).await?; let call = ctx .data() .voice_manager .connect(guild_id, channel_id) .await?; - let input = crate::voice::decode_audio(&audio_data)?; + let input = crate::tts::pcm_bytes_to_input(audio_data); let mut call_lock = call.lock().await; if call_lock.current_channel().is_some() { call_lock.play_input(input); diff --git a/src/commands/tts.rs b/src/commands/tts.rs index 8d20179..f45d2e8 100644 --- a/src/commands/tts.rs +++ b/src/commands/tts.rs @@ -15,7 +15,7 @@ pub enum OutputMode { Vc, } -/// Generate TTS (Piper locally, Google as fallback) and output to file or voice channel +/// Generate TTS (local Piper) and output to file or voice channel #[poise::command(slash_command)] pub async fn tts( ctx: Context<'_>, @@ -25,21 +25,21 @@ pub async fn tts( ctx.defer().await?; let output = output.unwrap_or(OutputMode::Vc); - let (audio_data, ext) = - crate::tts::synthesize(&ctx.data().config, &ctx.data().http_client, &text).await?; + let audio_data = ctx.data().tts.synthesize(&text).await?; match output { OutputMode::File => { + let wav = crate::tts::encode_wav(&audio_data, 48000, 2); + tokio::fs::create_dir_all(crate::config::TEMP_PATH) .await .ok(); let path = format!( - "{}/tts_{}.{}", + "{}/tts_{}.wav", crate::config::TEMP_PATH, uuid::Uuid::new_v4(), - ext ); - tokio::fs::write(&path, &audio_data).await?; + tokio::fs::write(&path, &wav).await?; if let Err(e) = ctx .send( poise::CreateReply::default() @@ -69,7 +69,7 @@ pub async fn tts( .voice_manager .connect(guild_id, channel_id) .await?; - let input = crate::voice::decode_audio(&audio_data)?; + let input = crate::tts::pcm_bytes_to_input(audio_data); let mut call_lock = call.lock().await; if call_lock.current_channel().is_some() { call_lock.play_input(input); -- cgit v1.2.3