DHEIVER commited on
Commit
6f7862c
1 Parent(s): 77e0709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -1,23 +1,31 @@
1
  import gradio as gr
2
- from bark import SAMPLE_RATE, generate_audio, preload_models
3
- from IPython.display import Audio
 
4
 
5
- # Preload models if needed
6
- preload_models()
 
 
 
 
 
 
 
7
 
8
- def create_audio(text):
9
- audio_array = generate_audio(text)
10
- return audio_array, SAMPLE_RATE
 
 
 
11
 
12
  iface = gr.Interface(
13
- fn=create_audio,
14
- inputs=gr.inputs.Textbox(lines=5, placeholder="Digite seu texto aqui..."),
15
- outputs=[
16
- gr.outputs.Audio(type="numpy", label="Audio Gerado"),
17
- gr.outputs.Textbox(label="Taxa de Amostragem")
18
- ],
19
- title="Gerador de Áudio com IA",
20
- description="Digite um texto para gerar áudio usando IA."
21
  )
22
 
23
  iface.launch()
 
1
  import gradio as gr
2
+ from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
3
+ from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
4
+ import numpy as np
5
 
6
+ def load_tts_model():
7
+ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
8
+ "facebook/tts_transformer-zh-cv7_css10",
9
+ arg_overrides={"vocoder": "hifigan", "fp16": False}
10
+ )
11
+ model = models[0]
12
+ TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
13
+ generator = task.build_generator(model, cfg)
14
+ return task, model, generator
15
 
16
+ task, model, generator = load_tts_model()
17
+
18
+ def synthesize_text(text):
19
+ sample = TTSHubInterface.get_model_input(task, text)
20
+ wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
21
+ return np.array(wav), rate
22
 
23
  iface = gr.Interface(
24
+ fn=synthesize_text,
25
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Chinese text here..."),
26
+ outputs=gr.outputs.Audio(label="Synthesized Speech"),
27
+ title="Text to Speech Synthesis",
28
+ description="A simple text-to-speech app using Fairseq TTS model."
 
 
 
29
  )
30
 
31
  iface.launch()