found bug in random srs

This commit is contained in:
micialware committed 2026-08-20 11:17:51 +03:00
1 parent 01ba0567f5
commit c5e91b844c
3 files changed
+17 -29

No files matched your search

+7 -9
View File
@@ -4,11 +4,11 @@ use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::BufReader;
pub async fn get_voice(text: &str) -> BufReader<File> {
pub async fn get_voice(text: &str) -> Result<BufReader<File>, ()> {
let mut path = app_data_dir();
path.push("voice");
if !path.exists() {
std::fs::create_dir(path.clone()).unwrap();
std::fs::create_dir(path.clone()).map_err(|_|())?;
}
let hash = format!("{}.wav", hex::encode(Sha256::digest(text.as_bytes())));
path.push(hash);
@@ -20,21 +20,19 @@ pub async fn get_voice(text: &str) -> BufReader<File> {
.send()
.await;
let query = query.unwrap().text().await.unwrap();
let query = query.map_err(|_|())?.text().await.map_err(|_|())?;
// Synthesis
let audio = client
.post(format!("{engine_url}/synthesis?speaker=11"))
.header("Content-Type", "application/json")
.body(query)
.send()
.await
.unwrap()
.await.map_err(|_|())?
.bytes()
.await
.unwrap();
.await.map_err(|_|())?;
tokio::fs::write(&path, &audio).await.unwrap();
tokio::fs::write(&path, &audio).await.map_err(|_|())?;
}
BufReader::new(File::open(path).unwrap())
Ok(BufReader::new(File::open(path).map_err(|_|())?))
}