Spaces:
Build error
Build error
| import os | |
| import numpy as np | |
| import gradio as gr | |
| import deepspeech | |
| import requests | |
| import tarfile | |
| import wave | |
| # ุฅุนุฏุงุฏ ุงูู ุณุงุฑ ูููู ูุฐุฌ | |
| MODEL_DIR = 'deepspeech_model' | |
| MODEL_PATH = os.path.join(MODEL_DIR, 'deepspeech-0.9.3-models.pbmm') | |
| SCORER_PATH = os.path.join(MODEL_DIR, 'deepspeech-0.9.3-models.scorer') | |
| AUDIO_URL = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/audio-0.9.3.tar.gz' | |
| # ุชุญู ูู ุงููู ูุฐุฌ ุฅุฐุง ูู ููู ู ูุฌูุฏูุง | |
| def download_model(): | |
| if not os.path.exists(MODEL_DIR): | |
| os.makedirs(MODEL_DIR) | |
| if not os.path.exists(MODEL_PATH): | |
| print("Downloading model...") | |
| model_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm' | |
| response = requests.get(model_url) | |
| with open(MODEL_PATH, 'wb') as f: | |
| f.write(response.content) | |
| if not os.path.exists(SCORER_PATH): | |
| print("Downloading scorer...") | |
| scorer_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer' | |
| response = requests.get(scorer_url) | |
| with open(SCORER_PATH, 'wb') as f: | |
| f.write(response.content) | |
| # ุชุญู ูู ู ููุงุช ุงูุตูุช ุงูุฃู ุซูุฉ | |
| def download_audio_samples(): | |
| if not os.path.exists('audio'): | |
| print("Downloading audio samples...") | |
| response = requests.get(AUDIO_URL) | |
| with open('audio-0.9.3.tar.gz', 'wb') as f: | |
| f.write(response.content) | |
| with tarfile.open('audio-0.9.3.tar.gz') as tar: | |
| tar.extractall() | |
| # ุชุญู ูู ุงููู ูุฐุฌ ูู ููุงุช ุงูุตูุช | |
| download_model() | |
| download_audio_samples() | |
| # ุชุญู ูู ุงููู ูุฐุฌ | |
| ds_model = deepspeech.Model(MODEL_PATH) | |
| ds_model.enableExternalScorer(SCORER_PATH) | |
| # ุฏุงูุฉ ูุชุญููู ุงูุตูุช ุฅูู ูุต | |
| def transcribe(audio): | |
| with wave.open(audio.name, 'rb') as w: | |
| audio_data = np.frombuffer(w.readframes(w.getnframes()), np.int16) | |
| return ds_model.stt(audio_data) | |
| # ูุงุฌูุฉ ุงูู ุณุชุฎุฏู | |
| interface = gr.Interface(fn=transcribe, inputs="audio", outputs="text") | |
| interface.launch() | |