hugoiabd commited on
Commit
1209d66
·
verified ·
1 Parent(s): a64e0be

Script caso 1 Whisper (app.py)

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import numpy as np
4
+
5
+ pipe = pipeline(
6
+ "automatic-speech-recognition", model="openai/whisper-base"
7
+ )
8
+
9
+ def transcribe(audio):
10
+ sr, y = audio
11
+ # Pasamos el array de muestras a tipo NumPy de 32 bits
12
+ y = y.astype(np.float32)
13
+ y /= np.max(np.abs(y))
14
+
15
+ return pipe({"sampling_rate": sr, "raw": y})["text"]
16
+
17
+ import gradio as gr
18
+
19
+ demo = gr.Interface(
20
+ transcribe,
21
+ gr.Audio(sources=["microphone"]),
22
+ "text",
23
+ )
24
+
25
+ demo.launch(share=True)