feat: implement VoiceService with multi-model speech-to-text and text-to-speech capabilities
This commit is contained in:
@@ -121,8 +121,8 @@ class VoiceService:
|
|||||||
and lang_prefix in ["ta", "hi", "te", "kn", "bn", "mr", "gu", "ml", "pa", "od", "en"]
|
and lang_prefix in ["ta", "hi", "te", "kn", "bn", "mr", "gu", "ml", "pa", "od", "en"]
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
speaker = "anushka" if lang_prefix in ["ta", "hi", "te", "kn"] else "karun"
|
speaker = "kavya" if lang_prefix in ["ta", "hi", "te", "kn"] else "gokul"
|
||||||
async with httpx2.AsyncClient(timeout=3.0) as client:
|
async with httpx2.AsyncClient(timeout=5.0) as client:
|
||||||
headers = {
|
headers = {
|
||||||
"api-subscription-key": self.sarvam_key,
|
"api-subscription-key": self.sarvam_key,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -131,7 +131,7 @@ class VoiceService:
|
|||||||
"inputs": [cleaned_text],
|
"inputs": [cleaned_text],
|
||||||
"target_language_code": language_code,
|
"target_language_code": language_code,
|
||||||
"speaker": speaker,
|
"speaker": speaker,
|
||||||
"model": "bulbul:v2",
|
"model": "bulbul:v3",
|
||||||
}
|
}
|
||||||
res = await client.post(
|
res = await client.post(
|
||||||
"https://api.sarvam.ai/text-to-speech",
|
"https://api.sarvam.ai/text-to-speech",
|
||||||
@@ -153,7 +153,7 @@ class VoiceService:
|
|||||||
|
|
||||||
# 2. Use OpenAI TTS
|
# 2. Use OpenAI TTS
|
||||||
if self.openai_key and self.openai_key.strip() not in ["your_openai_api_key", "your_openai_key", ""]:
|
if self.openai_key and self.openai_key.strip() not in ["your_openai_api_key", "your_openai_key", ""]:
|
||||||
client = AsyncOpenAI(api_key=self.openai_key, timeout=1.5)
|
client = AsyncOpenAI(api_key=self.openai_key, timeout=5.0)
|
||||||
try:
|
try:
|
||||||
response = await client.audio.speech.create(
|
response = await client.audio.speech.create(
|
||||||
model="tts-1",
|
model="tts-1",
|
||||||
|
|||||||
Reference in New Issue
Block a user