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
/
app.py
50 lines (39 loc) · 1.47 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
import logging
import os
import requests
from spokestack.io.pyaudio import PyAudioOutput
from spokestack.profile.wakeword_asr import WakewordSpokestackASR
from spokestack.tts.clients.spokestack import TextToSpeechClient
from spokestack.tts.manager import TextToSpeechManager
from const import DEFAULT_MODEL_URL, FILE_NAMES, KEY_ID, KEY_SECRET, SAVE_PATH
_LOGGER = logging.getLogger(__name__)
def main():
# download wakeword models
download_models(DEFAULT_MODEL_URL)
# initialize the speech pipeline
pipeline = WakewordSpokestackASR.create(
spokestack_id=KEY_ID, spokestack_secret=KEY_SECRET, model_dir="tflite"
)
# initialize text to speech
manager = TextToSpeechManager(
client=TextToSpeechClient(key_id=KEY_ID, key_secret=KEY_SECRET),
output=PyAudioOutput(),
)
# add activation handler
@pipeline.event
def on_activate(context):
manager.synthesize("wake word detected", "text", "demo-male")
pipeline.run()
def download_models(model_url):
"""Download wake word models from URL."""
_LOGGER.info("Downloading Wake Word Models")
# make a local save path for the models
os.makedirs(SAVE_PATH, exist_ok=True)
for name in FILE_NAMES:
# retreive the model
req = requests.get(os.path.join(model_url, name))
# write the model locally
with open(os.path.join(SAVE_PATH, name), "wb") as file:
file.write(req.content)
if __name__ == "__main__":
main()