-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
176 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod chatgpt; | ||
pub mod chatgpt_api; | ||
pub mod tts; |
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
File renamed without changes.
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,41 @@ | ||
use crate::util::exception::Exception; | ||
use crate::util::http_client; | ||
|
||
pub struct AzureTTS { | ||
pub endpoint: String, | ||
pub resource: String, | ||
pub api_key: String, | ||
pub voice: String, | ||
} | ||
|
||
impl AzureTTS { | ||
pub async fn synthesize(&self, text: &str) -> Result<Vec<u8>, Exception> { | ||
let body = format!( | ||
r#"<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US"> | ||
<voice name="{}"><mstts:express-as style="narration-relaxed"><![CDATA[ | ||
{text} | ||
]]></mstts:express-as></voice></speak>"#, | ||
self.voice | ||
); | ||
|
||
let response = http_client::http_client() | ||
.post(&self.endpoint) | ||
.header("Ocp-Apim-Subscription-Key", &self.api_key) | ||
.header("User-Agent", &self.resource) | ||
.header("X-Microsoft-OutputFormat", "riff-44100hz-16bit-mono-pcm") | ||
.header("Content-Type", "application/ssml+xml") | ||
.body(body) | ||
.send() | ||
.await?; | ||
|
||
let status = response.status(); | ||
if status != 200 { | ||
let response_text = response.text().await?; | ||
return Err(Exception::ExternalError(format!( | ||
"failed to call azure api, status={status}, response={response_text}" | ||
))); | ||
} | ||
|
||
Ok(response.bytes().await?.to_vec()) | ||
} | ||
} |
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 was deleted.
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub enum Provider { | ||
#[serde(rename = "azure")] | ||
Azure, | ||
#[serde(rename = "gcloud")] | ||
GCloud, | ||
} |
Oops, something went wrong.