Antoniskaraolis commited on
Commit
3ecb0fd
·
1 Parent(s): ad79b29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -1,17 +1,21 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import soundfile as sf
4
 
 
5
  asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
6
 
7
  def transcribe(audio_file):
8
- data, samplerate = sf.read(audio_file.name)
 
 
9
  transcription = asr_model(data, sampling_rate=samplerate)
10
  return transcription["text"]
11
 
 
12
  iface = gr.Interface(
13
  fn=transcribe,
14
- inputs="audio",
15
  outputs="text"
16
  )
17
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import librosa
4
 
5
+ # Initialize the model
6
  asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
7
 
8
  def transcribe(audio_file):
9
+ # Load the audio file with librosa
10
+ data, samplerate = librosa.load(audio_file.name, sr=None)
11
+ # Pass the audio data to the model for transcription
12
  transcription = asr_model(data, sampling_rate=samplerate)
13
  return transcription["text"]
14
 
15
+ # Create the Gradio interface
16
  iface = gr.Interface(
17
  fn=transcribe,
18
+ inputs=gr.inputs.Audio(source="microphone", type="file"),
19
  outputs="text"
20
  )
21