Tonic commited on
Commit
e98c8c0
1 Parent(s): 81dcc03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
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", # Task
150
- "", # Audio source
151
- None, # Input audio mic
152
- None, # Input audio file
153
- input_text, # Input text
154
- source_language, # Source language
155
- target_language, # Target language
156
- api_name="/run", # API endpoint
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
- # 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
 
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):