malek-messaoudii
commited on
Commit
·
a61d0cb
1
Parent(s):
77e2cd7
feat: Update generate_speech function to use gTTS backend with MP3 format and modify voice parameter to accept language codes. Clean up tts_service.py by removing unused GROQ API key checks and related code.
Browse files- services/mcp_service.py +5 -1
- services/tts_service.py +1 -21
services/mcp_service.py
CHANGED
|
@@ -49,7 +49,11 @@ def transcribe_audio(audio_path: str) -> str:
|
|
| 49 |
return speech_to_text(audio_path)
|
| 50 |
|
| 51 |
@mcp_server.tool()
|
| 52 |
-
def generate_speech(text: str, voice: str = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return text_to_speech(text, voice, format)
|
| 54 |
|
| 55 |
@mcp_server.tool()
|
|
|
|
| 49 |
return speech_to_text(audio_path)
|
| 50 |
|
| 51 |
@mcp_server.tool()
|
| 52 |
+
def generate_speech(text: str, voice: str = "en", format: str = "mp3") -> str:
|
| 53 |
+
"""
|
| 54 |
+
Generate speech using the free gTTS backend (MP3 only).
|
| 55 |
+
'voice' expects a language code (e.g., 'en', 'fr').
|
| 56 |
+
"""
|
| 57 |
return text_to_speech(text, voice, format)
|
| 58 |
|
| 59 |
@mcp_server.tool()
|
services/tts_service.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import uuid
|
| 2 |
from pathlib import Path
|
| 3 |
-
from config import GROQ_TTS_API_KEY, GROQ_TTS_MODEL
|
| 4 |
from gtts import gTTS
|
| 5 |
|
|
|
|
| 6 |
def text_to_speech(
|
| 7 |
text: str,
|
| 8 |
voice: str = "en",
|
|
@@ -12,26 +12,6 @@ def text_to_speech(
|
|
| 12 |
Convert text to speech using gTTS (Google Translate, free).
|
| 13 |
Only MP3 is supported.
|
| 14 |
"""
|
| 15 |
-
if not GROQ_TTS_API_KEY:
|
| 16 |
-
raise RuntimeError("GROQ_TTS_API_KEY is not set in config")
|
| 17 |
-
|
| 18 |
-
if not text or not text.strip():
|
| 19 |
-
raise ValueError("Text cannot be empty")
|
| 20 |
-
|
| 21 |
-
url = "https://api.groq.com/openai/v1/audio/speech"
|
| 22 |
-
|
| 23 |
-
headers = {
|
| 24 |
-
"Authorization": f"Bearer {GROQ_TTS_API_KEY}",
|
| 25 |
-
"Content-Type": "application/json"
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
payload = {
|
| 29 |
-
"model": GROQ_TTS_MODEL,
|
| 30 |
-
"input": text.strip(),
|
| 31 |
-
"voice": voice,
|
| 32 |
-
"response_format": fmt
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
if not text or not text.strip():
|
| 36 |
raise ValueError("Text cannot be empty")
|
| 37 |
|
|
|
|
| 1 |
import uuid
|
| 2 |
from pathlib import Path
|
|
|
|
| 3 |
from gtts import gTTS
|
| 4 |
|
| 5 |
+
|
| 6 |
def text_to_speech(
|
| 7 |
text: str,
|
| 8 |
voice: str = "en",
|
|
|
|
| 12 |
Convert text to speech using gTTS (Google Translate, free).
|
| 13 |
Only MP3 is supported.
|
| 14 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if not text or not text.strip():
|
| 16 |
raise ValueError("Text cannot be empty")
|
| 17 |
|