akxier commited on
Commit
f57650f
·
verified ·
1 Parent(s): 7c81587

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ def transcribe(audio):
10
+ sr, y = audio
11
+ y = y.astype(np.float32)
12
+ y /= np.max(np.abs(y))
13
+
14
+ text_generated = transcriber({"sampling_rate": sr, "raw": y})["text"]
15
+ audio_generated = tts(text_generated)
16
+
17
+ audio_returned = audio_generated["sampling_rate"],audio_generated["audio"][0]
18
+
19
+ return [text_generated, audio_returned]
20
+
21
+
22
+ demo = gr.Interface(
23
+ transcribe,
24
+ inputs=gr.Audio(sources=["microphone"]),
25
+ outputs=[
26
+ gr.Text(label="texto generado"),
27
+ gr.Audio(label="audio generado")
28
+ ],
29
+ title="De audio a Whisper y TTS",
30
+ description="Transcribe el audio y luego sintetiza el texto en audio"
31
+ )
32
+
33
+ demo.launch()