Skip to content

Commit 43605ec

Browse files
committed
feat: support set groq url
1 parent 8e4d2d3 commit 43605ec

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

src/ai/tts.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ pub async fn stream_gsv(
7474
/// return: wav_audio: 16bit,48k,single-channel.
7575
pub async fn groq(
7676
client: &reqwest::Client,
77+
url: &str,
7778
model: &str,
7879
token: &str,
7980
voice: &str,
8081
text: &str,
8182
) -> anyhow::Result<Bytes> {
83+
let url = if url.is_empty() {
84+
"https://api.groq.com/openai/v1/audio/speech"
85+
} else {
86+
url
87+
};
88+
8289
log::debug!("groq tts. voice: {voice}, text: {text}");
8390
let res = client
84-
.post("https://api.groq.com/openai/v1/audio/speech")
91+
.post(url)
8592
.bearer_auth(token)
8693
.json(&serde_json::json!({
8794
"model":model,
@@ -111,7 +118,7 @@ async fn test_groq() {
111118
let speaker = "Aaliyah-PlayAI";
112119
let text = "你好,我是胡桃";
113120
let client = reqwest::Client::new();
114-
let wav_audio = groq(&client, "playai-tts", &token, speaker, text)
121+
let wav_audio = groq(&client, "", "playai-tts", &token, speaker, text)
115122
.await
116123
.unwrap();
117124
let mut reader = wav_io::reader::Reader::from_vec(wav_audio.to_vec()).unwrap();

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub struct GroqTTS {
7070
pub api_key: String,
7171
pub model: String,
7272
pub voice: String,
73+
#[serde(default)]
74+
pub url: String,
7375
}
7476

7577
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

src/services/realtime_ws.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,15 @@ async fn tts_and_send(
11851185
Ok(())
11861186
}
11871187
crate::config::TTSConfig::Groq(groq) => {
1188-
let wav_data =
1189-
crate::ai::tts::groq(&client, &groq.model, &groq.api_key, &groq.voice, &text)
1190-
.await?;
1188+
let wav_data = crate::ai::tts::groq(
1189+
&client,
1190+
&groq.url,
1191+
&groq.model,
1192+
&groq.api_key,
1193+
&groq.voice,
1194+
&text,
1195+
)
1196+
.await?;
11911197
let duration_sec = send_wav(tx, response_id, item_id, text, wav_data).await?;
11921198
log::info!("Groq TTS duration: {:?}", duration_sec);
11931199
Ok(())

src/services/ws.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,15 @@ async fn tts_and_send(
322322
Ok(duration_sec)
323323
}
324324
crate::config::TTSConfig::Groq(groq) => {
325-
let wav_data =
326-
crate::ai::tts::groq(&client, &groq.model, &groq.api_key, &groq.voice, &text)
327-
.await?;
325+
let wav_data = crate::ai::tts::groq(
326+
&client,
327+
&groq.url,
328+
&groq.model,
329+
&groq.api_key,
330+
&groq.voice,
331+
&text,
332+
)
333+
.await?;
328334
let duration_sec = send_wav(tx, text, wav_data).await?;
329335
log::info!("Groq TTS duration: {:?}", duration_sec);
330336
Ok(duration_sec)

src/services/ws/stable/tts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ async fn groq_tts(
317317
text: &str,
318318
tts_resp_tx: &TTSResponseTx,
319319
) -> anyhow::Result<()> {
320-
let bytes = crate::ai::tts::groq(client, &tts.model, &tts.api_key, &tts.voice, text).await?;
320+
let bytes =
321+
crate::ai::tts::groq(client, &tts.url, &tts.model, &tts.api_key, &tts.voice, text).await?;
321322

322323
tts_resp_tx.send(bytes.to_vec())?;
323324
Ok(())

0 commit comments

Comments
 (0)