Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pip install ffmpeg ffprobe
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from transformers import WhisperProcessor
|
| 6 |
+
pipe = pipeline(task="automatic-speech-recognition", model="openai/whisper-tiny")
|
| 7 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-tiny")
|
| 8 |
+
pipe.model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="english", task="transcribe")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def recognize(input_audio):
|
| 14 |
+
print('?????????-------------')
|
| 15 |
+
print(type(input_audio))
|
| 16 |
+
print(input_audio)
|
| 17 |
+
output_text = pipe(input_audio)['text']
|
| 18 |
+
return output_text
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("""
|
| 26 |
+
""")
|
| 27 |
+
# 录音功能
|
| 28 |
+
input_audio = gr.Audio(source="microphone", type="filepath", label='Audio')
|
| 29 |
+
|
| 30 |
+
audio_button = gr.Button(value="Recognize!")
|
| 31 |
+
text = gr.Textbox(lines=2, label='你要不要看看你说了啥???')
|
| 32 |
+
audio_button.click(recognize, inputs=[input_audio], outputs=[text])
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
demo.launch()
|