ismaeltorres00 commited on
Commit
243b012
·
verified ·
1 Parent(s): a98b07d

Create app4.py

Browse files
Files changed (1) hide show
  1. app4.py +32 -0
app4.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import numpy as np
3
+ import gradio as gr
4
+
5
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
6
+ tts = pipeline("text-to-speech", model="suno/bark-small")
7
+
8
+ def transcribe(audio):
9
+ sr, y = audio
10
+ y = y.astype(np.float32)
11
+ y /= np.max(np.abs(y))
12
+
13
+ text_generated = transcriber({"sampling_rate": sr, "raw": y})["text"]
14
+ audio_generated = tts(text_generated)
15
+
16
+ audio_returned = audio_generated["sampling_rate"],audio_generated["audio"][0]
17
+
18
+ return [text_generated, audio_returned]
19
+
20
+
21
+ demo = gr.Interface(
22
+ transcribe,
23
+ inputs=gr.Audio(sources=["microphone"]),
24
+ outputs=[
25
+ gr.Text(label="texto generado"),
26
+ gr.Audio(label="audio generado")
27
+ ],
28
+ title="De audio a Whisper y TTS",
29
+ description="Transcribe el audio y luego sintetiza el texto en audio"
30
+ )
31
+
32
+ demo.launch()