Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -120,11 +120,9 @@ def process_speech(input_language, audio_input):
|
|
| 120 |
except Exception as e :
|
| 121 |
return f"{e}"
|
| 122 |
|
| 123 |
-
import os
|
| 124 |
-
|
| 125 |
def convert_text_to_speech(input_text, target_language):
|
| 126 |
"""
|
| 127 |
-
Convert text to speech in the specified language and return
|
| 128 |
"""
|
| 129 |
try:
|
| 130 |
text_to_speech_result = seamless_client.predict(
|
|
@@ -138,21 +136,21 @@ def convert_text_to_speech(input_text, target_language):
|
|
| 138 |
api_name="/run" # API name
|
| 139 |
)
|
| 140 |
|
| 141 |
-
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
-
max_length = 12 # Maximum file name length
|
| 145 |
dir_name, file_name = os.path.split(audio_file)
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
file_name = file_name[:max_length - len(file_extension)] + file_extension
|
| 150 |
-
audio_file = os.path.join(dir_name, file_name)
|
| 151 |
|
| 152 |
-
|
|
|
|
| 153 |
except Exception as e:
|
| 154 |
return f"An error occurred during text-to-speech conversion: {e}", input_text
|
| 155 |
|
|
|
|
| 156 |
def save_image(image_input, output_dir="saved_images"):
|
| 157 |
if not os.path.exists(output_dir):
|
| 158 |
os.makedirs(output_dir)
|
|
|
|
| 120 |
except Exception as e :
|
| 121 |
return f"{e}"
|
| 122 |
|
|
|
|
|
|
|
| 123 |
def convert_text_to_speech(input_text, target_language):
|
| 124 |
"""
|
| 125 |
+
Convert text to speech in the specified language and return the audio file path and the input text.
|
| 126 |
"""
|
| 127 |
try:
|
| 128 |
text_to_speech_result = seamless_client.predict(
|
|
|
|
| 136 |
api_name="/run" # API name
|
| 137 |
)
|
| 138 |
|
| 139 |
+
# Assuming the audio file path is in the second position of the result
|
| 140 |
+
audio_file = text_to_speech_result[1]
|
| 141 |
|
| 142 |
+
max_length = 25
|
|
|
|
| 143 |
dir_name, file_name = os.path.split(audio_file)
|
| 144 |
+
file_extension = os.path.splitext(file_name)[1]
|
| 145 |
+
shortened_file_name = file_name[:max_length - len(file_extension)] + file_extension
|
| 146 |
+
shortened_audio_file = os.path.join(dir_name, shortened_file_name)
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
# Return the shortened audio file path and the input text
|
| 149 |
+
return shortened_audio_file, input_text
|
| 150 |
except Exception as e:
|
| 151 |
return f"An error occurred during text-to-speech conversion: {e}", input_text
|
| 152 |
|
| 153 |
+
|
| 154 |
def save_image(image_input, output_dir="saved_images"):
|
| 155 |
if not os.path.exists(output_dir):
|
| 156 |
os.makedirs(output_dir)
|