Spaces:
Sleeping
Sleeping
| import os | |
| import json | |
| import gradio as gr | |
| import wave | |
| import pydub | |
| import vosk | |
| # Path to Vosk model | |
| model_path = "models/vosk-model-small-en-us-0.15" | |
| if not os.path.exists(model_path): | |
| raise FileNotFoundError(f"Model not found at {model_path}") | |
| # Initialize the Vosk model | |
| model = vosk.Model(model_path) | |
| def transcribe(audio): | |
| rec = vosk.KaldiRecognizer(model, 16000) | |
| rec.AcceptWaveform(audio) | |
| result = rec.Result() | |
| text = json.loads(result).get('text', '') | |
| return text | |
| iface = gr.Interface(fn=transcribe, | |
| inputs=gr.inputs.Audio(source="microphone", type="filepath"), | |
| outputs="text", | |
| live=True) | |
| if __name__ == "__main__": | |
| iface.launch() | |