Amamrnaf commited on
Commit
034f936
·
1 Parent(s): cc8d375
Files changed (1) hide show
  1. app.py +30 -21
app.py CHANGED
@@ -1,24 +1,33 @@
1
  import gradio as gr
2
  import os
3
-
4
- def process_input(text_input, speaker_audio, speaker_name, option_selected):
5
- if speaker_audio is None or speaker_name.strip() == "":
6
- return "Please provide a valid audio file and speaker name."
7
-
8
- # Save speaker audio under the name of the speaker
9
- speaker_audio_path = f"{speaker_name}.wav"
10
- speaker_audio.save(speaker_audio_path)
11
-
12
- # Placeholder for generating the output audio
13
- output_audio_path = f"generated_{speaker_name}.wav"
14
-
15
- # Assuming some TTS or cloning process here
16
- # Generate and save the output audio
17
- # Replace this with your actual processing logic
18
- with open(output_audio_path, "wb") as f:
19
- f.write(b"Placeholder audio data") # Replace with actual audio data
20
-
21
- return output_audio_path
 
 
 
 
 
 
 
 
 
22
 
23
  # Gradio interface
24
  with gr.Blocks() as demo:
@@ -31,14 +40,14 @@ with gr.Blocks() as demo:
31
  speaker_audio = gr.Audio(label="Speaker Audio (to be cloned)",type='filepath', format='wav')
32
  speaker_name = gr.Textbox(label="Speaker Name", placeholder="Enter the speaker's name.")
33
 
34
- option_selected = gr.Dropdown(choices=["Option 1", "Option 2", "Option 3"], label="Select an Option")
35
 
36
  submit_btn = gr.Button("Submit")
37
 
38
  output_audio = gr.Audio(label="Generated Audio Output")
39
 
40
  submit_btn.click(
41
- process_input,
42
  inputs=[text_input, speaker_audio, speaker_name, option_selected],
43
  outputs=output_audio,
44
  )
 
1
  import gradio as gr
2
  import os
3
+ from coqui_tts import run_audio_generation_v1
4
+
5
+ def process_audio(input_text, speaker_audio, speaker_name, option_selected):
6
+ try:
7
+ # Ensure necessary directories exist
8
+ os.makedirs("./tmp/audio/input_src/", exist_ok=True)
9
+ os.makedirs("audio", exist_ok=True)
10
+
11
+ # Save speaker audio to the required location
12
+ speaker_audio_path = "./tmp/audio/input_src/0.wav"
13
+ with open(speaker_audio_path, "wb") as f:
14
+ f.write(speaker_audio)
15
+
16
+ # Check selected option and execute corresponding function
17
+ if option_selected == "Xtts_v2":
18
+ # Generate TTS audio using run_audio_generation_v1
19
+ run_audio_generation_v1(input_text)
20
+ else:
21
+ return f"The option '{option_selected}' is not implemented yet."
22
+
23
+ # Save the output audio under the speaker's name
24
+ speaker_output_path = f"audio/{speaker_name}.wav"
25
+ os.rename("audio/output.wav", speaker_output_path)
26
+
27
+ return speaker_output_path
28
+
29
+ except Exception as e:
30
+ return str(e)
31
 
32
  # Gradio interface
33
  with gr.Blocks() as demo:
 
40
  speaker_audio = gr.Audio(label="Speaker Audio (to be cloned)",type='filepath', format='wav')
41
  speaker_name = gr.Textbox(label="Speaker Name", placeholder="Enter the speaker's name.")
42
 
43
+ option_selected = gr.Dropdown(choices=["Xtts_v2", "metaVoice(not working at the moment)", "more"], label="Select an Option")
44
 
45
  submit_btn = gr.Button("Submit")
46
 
47
  output_audio = gr.Audio(label="Generated Audio Output")
48
 
49
  submit_btn.click(
50
+ fn=process_audio,
51
  inputs=[text_input, speaker_audio, speaker_name, option_selected],
52
  outputs=output_audio,
53
  )