Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,6 +140,7 @@ def process_speech(input_language, audio_input):
|
|
| 140 |
return f"{e}"
|
| 141 |
|
| 142 |
|
|
|
|
| 143 |
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]:
|
| 144 |
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
|
| 145 |
|
|
@@ -156,11 +157,10 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
|
|
| 156 |
)
|
| 157 |
|
| 158 |
# Initialize variables
|
| 159 |
-
original_audio_file = None
|
| 160 |
translated_text = ""
|
| 161 |
new_file_path = ""
|
| 162 |
|
| 163 |
-
#
|
| 164 |
for item in result:
|
| 165 |
if isinstance(item, str):
|
| 166 |
# Check if the item is likely a URL
|
|
@@ -169,19 +169,23 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
|
|
| 169 |
# Assign the first non-URL string as the translated text
|
| 170 |
if not translated_text:
|
| 171 |
translated_text = item
|
| 172 |
-
elif os.path.
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
return new_file_path, translated_text
|
| 182 |
|
| 183 |
except Exception as e:
|
| 184 |
return f"Error in text-to-speech conversion: {str(e)}", ""
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
|
|
|
|
| 140 |
return f"{e}"
|
| 141 |
|
| 142 |
|
| 143 |
+
|
| 144 |
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]:
|
| 145 |
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
|
| 146 |
|
|
|
|
| 157 |
)
|
| 158 |
|
| 159 |
# Initialize variables
|
|
|
|
| 160 |
translated_text = ""
|
| 161 |
new_file_path = ""
|
| 162 |
|
| 163 |
+
# Process each item in the result
|
| 164 |
for item in result:
|
| 165 |
if isinstance(item, str):
|
| 166 |
# Check if the item is likely a URL
|
|
|
|
| 169 |
# Assign the first non-URL string as the translated text
|
| 170 |
if not translated_text:
|
| 171 |
translated_text = item
|
| 172 |
+
elif os.path.isdir(item):
|
| 173 |
+
# Process the directory to find the first audio file
|
| 174 |
+
for file in os.listdir(item):
|
| 175 |
+
file_path = os.path.join(item, file)
|
| 176 |
+
if os.path.isfile(file_path) and file_path.endswith('.wav'):
|
| 177 |
+
new_file_name = f"audio_output_{uuid.uuid4()}.wav"
|
| 178 |
+
new_file_path = os.path.join(os.path.dirname(file_path), new_file_name)
|
| 179 |
+
os.rename(file_path, new_file_path)
|
| 180 |
+
break # Stop after finding the first audio file
|
| 181 |
+
if new_file_path:
|
| 182 |
+
break # Exit if an audio file has been processed
|
| 183 |
|
| 184 |
return new_file_path, translated_text
|
| 185 |
|
| 186 |
except Exception as e:
|
| 187 |
return f"Error in text-to-speech conversion: {str(e)}", ""
|
| 188 |
+
|
| 189 |
|
| 190 |
|
| 191 |
|