Afrinetwork7
commited on
Commit
•
1771b70
1
Parent(s):
be921fa
Update app.py
Browse files
app.py
CHANGED
@@ -94,16 +94,18 @@ async def transcribe_audio(request: AudioRequest):
|
|
94 |
async def synthesize_speech(request: TTSRequest):
|
95 |
logger.info(f"Synthesize request received: text='{request.text}', language='{request.language}', speed={request.speed}")
|
96 |
try:
|
|
|
|
|
|
|
97 |
# Input validation
|
98 |
-
logger.info("Validating input parameters")
|
99 |
if not request.text:
|
100 |
raise ValueError("Text cannot be empty")
|
101 |
-
if
|
102 |
raise ValueError(f"Unsupported language: {request.language}")
|
103 |
if not 0.5 <= request.speed <= 2.0:
|
104 |
raise ValueError(f"Speed must be between 0.5 and 2.0, got {request.speed}")
|
105 |
|
106 |
-
logger.info("Calling synthesize function")
|
107 |
result, filtered_text = synthesize(request.text, request.language, request.speed)
|
108 |
logger.info(f"Synthesize function completed. Filtered text: '{filtered_text}'")
|
109 |
|
@@ -164,7 +166,7 @@ async def synthesize_speech(request: TTSRequest):
|
|
164 |
content={"message": "An unexpected error occurred during speech synthesis", "details": error_details}
|
165 |
)
|
166 |
finally:
|
167 |
-
logger.info("Synthesize request completed")
|
168 |
|
169 |
@app.post("/identify")
|
170 |
async def identify_language(request: AudioRequest):
|
|
|
94 |
async def synthesize_speech(request: TTSRequest):
|
95 |
logger.info(f"Synthesize request received: text='{request.text}', language='{request.language}', speed={request.speed}")
|
96 |
try:
|
97 |
+
# Extract the ISO code from the full language name
|
98 |
+
lang_code = request.language.split()[0].strip()
|
99 |
+
|
100 |
# Input validation
|
|
|
101 |
if not request.text:
|
102 |
raise ValueError("Text cannot be empty")
|
103 |
+
if lang_code not in TTS_LANGUAGES:
|
104 |
raise ValueError(f"Unsupported language: {request.language}")
|
105 |
if not 0.5 <= request.speed <= 2.0:
|
106 |
raise ValueError(f"Speed must be between 0.5 and 2.0, got {request.speed}")
|
107 |
|
108 |
+
logger.info(f"Calling synthesize function with lang_code: {lang_code}")
|
109 |
result, filtered_text = synthesize(request.text, request.language, request.speed)
|
110 |
logger.info(f"Synthesize function completed. Filtered text: '{filtered_text}'")
|
111 |
|
|
|
166 |
content={"message": "An unexpected error occurred during speech synthesis", "details": error_details}
|
167 |
)
|
168 |
finally:
|
169 |
+
logger.info("Synthesize request completed")
|
170 |
|
171 |
@app.post("/identify")
|
172 |
async def identify_language(request: AudioRequest):
|