-
Notifications
You must be signed in to change notification settings - Fork 37
/
transcribe_whisper.py
41 lines (27 loc) · 1.06 KB
/
transcribe_whisper.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
from concurrent.futures import ThreadPoolExecutor
from utils import recognizer, microphone
from state import state_store
def process_audio(recognizer, audio, model, fn):
text = recognizer.recognize_whisper_api(audio)
print("[whisper] transcript: ", text)
# Cancels the noise words to some extent
if (len(text) > 8):
fn(text)
else:
print("[whisper] ignored cause noise:", text)
voice_recognition_executor = ThreadPoolExecutor(4)
def get_callback(fn):
def callback(recognizer, audio):
voice_recognition_executor.submit(process_audio, recognizer, audio,
"small.en", fn)
return callback
with microphone as source:
print("[whisper] Calibrating...")
recognizer.adjust_for_ambient_noise(source)
def transcribe_whisper(fn):
callback = get_callback(fn)
print("[whisper] Listening...")
stop = recognizer.listen_in_background(microphone,
callback,
phrase_time_limit=10)
return stop