aboutsummaryrefslogtreecommitdiffstats
path: root/src/commands/tts.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-09-05 19:35:21 +0200
committersalmonik <salmonik@tuta.io>2026-09-05 19:35:21 +0200
commit8e868894cbcaf421c263f3555af4d29bef653420 (patch)
treea6b6f1de5caeef59367e52a8b7cfa6c2cd9f201d /src/commands/tts.rs
parentremove ` from TTS and make events use lang.rs (diff)
downloadsenator-sperma-8e868894cbcaf421c263f3555af4d29bef653420.tar.gz
senator-sperma-8e868894cbcaf421c263f3555af4d29bef653420.zip
feat: piper now not a subprocess, cache system for TTS
Diffstat (limited to 'src/commands/tts.rs')
-rw-r--r--src/commands/tts.rs14
1 files changed, 7 insertions, 7 deletions
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 {
15 Vc, 15 Vc,
16} 16}
17 17
18/// Generate TTS (Piper locally, Google as fallback) and output to file or voice channel 18/// Generate TTS (local Piper) and output to file or voice channel
19#[poise::command(slash_command)] 19#[poise::command(slash_command)]
20pub async fn tts( 20pub async fn tts(
21 ctx: Context<'_>, 21 ctx: Context<'_>,
@@ -25,21 +25,21 @@ pub async fn tts(
25 ctx.defer().await?; 25 ctx.defer().await?;
26 26
27 let output = output.unwrap_or(OutputMode::Vc); 27 let output = output.unwrap_or(OutputMode::Vc);
28 let (audio_data, ext) = 28 let audio_data = ctx.data().tts.synthesize(&text).await?;
29 crate::tts::synthesize(&ctx.data().config, &ctx.data().http_client, &text).await?;
30 29
31 match output { 30 match output {
32 OutputMode::File => { 31 OutputMode::File => {
32 let wav = crate::tts::encode_wav(&audio_data, 48000, 2);
33
33 tokio::fs::create_dir_all(crate::config::TEMP_PATH) 34 tokio::fs::create_dir_all(crate::config::TEMP_PATH)
34 .await 35 .await
35 .ok(); 36 .ok();
36 let path = format!( 37 let path = format!(
37 "{}/tts_{}.{}", 38 "{}/tts_{}.wav",
38 crate::config::TEMP_PATH, 39 crate::config::TEMP_PATH,
39 uuid::Uuid::new_v4(), 40 uuid::Uuid::new_v4(),
40 ext
41 ); 41 );
42 tokio::fs::write(&path, &audio_data).await?; 42 tokio::fs::write(&path, &wav).await?;
43 if let Err(e) = ctx 43 if let Err(e) = ctx
44 .send( 44 .send(
45 poise::CreateReply::default() 45 poise::CreateReply::default()
@@ -69,7 +69,7 @@ pub async fn tts(
69 .voice_manager 69 .voice_manager
70 .connect(guild_id, channel_id) 70 .connect(guild_id, channel_id)
71 .await?; 71 .await?;
72 let input = crate::voice::decode_audio(&audio_data)?; 72 let input = crate::tts::pcm_bytes_to_input(audio_data);
73 let mut call_lock = call.lock().await; 73 let mut call_lock = call.lock().await;
74 if call_lock.current_channel().is_some() { 74 if call_lock.current_channel().is_some() {
75 call_lock.play_input(input); 75 call_lock.play_input(input);