gitgato commited on
Commit
a983024
verified
1 Parent(s): 4c3abe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -24
app.py CHANGED
@@ -1,34 +1,48 @@
1
- import spaces
2
  import gradio as gr
3
  import torch
4
  from TTS.api import TTS
5
  import os
 
 
6
  os.environ["COQUI_TOS_AGREED"] = "1"
7
 
8
- device = "cuda"
 
9
 
10
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
 
11
 
12
- @spaces.GPU(enable_queue=True)
13
  def clone(text, audio):
14
- tts.tts_to_file(text=text, speaker_wav=audio, language="es", file_path="./output.wav")
15
- return "./output.wav"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- iface = gr.Interface(fn=clone,
18
- inputs=[gr.Textbox(label='Text'),gr.Audio(type='filepath', label='Voice reference audio file')],
19
- outputs=gr.Audio(type='filepath'),
20
- title='cn-speech-esss',
21
- description="""
22
- by [Gitgato](gitgato)
23
- This space uses xtts_v2 model. Non-commercial use only. [Coqui Public Model License](https://coqui.ai/cpml)
24
-
25
- Please 鉂わ笍 this Space. <a href="mailto: a@om">Email me</a>.
26
- """,
27
- theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),
28
- examples=[["Hey! It's me Dorthy, from the Wizard of Oz. Type in whatever you'd like me to say.","./audio/Wizard-of-Oz-Dorthy.wav"],
29
- ["It's me Vito Corleone, from the Godfather. Type in whatever you'd like me to say.","./audio/Godfather.wav"],
30
- ["Hey, it's me Paris Hilton. Type in whatever you'd like me to say.","./audio/Paris-Hilton.mp3"],
31
- ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.","./audio/Megan-Fox.mp3"],
32
- ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.","./audio/Jeff-Goldblum.mp3"],
33
- ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.","./audio/Heath-Ledger.mp3"],])
34
- iface.launch()
 
 
1
  import gradio as gr
2
  import torch
3
  from TTS.api import TTS
4
  import os
5
+
6
+ # Aceptar t茅rminos de uso de Coqui TTS
7
  os.environ["COQUI_TOS_AGREED"] = "1"
8
 
9
+ # Configurar para usar CPU si no hay GPU disponible
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
+ # Inicializar el modelo de TTS con manejo seguro de carga
13
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=torch.cuda.is_available()).to(device)
14
 
15
+ # Funci贸n para clonar la voz y generar el archivo de audio
16
  def clone(text, audio):
17
+ output_path = "./output.wav"
18
+ tts.tts_to_file(text=text, speaker_wav=audio, language="es", file_path=output_path)
19
+ return output_path
20
+
21
+ # Interfaz de Gradio
22
+ iface = gr.Interface(
23
+ fn=clone,
24
+ inputs=[
25
+ gr.Textbox(label='Text'),
26
+ gr.Audio(type='filepath', label='Voice reference audio file')
27
+ ],
28
+ outputs=gr.Audio(type='filepath'),
29
+ title='cn-speech-esss',
30
+ description="""
31
+ by [Gitgato](gitgato)
32
+ This space uses the xtts_v2 model. Non-commercial use only. [Coqui Public Model License](https://coqui.ai/cpml)
33
+
34
+ Please 鉂わ笍 this Space. <a href="mailto:a@om">Email me</a>.
35
+ """,
36
+ theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"),
37
+ examples=[
38
+ ["Hey! It's me Dorthy, from the Wizard of Oz. Type in whatever you'd like me to say.", "./audio/Wizard-of-Oz-Dorthy.wav"],
39
+ ["It's me Vito Corleone, from the Godfather. Type in whatever you'd like me to say.", "./audio/Godfather.wav"],
40
+ ["Hey, it's me Paris Hilton. Type in whatever you'd like me to say.", "./audio/Paris-Hilton.mp3"],
41
+ ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.", "./audio/Megan-Fox.mp3"],
42
+ ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.", "./audio/Jeff-Goldblum.mp3"],
43
+ ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.", "./audio/Heath-Ledger.mp3"],
44
+ ]
45
+ )
46
 
47
+ # Lanzar la interfaz
48
+ iface.launch()