MAZALA2024 commited on
Commit
8d4ed80
·
verified ·
1 Parent(s): 32fb87d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -2,27 +2,29 @@ import gradio as gr
2
  import base64
3
  import numpy as np
4
  from scipy.io import wavfile
5
- from voice_processing import tts, get_model_names, voice_mapping
6
  from io import BytesIO
 
7
 
8
- def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload):
 
9
  edge_tts_voice = voice_mapping.get(selected_voice)
10
  if not edge_tts_voice:
11
  return {"error": f"Invalid voice '{selected_voice}'."}, None
12
 
13
  voice_upload_file = None
14
  if use_uploaded_voice and voice_upload is not None:
15
- voice_upload_file = voice_upload.read()
 
16
 
17
- # Call the tts processing function
18
- result = tts(
19
  model_name, tts_text, edge_tts_voice, slang_rate, use_uploaded_voice, voice_upload_file
20
  )
21
-
22
- if isinstance(result, dict) and "error" in result:
23
- return result, None
24
-
25
- info, _, (tgt_sr, audio_output) = result
26
 
27
  # Process audio output to bytes
28
  audio_bytes = None
@@ -47,9 +49,9 @@ def get_voices():
47
  iface = gr.Interface(
48
  fn=convert_tts,
49
  inputs=[
50
- gr.Dropdown(choices=get_models(), label="Model"),
51
  gr.Textbox(label="Text", placeholder="Enter text here"),
52
- gr.Dropdown(choices=get_voices(), label="Voice"),
53
  gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate"),
54
  gr.Checkbox(label="Use Uploaded Voice"),
55
  gr.File(label="Voice File")
@@ -59,8 +61,7 @@ iface = gr.Interface(
59
  gr.Textbox(label="Audio URI")
60
  ],
61
  title="Text-to-Speech Conversion"
62
- # Remove or comment out concurrency parameters not supported in Gradio 4.36.0
63
  )
64
 
65
  # Launch the interface
66
- iface.launch(debug=True, show_error=True)
 
2
  import base64
3
  import numpy as np
4
  from scipy.io import wavfile
5
+ from voice_processing import parallel_tts, get_model_names, voice_mapping
6
  from io import BytesIO
7
+ import asyncio # Import asyncio
8
 
9
+ # Define an asynchronous function for the Gradio interface
10
+ async def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload):
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
+ # Create task for parallel processing
21
+ task = (
22
  model_name, tts_text, edge_tts_voice, slang_rate, use_uploaded_voice, voice_upload_file
23
  )
24
+
25
+ # Asynchronous call to your tts processing function using parallel processing
26
+ result = await asyncio.get_event_loop().run_in_executor(None, parallel_tts, [task])
27
+ info, _, (tgt_sr, audio_output) = result[0]
 
28
 
29
  # Process audio output to bytes
30
  audio_bytes = None
 
49
  iface = gr.Interface(
50
  fn=convert_tts,
51
  inputs=[
52
+ gr.Dropdown(choices=get_models(), label="Model", interactive=True),
53
  gr.Textbox(label="Text", placeholder="Enter text here"),
54
+ gr.Dropdown(choices=get_voices(), label="Voice", interactive=True),
55
  gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate"),
56
  gr.Checkbox(label="Use Uploaded Voice"),
57
  gr.File(label="Voice File")
 
61
  gr.Textbox(label="Audio URI")
62
  ],
63
  title="Text-to-Speech Conversion"
 
64
  )
65
 
66
  # Launch the interface
67
+ iface.launch(debug=True) # Set share=True to create a public link