You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-12-08 21:51:53 +02:00
infinite pool for telebot, sleep mode for voice assistant
This commit is contained in:
@@ -43,8 +43,9 @@ def getSerial(url):
|
|||||||
seasons[current_season] = {}
|
seasons[current_season] = {}
|
||||||
continue
|
continue
|
||||||
spans = elem.find_all('span')
|
spans = elem.find_all('span')
|
||||||
|
if not spans: break
|
||||||
audio = spans[2].text
|
audio = spans[2].text
|
||||||
if 'Оригинальная дорожка' in audio or 'Полное дублирование' in audio or 'LostFilm' in audio:
|
if audio in ['Оригинальная дорожка', 'Полное дублирование', 'LostFilm']:
|
||||||
num = int(spans[0].text.split(' ')[0])-1
|
num = int(spans[0].text.split(' ')[0])-1
|
||||||
seasons[current_season][num] = {'href': elem.ul.li.a['href'], 'title': f'{current_season+1} сезон {num+1} серия'}
|
seasons[current_season][num] = {'href': elem.ul.li.a['href'], 'title': f'{current_season+1} сезон {num+1} серия'}
|
||||||
|
|
||||||
|
|||||||
27
main.py
27
main.py
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/local/bin/python3.8
|
#!/usr/local/bin/python3.8
|
||||||
import os
|
import os
|
||||||
import config
|
import config
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
import time
|
|
||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
'Voice Assistant': 'voice_assistant',
|
'Voice Assistant': 'voice_assistant',
|
||||||
@@ -15,28 +13,3 @@ for name, module in modules.items():
|
|||||||
os.system(f'lxterminal --command="python3.8 {config.path}/{module}.py"')
|
os.system(f'lxterminal --command="python3.8 {config.path}/{module}.py"')
|
||||||
except:
|
except:
|
||||||
print(f'[error]\t{name} launch failed')
|
print(f'[error]\t{name} launch failed')
|
||||||
|
|
||||||
def launch_vc():
|
|
||||||
try:
|
|
||||||
print('Voice Assistant activation...')
|
|
||||||
os.system(f'lxterminal --command="python3.8 {config.path}/voice_assistant.py"')
|
|
||||||
except:
|
|
||||||
print(f'[error]\tlaunch failed')
|
|
||||||
|
|
||||||
if config.double_clap_activation:
|
|
||||||
lastClapTime = 0
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
|
||||||
GPIO.setup(12, GPIO.IN)
|
|
||||||
|
|
||||||
def callback(channel):
|
|
||||||
global lastClapTime
|
|
||||||
now = time.time()
|
|
||||||
delta = now - lastClapTime
|
|
||||||
if 0.1 < delta < 0.6:
|
|
||||||
lauch_vc()
|
|
||||||
else:
|
|
||||||
lastClapTime = now
|
|
||||||
|
|
||||||
GPIO.add_event_detect(12, GPIO.RISING, callback=callback)
|
|
||||||
while True: time.sleep(1)
|
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ def execute(msg):
|
|||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
#try:
|
try:
|
||||||
print("Start polling...")
|
print("Start polling...")
|
||||||
bot.polling(callback = check_threads, args = (threads,) )
|
bot.polling(callback = check_threads, args = (threads,) )
|
||||||
#except:
|
except:
|
||||||
print("Polling failed")
|
print("Polling failed")
|
||||||
|
|||||||
@@ -9,10 +9,19 @@ listener = SpeechRecognition.SpeechToText()
|
|||||||
voice = Text2Speech.Engine()
|
voice = Text2Speech.Engine()
|
||||||
threads = []
|
threads = []
|
||||||
memory = []
|
memory = []
|
||||||
online = True
|
|
||||||
voids = 0
|
voids = 0
|
||||||
|
|
||||||
listener.listen_noise()
|
listener.listen_noise()
|
||||||
|
|
||||||
|
if config.double_clap_activation:
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
lastClapTime = 0
|
||||||
|
doubleClap = False
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(12, GPIO.IN)
|
||||||
|
GPIO.add_event_detect(12, GPIO.RISING, callback=checkClap)
|
||||||
|
|
||||||
def reply(responce):
|
def reply(responce):
|
||||||
if responce['text']: # print answer
|
if responce['text']: # print answer
|
||||||
print('Archie: '+responce['text'])
|
print('Archie: '+responce['text'])
|
||||||
@@ -29,6 +38,25 @@ def check_threads():
|
|||||||
thread['finish_event'].clear()
|
thread['finish_event'].clear()
|
||||||
del thread
|
del thread
|
||||||
|
|
||||||
|
# check double clap from arduino microphone module
|
||||||
|
def checkClap(channel):
|
||||||
|
global lastClapTime
|
||||||
|
now = time.time()
|
||||||
|
delta = now - lastClapTime
|
||||||
|
if 0.1 < delta < 0.6:
|
||||||
|
doubleClap = True
|
||||||
|
else:
|
||||||
|
lastClapTime = now
|
||||||
|
|
||||||
|
# waiting for double clap
|
||||||
|
def sleep():
|
||||||
|
global doubleClap
|
||||||
|
while not doubleClap:
|
||||||
|
check_threads()
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
doubleClap = False
|
||||||
|
|
||||||
while True: # main loop
|
while True: # main loop
|
||||||
check_threads()
|
check_threads()
|
||||||
print('\nYou: ', end='')
|
print('\nYou: ', end='')
|
||||||
@@ -38,44 +66,37 @@ while True: # main loop
|
|||||||
if speech['status'] == 'ok':
|
if speech['status'] == 'ok':
|
||||||
print(text)
|
print(text)
|
||||||
voids = 0
|
voids = 0
|
||||||
# set online add clean input if name in text
|
# repeat last answer
|
||||||
if name := list(set(config.names) & set(text.split(' '))):
|
if Command.isRepeat(text):
|
||||||
online = True
|
reply(memory[0]['responce']);
|
||||||
text = text.replace(name[0], '').strip()
|
continue
|
||||||
# recognize and execute command
|
# recognize command with context
|
||||||
if online:
|
try:
|
||||||
# repeat last answer
|
cmd, params = memory[0]['cmd'].checkContext(text).values()
|
||||||
if Command.isRepeat(text):
|
if memory[0].get('params'): params = {**memory[0].get('params'), **params}
|
||||||
reply(memory[0]['responce']);
|
except:
|
||||||
continue
|
cmd, params = Command.reg_find(text).values()
|
||||||
# recognize command with context
|
# execute command
|
||||||
try:
|
responce = cmd.start(params)
|
||||||
cmd, params = memory[0]['cmd'].checkContext(text).values()
|
# say answer
|
||||||
if memory[0].get('params'): params = {**memory[0].get('params'), **params}
|
reply(responce)
|
||||||
except:
|
# waiting answer on question
|
||||||
cmd, params = Command.reg_find(text).values()
|
if responce['type'] == 'question':
|
||||||
# execute command
|
print('\nYou: ', end='')
|
||||||
responce = cmd.start(params)
|
speech = listener.listen()
|
||||||
# say answer
|
if speech['status'] == 'ok':
|
||||||
reply(responce)
|
text = speech['text']
|
||||||
# waiting answer on question
|
print(text)
|
||||||
if responce['type'] == 'question':
|
if responce := responce['callback'].answer(text): reply(responce)
|
||||||
print('\nYou: ', end='')
|
# remember the command
|
||||||
speech = listener.listen()
|
memory.insert(0, {
|
||||||
if speech['status'] == 'ok':
|
'text': text,
|
||||||
text = speech['text']
|
'cmd': cmd,
|
||||||
print(text)
|
'responce': responce,
|
||||||
if responce := responce['callback'].answer(text): reply(responce)
|
})
|
||||||
# remember the command
|
|
||||||
memory.insert(0, {
|
|
||||||
'text': text,
|
|
||||||
'cmd': cmd,
|
|
||||||
'responce': responce,
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
if speech['status'] == 'error': print('Отсутсвует подключение к интернету');
|
if speech['status'] == 'error': print('Отсутсвует подключение к интернету');
|
||||||
elif online and speech['status'] == 'void': voids += 1;
|
elif speech['status'] == 'void': voids += 1;
|
||||||
if online and voids >= 3: online = False; voids = 0
|
if voids >= 3:
|
||||||
if not online:
|
voids = 0
|
||||||
if config.double_clap_activation: break
|
if config.double_clap_activation: sleep()
|
||||||
else: listener.listen_noise()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user