Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -155,32 +155,27 @@ def process_audio_to_text(audio_path, inputlanguage="English", outputlanguage="E
|
|
155 |
return result[0]
|
156 |
|
157 |
|
158 |
-
def process_text_to_audio(text, translatefrom="English", translateto="English"
|
159 |
"""
|
160 |
-
Convert text input to audio
|
161 |
"""
|
162 |
try:
|
163 |
-
|
|
|
164 |
text,
|
165 |
translatefrom,
|
166 |
translateto,
|
167 |
api_name="/t2st"
|
168 |
)
|
169 |
-
if "error" in audio_response:
|
170 |
-
raise ValueError(f"API Error: {audio_response['error']}")
|
171 |
-
audio_data = audio_response[0]
|
172 |
|
173 |
-
|
174 |
-
|
|
|
175 |
|
176 |
-
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
with open(file_path, 'wb') as file:
|
181 |
-
file.write(audio_data)
|
182 |
-
|
183 |
-
return file_path
|
184 |
except Exception as e:
|
185 |
print(f"Error processing text to audio: {e}")
|
186 |
return None
|
|
|
155 |
return result[0]
|
156 |
|
157 |
|
158 |
+
def process_text_to_audio(text, translatefrom="English", translateto="English"):
|
159 |
"""
|
160 |
+
Convert text input to audio using the Gradio client and return the local file path of the generated audio.
|
161 |
"""
|
162 |
try:
|
163 |
+
# Call the client's predict method with the text, source language, and target language
|
164 |
+
result = audio_client.predict(
|
165 |
text,
|
166 |
translatefrom,
|
167 |
translateto,
|
168 |
api_name="/t2st"
|
169 |
)
|
|
|
|
|
|
|
170 |
|
171 |
+
# The result is expected to be a tuple (audio_file_path, translated_text)
|
172 |
+
if not isinstance(result, tuple) or len(result) < 2:
|
173 |
+
raise ValueError("Unexpected result format from audio_client.predict")
|
174 |
|
175 |
+
audio_file_path, _ = result # Ignore the translated text for this function's purpose
|
176 |
|
177 |
+
# Return the local file path of the generated audio
|
178 |
+
return audio_file_path
|
|
|
|
|
|
|
|
|
179 |
except Exception as e:
|
180 |
print(f"Error processing text to audio: {e}")
|
181 |
return None
|