Shifterr commited on
Commit
f116567
·
verified ·
1 Parent(s): 6bbcab1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -2,35 +2,53 @@ import gradio as gr
2
  from TTS.api import TTS
3
  import os
4
 
5
- # 1. Load the Model (Uses GPU if available, otherwise CPU)
6
- # The first run will take about 2-3 minutes to download the 2GB model.
7
  device = "cuda" if os.environ.get("CUDA_VISIBLE_DEVICES") else "cpu"
8
  print(f"Loading XTTS v2 on {device}...")
9
 
 
10
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=(device == "cuda"))
11
 
12
- # 2. Define the Generator Function
13
  def clone_voice(text, speaker_wav_path, language="en"):
14
- if not text or not speaker_wav_path:
 
 
 
 
 
 
 
 
 
15
  return None
16
 
17
  output_path = "output.wav"
18
 
19
- # Generate the audio using the uploaded sample
20
- tts.tts_to_file(
21
- text=text,
22
- file_path=output_path,
23
- speaker_wav=speaker_wav_path,
24
- language=language
25
- )
26
- return output_path
 
 
 
 
 
 
27
 
28
- # 3. Create the API Interface
29
  demo = gr.Interface(
30
  fn=clone_voice,
31
  inputs=[
32
- gr.Textbox(label="Text to Speak"),
33
- gr.Audio(type="filepath", label="Upload Voice Sample (WAV/MP3)")
 
 
 
34
  ],
35
  outputs=gr.Audio(label="Generated Audio"),
36
  title="PLOT Voice Engine (XTTS v2)",
 
2
  from TTS.api import TTS
3
  import os
4
 
5
+ # 1. Load Model
6
+ # We check if CUDA is available to select GPU or CPU
7
  device = "cuda" if os.environ.get("CUDA_VISIBLE_DEVICES") else "cpu"
8
  print(f"Loading XTTS v2 on {device}...")
9
 
10
+ # Initialize TTS with the target model
11
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=(device == "cuda"))
12
 
 
13
  def clone_voice(text, speaker_wav_path, language="en"):
14
+ # DEBUGGING: Print what we received
15
+ print(f"--- NEW REQUEST ---")
16
+ print(f"Text: {text}")
17
+ print(f"Speaker Path: {speaker_wav_path}")
18
+
19
+ if not text:
20
+ print("Error: No text provided.")
21
+ return None
22
+ if not speaker_wav_path:
23
+ print("Error: No audio file provided.")
24
  return None
25
 
26
  output_path = "output.wav"
27
 
28
+ try:
29
+ # Generate audio
30
+ tts.tts_to_file(
31
+ text=text,
32
+ file_path=output_path,
33
+ speaker_wav=speaker_wav_path,
34
+ language=language
35
+ )
36
+ print(f"Success! Generated: {output_path}")
37
+ return output_path
38
+
39
+ except Exception as e:
40
+ print(f"CRASH DURING GENERATION: {e}")
41
+ return None
42
 
43
+ # 2. Interface
44
  demo = gr.Interface(
45
  fn=clone_voice,
46
  inputs=[
47
+ gr.Textbox(label="Text to Speak", value="Hello, this is a test of my cloned voice."),
48
+ gr.Audio(
49
+ label="Upload Voice Sample (WAV/MP3)",
50
+ type="filepath" # CRITICAL: Forces Gradio to send a file path, not a numpy array
51
+ )
52
  ],
53
  outputs=gr.Audio(label="Generated Audio"),
54
  title="PLOT Voice Engine (XTTS v2)",