From 4e589cf53de08e3689ab5c62ca7efe90f4ac9f48 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 29 Nov 2024 15:40:55 +0100 Subject: Set audio folder --- src/audio.rs | 5 +++-- src/config.rs | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/audio.rs b/src/audio.rs index a67f3da..961af4a 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -14,7 +14,6 @@ use std::{ pub async fn tts(text: String, filename: String) -> Result<(), String> { let url = "https://api.v7.unrealspeech.com/stream"; let api_key = format!("Bearer {}", CONFIG.unrealspeech_token); - let filepath = format!("./assets/sounds/{}", filename); // Request JSON body let body = serde_json::json!({ @@ -45,6 +44,8 @@ pub async fn tts(text: String, filename: String) -> Result<(), String> { // Check for successful response if response.status().is_success() { + let filepath = format!("{}/{}", CONFIG.audio_path, filename); + let mut file = File::create(filepath).unwrap(); let content = response.bytes().await.unwrap(); let _ = file.write_all(&content); @@ -75,7 +76,7 @@ pub async fn show_file( ); } - let file_name = format!("./assets/sounds/{}", id); + let file_name = format!("{}/{}", CONFIG.audio_path, id); let file_path = StdPath::new(&file_name); if !file_path.exists() { diff --git a/src/config.rs b/src/config.rs index 763b852..11c46e8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,9 @@ pub struct Configuration { /// Token used for text-to-speach API pub unrealspeech_token: String, + + /// Audio folder path + pub audio_path: String, } impl Configuration { -- cgit v1.2.3-18-g5258