-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_whispers.py
executable file
·52 lines (39 loc) · 1.18 KB
/
test_whispers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import time
import torch
# from datasets import load_dataset
from transformers import pipeline
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# Load pipeline
# big, small etc
pipe = pipeline(
"automatic-speech-recognition",
model="bofenghuang/whisper-small-cv11-german",
device=device,
)
# NB: set forced_decoder_ids for generation utils
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(
language="de", task="transcribe"
)
pipe.model.eval()
# NB: decoding option
# limit the maximum number of generated tokens to 225
pipe.model.config.max_length = 225 + 1
# sampling
# pipe.model.config.do_sample = True
# beam search
# pipe.model.config.num_beams = 5
# return
# pipe.model.config.return_dict_in_generate = True
# pipe.model.config.output_scores = True
# pipe.model.config.num_return_sequences = 5
start_time = time.time()
import soundfile as sf
# load wave file from disk
waveform, sr = sf.read("out.wav")
# Run
with torch.no_grad():
generated_sentences = pipe(waveform)["text"]
print(generated_sentences)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time:.5f} seconds")