-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeepSpeech.py
31 lines (26 loc) · 1.02 KB
/
DeepSpeech.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
import logging as log
import deepspeech
import numpy as np
from halo import Halo
class DeepSpeech():
def __init__(self, model_file, scorer_file, vad_audio):
log.info("DeepSpeech model: {}".format(model_file))
self.model = deepspeech.Model(model_file)
log.info("DeepSpeech scorer: {}".format(scorer_file))
self.model.enableExternalScorer(scorer_file)
self.spinner = Halo(spinner='line')
self.vad_audio = vad_audio
self.frames = vad_audio.vad_collector()
def inference(self):
# Stream from microphone to DeepSpeech using VAD
self.vad_audio.clear()
log.info('Started capturing audio')
stream_context = self.model.createStream()
for frame in self.frames:
if frame is not None:
self.spinner.start()
stream_context.feedAudioContent(np.frombuffer(frame, np.int16))
else:
self.spinner.stop()
text = stream_context.finishStream()
return text