diff options
| author | salmonik <salmonik@tuta.io> | 2026-09-05 19:35:21 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-09-05 19:35:21 +0200 |
| commit | 8e868894cbcaf421c263f3555af4d29bef653420 (patch) | |
| tree | a6b6f1de5caeef59367e52a8b7cfa6c2cd9f201d /src/commands | |
| parent | remove ` from TTS and make events use lang.rs (diff) | |
| download | senator-sperma-8e868894cbcaf421c263f3555af4d29bef653420.tar.gz senator-sperma-8e868894cbcaf421c263f3555af4d29bef653420.zip | |
feat: piper now not a subprocess, cache system for TTS
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/ai.rs | 5 | ||||
| -rw-r--r-- | src/commands/tts.rs | 14 |
2 files changed, 9 insertions, 10 deletions
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( | |||
| 30 | }) | 30 | }) |
| 31 | .ok_or_else(lang::err_not_in_voice)?; | 31 | .ok_or_else(lang::err_not_in_voice)?; |
| 32 | 32 | ||
| 33 | let (audio_data, _) = | 33 | let audio_data = ctx.data().tts.synthesize(&response).await?; |
| 34 | crate::tts::synthesize(&ctx.data().config, &ctx.data().http_client, &response).await?; | ||
| 35 | 34 | ||
| 36 | let call = ctx | 35 | let call = ctx |
| 37 | .data() | 36 | .data() |
| 38 | .voice_manager | 37 | .voice_manager |
| 39 | .connect(guild_id, channel_id) | 38 | .connect(guild_id, channel_id) |
| 40 | .await?; | 39 | .await?; |
| 41 | let input = crate::voice::decode_audio(&audio_data)?; | 40 | let input = crate::tts::pcm_bytes_to_input(audio_data); |
| 42 | let mut call_lock = call.lock().await; | 41 | let mut call_lock = call.lock().await; |
| 43 | if call_lock.current_channel().is_some() { | 42 | if call_lock.current_channel().is_some() { |
| 44 | call_lock.play_input(input); | 43 | 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 { | |||
| 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)] |
| 20 | pub async fn tts( | 20 | pub 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); |
