papasega commited on
Commit
0819861
1 Parent(s): 7a1921e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -4,8 +4,16 @@ import gradio as gr
4
  model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
5
 
6
  def transcribe(audio):
7
- audio_file_path = audio[0]
8
- return model.transcribe_file(audio_file_path)
 
 
 
 
 
 
 
 
9
 
10
  demo = gr.Interface(
11
  fn=transcribe,
 
4
  model = EncoderASR.from_hparams("speechbrain/asr-wav2vec2-dvoice-wolof")
5
 
6
  def transcribe(audio):
7
+ if isinstance(audio, str): # Si audio est un chemin de fichier
8
+ return model.transcribe_file(audio)
9
+ else: # Si audio est un tuple (cas du microphone)
10
+ sr, y = audio
11
+ y = y.astype(np.float32)
12
+ y /= np.max(np.abs(y))
13
+ # Enregistrer temporairement l'audio pour utiliser la méthode transcribe_file
14
+ temp_file = 'temp.wav'
15
+ sf.write(temp_file, y, sr)
16
+ return model.transcribe_file(temp_file)
17
 
18
  demo = gr.Interface(
19
  fn=transcribe,