| import whisper | |
| import gradio as gr | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| import os | |
| transcription_value = "" | |
| def transcribe_speech(filepath): | |
| if filepath is None: | |
| gr.Warning("No audio found, please retry.") | |
| model = whisper.load_model("base") | |
| result = model.transcribe(filepath, fp16=False) | |
| return result["text"] | |
| def store_transcription(output): | |
| global transcription_value | |
| transcription_value = output | |
| return output | |
| mic_transcribe = gr.Interface( | |
| fn=lambda x: store_transcription(transcribe_speech(x)), | |
| inputs=gr.Audio(sources=["microphone"], type="filepath"), | |
| outputs=gr.Textbox(label="Transcription") | |
| ) | |
| test_interface = gr.Blocks() | |
| with test_interface: | |
| gr.TabbedInterface( | |
| [mic_transcribe], | |
| ["Transcribe Microphone"] | |
| ) | |
| test_interface.launch( | |
| share=True, | |
| server_port=8000, | |
| #prevent_thread_lock=True | |
| ) | |
| print(transcription_value) | |
| #test_interface.close() |