This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (45 loc) · 1.75 KB
/
app.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
53
54
55
from spokestack.activation_timeout import ActivationTimeout
from spokestack.asr.spokestack.speech_recognizer import CloudSpeechRecognizer
from spokestack.io.pyaudio import PyAudioInput, PyAudioOutput
from spokestack.nlu.tflite import TFLiteNLU
from spokestack.pipeline import SpeechPipeline
from spokestack.tts.clients.spokestack import TextToSpeechClient
from spokestack.tts.manager import TextToSpeechManager
from spokestack.vad.webrtc import VoiceActivityDetector
from spokestack.wakeword.tflite import WakewordTrigger
from config import KEY_ID, KEY_SECRET
from minecraft.dialogue_manager import DialogueManager
from minecraft.responses import Response
def main():
pipeline = SpeechPipeline(
PyAudioInput(frame_width=20, sample_rate=16000, exception_on_overflow=False),
[
VoiceActivityDetector(),
WakewordTrigger(pre_emphasis=0.97, model_dir="tflite"),
CloudSpeechRecognizer(spokestack_id=KEY_ID, spokestack_secret=KEY_SECRET),
ActivationTimeout(),
],
)
nlu = TFLiteNLU("tflite")
dialogue_manager = DialogueManager()
manager = TextToSpeechManager(
TextToSpeechClient(KEY_ID, KEY_SECRET), PyAudioOutput(),
)
@pipeline.event
def on_activate(context):
print("active")
@pipeline.event
def on_recognize(context):
pipeline.pause()
results = nlu(context.transcript)
response = dialogue_manager(results)
if response:
manager.synthesize(response, "text", "demo-male")
pipeline.resume()
if results.intent == "AMAZON.StopIntent":
pipeline.stop()
manager.synthesize(Response.WELCOME.value, "text", "demo-male")
pipeline.start()
pipeline.run()
if __name__ == "__main__":
main()