Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,22 +140,24 @@ def process_speech(input_language, audio_input):
|
|
| 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 |
|
| 147 |
try:
|
| 148 |
result = client.predict(
|
| 149 |
-
"T2ST",
|
| 150 |
-
"",
|
| 151 |
-
None,
|
| 152 |
-
None,
|
| 153 |
-
input_text,
|
| 154 |
-
source_language,
|
| 155 |
-
target_language,
|
| 156 |
-
api_name="/run",
|
| 157 |
)
|
| 158 |
-
|
| 159 |
# Initialize variables
|
| 160 |
translated_text = ""
|
| 161 |
new_file_path = ""
|
|
@@ -170,23 +172,20 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
|
|
| 170 |
if not translated_text:
|
| 171 |
translated_text = item
|
| 172 |
elif os.path.isdir(item):
|
| 173 |
-
#
|
| 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('.
|
| 177 |
-
|
| 178 |
-
new_file_path =
|
| 179 |
-
|
| 180 |
-
break # Stop after finding the first audio file
|
| 181 |
if new_file_path:
|
| 182 |
-
break
|
| 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 |
|
| 192 |
def process_image(image_input):
|
|
|
|
| 140 |
return f"{e}"
|
| 141 |
|
| 142 |
|
| 143 |
+
import os
|
| 144 |
+
import uuid
|
| 145 |
|
| 146 |
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]:
|
| 147 |
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
|
| 148 |
|
| 149 |
try:
|
| 150 |
result = client.predict(
|
| 151 |
+
task_name="T2ST",
|
| 152 |
+
audio_source="",
|
| 153 |
+
input_audio_mic=None,
|
| 154 |
+
input_audio_file=None,
|
| 155 |
+
input_text=input_text,
|
| 156 |
+
source_language=source_language,
|
| 157 |
+
target_language=target_language,
|
| 158 |
+
api_name="/run",
|
| 159 |
)
|
| 160 |
+
|
| 161 |
# Initialize variables
|
| 162 |
translated_text = ""
|
| 163 |
new_file_path = ""
|
|
|
|
| 172 |
if not translated_text:
|
| 173 |
translated_text = item
|
| 174 |
elif os.path.isdir(item):
|
| 175 |
+
# Find the first MP3 file in the directory
|
| 176 |
for file in os.listdir(item):
|
| 177 |
file_path = os.path.join(item, file)
|
| 178 |
+
if os.path.isfile(file_path) and file_path.endswith('.mp3'):
|
| 179 |
+
# Return the path of the MP3 file directly without renaming
|
| 180 |
+
new_file_path = file_path
|
| 181 |
+
break
|
|
|
|
| 182 |
if new_file_path:
|
| 183 |
+
break
|
| 184 |
|
| 185 |
return new_file_path, translated_text
|
| 186 |
|
| 187 |
except Exception as e:
|
| 188 |
return f"Error in text-to-speech conversion: {str(e)}", ""
|
|
|
|
|
|
|
| 189 |
|
| 190 |
|
| 191 |
def process_image(image_input):
|