MAZALA2024 commited on
Commit
c405c3a
·
verified ·
1 Parent(s): 2c87986

Update app_parallel.py

Browse files
Files changed (1) hide show
  1. app_parallel.py +9 -10
app_parallel.py CHANGED
@@ -8,34 +8,33 @@ import asyncio
8
 
9
  async def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload):
10
  try:
 
 
11
  edge_tts_voice = voice_mapping.get(selected_voice)
12
  if not edge_tts_voice:
 
13
  return {"error": f"Invalid voice '{selected_voice}'."}, None
14
 
15
  voice_upload_file = None
16
  if use_uploaded_voice and voice_upload is not None:
 
17
  with open(voice_upload.name, 'rb') as f:
18
  voice_upload_file = f.read()
19
 
 
20
  info, edge_output_filename, tts_output_data = await asyncio.wait_for(
21
  tts(model_name, tts_text, edge_tts_voice, slang_rate, use_uploaded_voice, voice_upload_file),
22
- timeout=60 # Adjust timeout as needed
23
  )
 
24
 
25
  if isinstance(info, dict) and "error" in info:
 
26
  return info, None
27
 
 
28
  tgt_sr, audio_output = tts_output_data
29
 
30
- audio_bytes = None
31
- if isinstance(audio_output, np.ndarray):
32
- byte_io = BytesIO()
33
- wavfile.write(byte_io, tgt_sr, audio_output.astype(np.int16))
34
- byte_io.seek(0)
35
- audio_bytes = byte_io.getvalue()
36
- else:
37
- audio_bytes = audio_output
38
-
39
  # Clean up the temporary EdgeTTS output file if it exists
40
  if edge_output_filename and os.path.exists(edge_output_filename):
41
  os.remove(edge_output_filename)
 
8
 
9
  async def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload):
10
  try:
11
+ print(f"Starting TTS for text: {tts_text[:50]}...") # Log the start of processing
12
+
13
  edge_tts_voice = voice_mapping.get(selected_voice)
14
  if not edge_tts_voice:
15
+ print(f"Invalid voice selected: {selected_voice}")
16
  return {"error": f"Invalid voice '{selected_voice}'."}, None
17
 
18
  voice_upload_file = None
19
  if use_uploaded_voice and voice_upload is not None:
20
+ print("Processing uploaded voice file...")
21
  with open(voice_upload.name, 'rb') as f:
22
  voice_upload_file = f.read()
23
 
24
+ print("Calling TTS function...")
25
  info, edge_output_filename, tts_output_data = await asyncio.wait_for(
26
  tts(model_name, tts_text, edge_tts_voice, slang_rate, use_uploaded_voice, voice_upload_file),
27
+ timeout=60
28
  )
29
+ print("TTS function call completed.")
30
 
31
  if isinstance(info, dict) and "error" in info:
32
+ print(f"Error returned from TTS function: {info['error']}")
33
  return info, None
34
 
35
+ print("Processing TTS output...")
36
  tgt_sr, audio_output = tts_output_data
37
 
 
 
 
 
 
 
 
 
 
38
  # Clean up the temporary EdgeTTS output file if it exists
39
  if edge_output_filename and os.path.exists(edge_output_filename):
40
  os.remove(edge_output_filename)