papasega commited on
Commit
5111bf2
1 Parent(s): 5749237

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -28
app.py CHANGED
@@ -19,39 +19,20 @@
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()
 
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 transcribe(audio_or_file):
26
+ if isinstance(audio_or_file, str): # If input is a file path
27
+ return model.transcribe_file(audio_or_file)
28
+ else: # If input is audio from microphone
29
+ return model.transcribe_array(audio_or_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  demo = gr.Interface(
32
+ transcribe,
33
+ ["state", gr.inputs.Microphone(source="local", type="wav"), "text"],
34
+ ["state", "text"],
35
+ live=True,
 
 
 
36
  )
37
 
38
  demo.launch()