-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (80 loc) · 3.36 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 Patrick Mispelhorn <patrick.mispelhorn@web.de>
#
# Izumi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Izumi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# from src.modules.dictation.dictate_module import DictateModule
from src.profile_loader import ProfileLoader
import pygame.mixer
from src.controller import Controller
from src.speech_to_text import SpeechToText
import time
import sys
import os
import argparse
from src.server import RemoteQueueServer
import threading
def main():
parser = argparse.ArgumentParser(description='Izumi a personal assistant')
parser.add_argument('-key', metavar="GOOGLE_API_KEY", type=str,
help="An key for accessing a speech to text API. An default will be used if not set.")
parser.add_argument('-profile', dest="profile_name", required=True, metavar="FILE", type=str,
help='path to a profile for setting up the pipeline')
parser.add_argument('--server', action='store_true',
help='starts remote control')
parser.add_argument('-file', type=str,
help='starts remote control')
parser.add_argument('-port', dest="port", required=False, default=47193, type=int)
# help='path to a profile for setting up the pipeline')
args = parser.parse_args()
#
# init sound output
pygame.init()
pygame.mixer.init()
controller: Controller = Controller(args)
speechToTextModule = SpeechToText(args,controller)
profile_loader = ProfileLoader(controller=controller, speechToText=speechToTextModule)
controller.profileLoader = profile_loader
# Load Profile
assert profile_loader.load_profile(args.profile_name) , "Profile load failed!"
speechToTextModule.start()
if args.server:
server = RemoteQueueServer(speechToTextModule.voice_commands,args.port)
server.run()
while controller.get_mode() != Controller.Mode.POWER_OFF:
text = speechToTextModule.voice_commands.get()
speechToTextModule.voice_commands.task_done()
controller.parse(text)
#events = pygame.event.get()
# print("Process voice command" ,text)
if args.server:
print("stop server")
server.stop()
print("Shutdown ...")
# calling this function requests that the background listener stop listening
speechToTextModule.shutdown()
# do some more unrelated things
# we're not listening anymore, even though the background thread might still be running for a second or two while cleaning u
for _ in range(0, 20):
time.sleep(0.1)
print("Shutdown complete")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)