-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.py
48 lines (36 loc) · 1.07 KB
/
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
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer
import os
import pyaudio
import pyttsx3
import json
import core
from nlu.classifier import classify
# Síntese de fala
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[-2].id)
def speak(text):
engine.say(text)
engine.runAndWait()
# Reconhecimento de fala
model = Model('model')
rec = KaldiRecognizer(model, 16000)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=2048)
stream.start_stream()
# Loop do reconhecimento de fala
while True:
data = stream.read(2048)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
result = rec.Result()
result = json.loads(result)
if result is not None:
text = result['text']
# Reconhecer entidade do texto.
entity = classify(text)
if entity == 'time\getTime':
speak(core.SystemInfo.get_time())
print('Text: {} Entity: {}'.format(text, entity))