R-Kentaren commited on
Commit
b51d214
·
verified ·
1 Parent(s): 1e6c39f

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -0
main.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+
3
+
4
+
5
+ def whisper_(input_audio):
6
+ model = whisper.load_model("medium")
7
+
8
+ # load audio and pad/trim it to fit 30 seconds
9
+ audio = whisper.load_audio(input_audio)
10
+ audio = whisper.pad_or_trim(audio)
11
+ # make log-Mel spectrogram and move to the same device as the model
12
+ mel = whisper.log_mel_spectrogram(audio, n_mels=model.dims.n_mels).to(model.device)
13
+
14
+ # detect the spoken language
15
+ _, probs = model.detect_language(mel)
16
+ print(f"Detected language: {max(probs, key=probs.get)}")
17
+
18
+ # decode the audio
19
+ options = whisper.DecodingOptions()
20
+ result = whisper.decode(model, mel, options)
21
+ # print the recognized text
22
+
23
+ text_result = result.text
24
+ return text_result
25
+
26
+