DHEIVER commited on
Commit
3b8b3c3
1 Parent(s): 838529c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -34
app.py CHANGED
@@ -1,40 +1,24 @@
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", # Considere usar um modelo para inglês
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
- # Exemplos pré-carregados em inglês
24
- examples = [
25
- ["Hello, how are you today?"],
26
- ["What's the weather like?"],
27
- ["Learning new languages is fun."],
28
- # Adicione mais exemplos aqui
29
- ]
30
-
31
- iface = gr.Interface(
32
- fn=synthesize_text,
33
- inputs=gr.inputs.Textbox(lines=2, placeholder="Enter English text here..."),
34
- outputs=gr.outputs.Audio(label="Synthesized Speech"),
35
- title="Text to Speech Synthesis",
36
- description="A simple text-to-speech app. Note: The model is trained for Chinese, results may vary for English.",
37
- examples=examples,
38
- theme="huggingface"
39
  )
40
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
 
3
 
4
+ # Initialize the pipeline
5
+ pipe = pipeline("text-to-speech", model="suno/bark-small")
 
 
 
 
 
 
 
6
 
7
+ # Define a function to handle the text-to-speech conversion
8
+ def text_to_speech(text):
9
+ output = pipe(text)
10
+ # Assuming the output is a sound file, we return the path to the sound file
11
+ return output['path']
12
 
13
+ # Create a Gradio interface
14
+ interface = gr.Interface(
15
+ fn=text_to_speech,
16
+ inputs="text",
17
+ outputs="audio",
18
+ title="Text-to-Speech App",
19
+ description="Convert text to speech using Hugging Face's Transformers"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  )
21
 
22
+ # Launch the app
23
+ if __name__ == "__main__":
24
+ interface.launch()