Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
import deepspeech
|
| 5 |
import requests
|
| 6 |
import tarfile
|
|
|
|
| 7 |
|
| 8 |
# إعداد المسار للنموذج
|
| 9 |
MODEL_DIR = 'deepspeech_model'
|
|
@@ -15,14 +16,14 @@ AUDIO_URL = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/audi
|
|
| 15 |
def download_model():
|
| 16 |
if not os.path.exists(MODEL_DIR):
|
| 17 |
os.makedirs(MODEL_DIR)
|
| 18 |
-
|
| 19 |
if not os.path.exists(MODEL_PATH):
|
| 20 |
print("Downloading model...")
|
| 21 |
model_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm'
|
| 22 |
response = requests.get(model_url)
|
| 23 |
with open(MODEL_PATH, 'wb') as f:
|
| 24 |
f.write(response.content)
|
| 25 |
-
|
| 26 |
if not os.path.exists(SCORER_PATH):
|
| 27 |
print("Downloading scorer...")
|
| 28 |
scorer_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer'
|
|
@@ -37,7 +38,7 @@ def download_audio_samples():
|
|
| 37 |
response = requests.get(AUDIO_URL)
|
| 38 |
with open('audio-0.9.3.tar.gz', 'wb') as f:
|
| 39 |
f.write(response.content)
|
| 40 |
-
|
| 41 |
with tarfile.open('audio-0.9.3.tar.gz') as tar:
|
| 42 |
tar.extractall()
|
| 43 |
|
|
@@ -51,8 +52,8 @@ ds_model.enableExternalScorer(SCORER_PATH)
|
|
| 51 |
|
| 52 |
# دالة لتحويل الصوت إلى نص
|
| 53 |
def transcribe(audio):
|
| 54 |
-
|
| 55 |
-
|
| 56 |
return ds_model.stt(audio_data)
|
| 57 |
|
| 58 |
# واجهة المستخدم
|
|
|
|
| 4 |
import deepspeech
|
| 5 |
import requests
|
| 6 |
import tarfile
|
| 7 |
+
import wave
|
| 8 |
|
| 9 |
# إعداد المسار للنموذج
|
| 10 |
MODEL_DIR = 'deepspeech_model'
|
|
|
|
| 16 |
def download_model():
|
| 17 |
if not os.path.exists(MODEL_DIR):
|
| 18 |
os.makedirs(MODEL_DIR)
|
| 19 |
+
|
| 20 |
if not os.path.exists(MODEL_PATH):
|
| 21 |
print("Downloading model...")
|
| 22 |
model_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm'
|
| 23 |
response = requests.get(model_url)
|
| 24 |
with open(MODEL_PATH, 'wb') as f:
|
| 25 |
f.write(response.content)
|
| 26 |
+
|
| 27 |
if not os.path.exists(SCORER_PATH):
|
| 28 |
print("Downloading scorer...")
|
| 29 |
scorer_url = 'https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer'
|
|
|
|
| 38 |
response = requests.get(AUDIO_URL)
|
| 39 |
with open('audio-0.9.3.tar.gz', 'wb') as f:
|
| 40 |
f.write(response.content)
|
| 41 |
+
|
| 42 |
with tarfile.open('audio-0.9.3.tar.gz') as tar:
|
| 43 |
tar.extractall()
|
| 44 |
|
|
|
|
| 52 |
|
| 53 |
# دالة لتحويل الصوت إلى نص
|
| 54 |
def transcribe(audio):
|
| 55 |
+
with wave.open(audio.name, 'rb') as w:
|
| 56 |
+
audio_data = np.frombuffer(w.readframes(w.getnframes()), np.int16)
|
| 57 |
return ds_model.stt(audio_data)
|
| 58 |
|
| 59 |
# واجهة المستخدم
|