Spaces:
Sleeping
Sleeping
Download app.py from SujanMidatani/speechToText: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/spaces/SujanMidatani/speechToText/resolve/main/app.py
- Command line
-
hf download hf://spaces/SujanMidatani/speechToText/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SujanMidatani/speechToText/resolve/main/app.py
673 Bytes
| import os | |
| import gradio as gr | |
| os.system("sudo apt-get update") | |
| os.system("apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg") | |
| # import sounddevice as sd | |
| import speech_recognition as sr | |
| recognizer = sr.Recognizer() | |
| def translate(audio_path:str,lang:str): | |
| with sr.AudioFile(audio_path) as source: | |
| audio = recognizer.record(source) | |
| try: | |
| spoken_text = recognizer.recognize_google(audio,language=lang) | |
| return spoken_text | |
| except: | |
| gr.Error("some error rised") | |
| k=gr.Interface(fn=translate, inputs=[gr.Audio(source="upload", type="filepath"),gr.Text(label="lang")], outputs="text") | |
| k.launch() |