You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-11-23 21:34:45 +02:00
Add online/offline mode, change Command.find() and @Command.background() returns, fix bugs
This commit is contained in:
45
main.py
45
main.py
@@ -2,11 +2,14 @@ import SpeechRecognition
|
||||
import Text2Speech
|
||||
import SmallTalk
|
||||
from Command import Command
|
||||
import config
|
||||
|
||||
listener = SpeechRecognition.SpeechToText()
|
||||
voice = Text2Speech.Engine()
|
||||
threads = []
|
||||
memory = []
|
||||
online = False
|
||||
voids = 0
|
||||
listener.listen_noise()
|
||||
|
||||
def check_threads():
|
||||
@@ -14,27 +17,37 @@ def check_threads():
|
||||
if thread['finish_event'].is_set():
|
||||
responce = thread['thread'].join()
|
||||
if responce['text']:
|
||||
voice.generate(responce['text']).speak()
|
||||
print(' — '+responce['text'])
|
||||
if responce['voice']:
|
||||
voice.generate(responce['voice']).speak()
|
||||
thread['finish_event'].clear()
|
||||
del thread
|
||||
|
||||
while True: # main loop
|
||||
check_threads()
|
||||
print('Listening...')
|
||||
print('\nYou: ', end='')
|
||||
speech = listener.listen()
|
||||
text = speech['text']
|
||||
print('You: ')
|
||||
if text:
|
||||
cmd = Command.find(text)
|
||||
responce = cmd.start(text)
|
||||
memory.insert(0, {
|
||||
'text': text,
|
||||
'cmd': cmd,
|
||||
'responce': responce
|
||||
})
|
||||
if responce['type'] == 'background': # add background thread to list
|
||||
threads.append(responce['thread'])
|
||||
if responce['text']:
|
||||
voice.generate(responce['text']).speak()
|
||||
speech['status'] = 'ok' if text else 'void'
|
||||
if speech['status'] == 'ok':
|
||||
print(text)
|
||||
if set(config.names) & set(text.split(' ')): online = True
|
||||
if online:
|
||||
voids = 0
|
||||
cmd, params = Command.reg_find(text).values()
|
||||
responce = cmd.start(text)
|
||||
memory.insert(0, {
|
||||
'text': text,
|
||||
'cmd': cmd,
|
||||
'responce': responce
|
||||
})
|
||||
if responce['type'] == 'background': # add background thread to list
|
||||
threads.append(responce['thread'])
|
||||
if responce['text']:
|
||||
print('Archie: '+responce['text'])
|
||||
if responce['voice']:
|
||||
voice.generate(responce['voice']).speak()
|
||||
else:
|
||||
print(speech['status'])
|
||||
if speech['status'] == 'error': print('Отсутсвует подключение к интернету');
|
||||
elif speech['status'] == 'void': voids += 1
|
||||
if voids >= 3: online = False; voids = 0
|
||||
|
||||
Reference in New Issue
Block a user