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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -5,9 +5,14 @@ import librosa
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"]
@@ -15,8 +20,8 @@ def transcribe(audio_file):
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
 
22
- iface.launch()
 
5
  # Initialize the model
6
  asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
7
 
8
+ def transcribe(audio_data):
9
+ # librosa expects a file path, but gradio passes a tuple (file name, file object)
10
+ # If the audio comes from a microphone, it's in the second position of the tuple
11
+ if isinstance(audio_data, tuple):
12
+ audio_data = audio_data[1]
13
+
14
  # Load the audio file with librosa
15
+ data, samplerate = librosa.load(audio_data, sr=None)
16
  # Pass the audio data to the model for transcription
17
  transcription = asr_model(data, sampling_rate=samplerate)
18
  return transcription["text"]
 
20
  # Create the Gradio interface
21
  iface = gr.Interface(
22
  fn=transcribe,
23
+ inputs=gr.Audio(source="microphone", type="file", label="Record or Upload Audio"),
24
  outputs="text"
25
  )
26
 
27
+ iface.launch()