Spaces:
Runtime error
Runtime error
app.py
CHANGED
@@ -5,9 +5,24 @@ import whisper
|
|
5 |
|
6 |
def speech_to_text(tmp_filename, model_size):
|
7 |
model = whisper.load_model(model_size)
|
8 |
-
result = model.transcribe(tmp_filename)
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
gr.Interface(
|
|
|
5 |
|
6 |
def speech_to_text(tmp_filename, model_size):
|
7 |
model = whisper.load_model(model_size)
|
|
|
8 |
|
9 |
+
# load audio and pad/trim it to fit 30 seconds
|
10 |
+
audio = whisper.load_audio("audio.mp3")
|
11 |
+
audio = whisper.pad_or_trim(audio)
|
12 |
+
|
13 |
+
# make log-Mel spectrogram and move to the same device as the model
|
14 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
15 |
+
|
16 |
+
# detect the spoken language
|
17 |
+
_, probs = model.detect_language(mel)
|
18 |
+
print(f"Detected language: {max(probs, key=probs.get)}")
|
19 |
+
|
20 |
+
# decode the audio
|
21 |
+
options = whisper.DecodingOptions()
|
22 |
+
result = whisper.decode(model, mel, options)
|
23 |
+
|
24 |
+
# print the recognized text
|
25 |
+
print(result.text)
|
26 |
|
27 |
|
28 |
gr.Interface(
|