forked from limapedro/mila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (36 loc) · 1007 Bytes
/
main.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
# Import libraries
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer
import os
import pyaudio
import json
import pyttsx3
# Import the core lib
from core import SystemInfo
# Import NLU classifier
from nlu.classifier import classify
# Speech Synthesis
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
# Speech Recognition
model = Model("model")
rec = KaldiRecognizer(model, 16000)
# Opens microphone for listening.
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=4096)
stream.start_stream()
while True:
data = stream.read(2048)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
# result is a string
result = rec.Result()
# convert it to a json/dictionary
result = json.loads(result)
text = result['text']
entity = classify(text)
if entity == 'time\\getTime':
speak(SystemInfo.get_time())