Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,23 +19,40 @@
|
|
19 |
|
20 |
from speechbrain.inference.ASR import EncoderASR
|
21 |
import gradio as gr
|
|
|
|
|
|
|
22 |
|
23 |
model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
|
24 |
|
25 |
-
def
|
26 |
return model.transcribe_file(audio.name)
|
27 |
|
28 |
-
def transcribe_microphone(
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
demo = gr.Interface(
|
32 |
-
fn=[
|
33 |
-
inputs=["file",
|
34 |
-
outputs="text",
|
35 |
-
title="Transcription automatique du wolof",
|
36 |
description="Ce modèle transcrit un fichier audio en wolof en texte en utilisant l'alphabet latin.",
|
37 |
-
input_labels=["Audio en wolof", "Microphone (parlez en wolof)"],
|
38 |
output_label="Transcription alphabet latin"
|
39 |
)
|
40 |
|
41 |
demo.launch()
|
|
|
|
19 |
|
20 |
from speechbrain.inference.ASR import EncoderASR
|
21 |
import gradio as gr
|
22 |
+
import numpy as np
|
23 |
+
import sounddevice as sd
|
24 |
+
import soundfile as sf
|
25 |
|
26 |
model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
|
27 |
|
28 |
+
def transcribe_audio(audio):
|
29 |
return model.transcribe_file(audio.name)
|
30 |
|
31 |
+
def transcribe_microphone():
|
32 |
+
# Record audio from microphone for 5 seconds
|
33 |
+
duration = 60 # seconds
|
34 |
+
fs = 16000 # sampling rate
|
35 |
+
recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype=np.int16)
|
36 |
+
sd.wait()
|
37 |
+
|
38 |
+
# Save recorded audio to a temporary file
|
39 |
+
temp_audio_file = "temp_audio.wav"
|
40 |
+
sf.write(temp_audio_file, recording, fs)
|
41 |
+
|
42 |
+
# Transcribe the recorded audio
|
43 |
+
transcription = model.transcribe_file(temp_audio_file)
|
44 |
+
|
45 |
+
return transcription
|
46 |
|
47 |
demo = gr.Interface(
|
48 |
+
fn=[transcribe_audio, transcribe_microphone],
|
49 |
+
inputs=["file", "microphone"],
|
50 |
+
outputs="text",
|
51 |
+
title="Transcription automatique du wolof",
|
52 |
description="Ce modèle transcrit un fichier audio en wolof en texte en utilisant l'alphabet latin.",
|
53 |
+
input_labels=["Audio en wolof", "Microphone (parlez en wolof)"],
|
54 |
output_label="Transcription alphabet latin"
|
55 |
)
|
56 |
|
57 |
demo.launch()
|
58 |
+
|