Spaces:
Sleeping
Sleeping
Washedashore
commited on
Commit
•
6800da3
1
Parent(s):
8cb94ac
Create python
Browse files
python
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
|
3 |
+
model = whisper.load_model("turbo")
|
4 |
+
|
5 |
+
# load audio and pad/trim it to fit 30 seconds
|
6 |
+
audio = whisper.load_audio("audio.mp3")
|
7 |
+
audio = whisper.pad_or_trim(audio)
|
8 |
+
|
9 |
+
# make log-Mel spectrogram and move to the same device as the model
|
10 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
11 |
+
|
12 |
+
# detect the spoken language
|
13 |
+
_, probs = model.detect_language(mel)
|
14 |
+
print(f"Detected language: {max(probs, key=probs.get)}")
|
15 |
+
|
16 |
+
# decode the audio
|
17 |
+
options = whisper.DecodingOptions()
|
18 |
+
result = whisper.decode(model, mel, options)
|
19 |
+
|
20 |
+
# print the recognized text
|
21 |
+
print(result.text)
|