-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
601 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod windows; | ||
pub mod azure; | ||
pub mod msedge; | ||
pub mod tiktok; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use reqwest::Client; | ||
use serde_json::json; | ||
use std::error::Error; | ||
use base64::Engine; | ||
|
||
static ENDPOINT: &str = "https://tiktok-tts.weilnet.workers.dev/api/generation"; | ||
|
||
pub struct TikTokTTS { | ||
text: String, | ||
voice: String, | ||
} | ||
|
||
impl TikTokTTS { | ||
pub fn new(text: String, voice: String) -> Self { | ||
Self { text, voice } | ||
} | ||
|
||
pub async fn send(&self) -> Result<Vec<u8>, Box<dyn Error>> { | ||
let client = Client::new(); | ||
let res = client | ||
.post(ENDPOINT) | ||
.header("Content-Type", "application/json") | ||
.json( | ||
&json!({ | ||
"text": self.text, | ||
"voice": self.voice, | ||
}) | ||
) | ||
.send().await?; | ||
let res = res.error_for_status()?; | ||
let data = res.json::<serde_json::Value>().await?; | ||
if !data["success"].as_bool().unwrap_or(false) || !data.get("data").is_some() { | ||
return Err(format!("TikTok API error: {:?}", data).into()); | ||
} | ||
let audio_base64 = data["data"].as_str().ok_or("Invalid audio data")?; | ||
let audio = base64::prelude::BASE64_STANDARD.decode(audio_base64)?; | ||
Ok(audio) | ||
} | ||
} | ||
|
||
pub async fn request(text: &str, voice: &str) -> Result<Vec<u8>, String> { | ||
let tts = TikTokTTS::new(text.to_string(), voice.to_string()); | ||
tts.send().await.map_err(|e| e.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.