Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
+
import gradio as gr
|
4 |
+
import whisper
|
5 |
+
|
6 |
+
# call whisper model for audio/speech processing
|
7 |
+
model = whisper.load_model("small")
|
8 |
+
|
9 |
+
def inference_audio(audio):
|
10 |
+
audio = whisper.load_audio(audio)
|
11 |
+
audio = whisper.pad_or_trim(audio)
|
12 |
+
|
13 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
14 |
+
|
15 |
+
_, probs = model.detect_language(mel)
|
16 |
+
|
17 |
+
options = whisper.DecodingOptions(fp16 = False)
|
18 |
+
result = whisper.decode(model, mel, options)
|
19 |
+
|
20 |
+
return result.text
|
21 |
+
|
22 |
+
|
23 |
+
app=gr.Interface(title="Speech to texxt",fn=inference_audio,inputs=gr.Audio(source="microphone"), outputs=["text"]).launch(debug = True)
|