ItzRoBeerT commited on
Commit
e53f453
·
verified ·
1 Parent(s): 780f1f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -1,22 +1,32 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
3
- import scipy
4
 
5
- def getText(text):
6
- return text
 
 
7
 
8
  def say_something(text):
9
- synthesiser = pipeline("text-to-speech", "suno/bark-small")
10
- speech = synthesiser("Hello world!", forward_params={"do_sample": True})
11
- scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"])
12
- return "bark_out.wav"
 
 
 
 
 
 
 
13
 
14
 
15
  with gr.Blocks() as demo:
16
- textBox = gr.Textbox(label="Text")
17
  button = gr.Button("Generate Speech")
18
  audio_output = gr.Audio(label="Generated Speech")
19
- button.click( say_something, outputs=[audio_output])
20
 
21
 
22
  demo.launch()
 
1
+ import os
2
  import gradio as gr
3
+ from transformers import BarkModel, AutoProcessor
4
+ import torch
5
 
6
+ # Desactivar paralelismo en tokenizers para evitar advertencias
7
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
8
+
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
 
11
  def say_something(text):
12
+ processor = AutoProcessor.from_pretrained("suno/bark-small")
13
+
14
+ model = BarkModel.from_pretrained("suno/bark-small").to(device)
15
+
16
+ inputs = processor(text)
17
+ audio_array = model.generate(**inputs)
18
+ audio_array = audio_array.cpu().numpy().squeeze()
19
+
20
+ # Devuelve el audio como un numpy array junto con el sample rate
21
+ sample_rate = model.generation_config.sample_rate
22
+ return (sample_rate, audio_array)
23
 
24
 
25
  with gr.Blocks() as demo:
26
+ textBox = gr.Textbox(label="Text", value="Hello! [laugths]. This is a test!")
27
  button = gr.Button("Generate Speech")
28
  audio_output = gr.Audio(label="Generated Speech")
29
+ button.click(say_something, inputs=textBox, outputs=audio_output)
30
 
31
 
32
  demo.launch()