Tonic commited on
Commit
19429d3
1 Parent(s): 950e427

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -156,7 +156,7 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
156
 
157
  # Initialize variables
158
  translated_text = ""
159
- new_file_path = ""
160
 
161
  # Process each item in the result
162
  for item in result:
@@ -167,23 +167,16 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
167
  # Assign the first non-URL string as the translated text
168
  if not translated_text:
169
  translated_text = item
170
- elif os.path.isdir(item):
171
- # Find the first MP3 file in the directory
172
- for file in os.listdir(item):
173
- file_path = os.path.join(item, file)
174
- if os.path.isfile(file_path) and file_path.endswith('.mp3'):
175
- # Return the path of the MP3 file directly without renaming
176
- new_file_path = file_path
177
- break
178
- if new_file_path:
179
- break
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
  def process_image(image_input):
188
  # Initialize the Gradio client with the URL of the Gradio server
189
  client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")
 
156
 
157
  # Initialize variables
158
  translated_text = ""
159
+ audio_file_path = ""
160
 
161
  # Process each item in the result
162
  for item in result:
 
167
  # Assign the first non-URL string as the translated text
168
  if not translated_text:
169
  translated_text = item
170
+ elif isinstance(item, tuple) and len(item) == 2:
171
+ # Assuming the item is a tuple containing sample rate and audio data
172
+ audio_file_path = save_audio(item) # Save the audio file
173
+ break
174
+
175
+ return audio_file_path, translated_text
 
 
 
 
 
 
176
 
177
  except Exception as e:
178
  return f"Error in text-to-speech conversion: {str(e)}", ""
179
 
 
180
  def process_image(image_input):
181
  # Initialize the Gradio client with the URL of the Gradio server
182
  client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")