From 42b672e9f7355862a801e25c47ebc7ae25917215 Mon Sep 17 00:00:00 2001 From: janvarev Date: Wed, 15 Dec 2021 12:53:52 +0300 Subject: [PATCH] rename main classes to VACore. Use VA prefix everywhere --- plugins/core.py | 6 ++--- plugins/plugin_greetings.py | 6 ++--- plugins/plugin_mediacmds.py | 24 +++++++++--------- plugins/plugin_mpchcmult.py | 10 ++++---- plugins/plugin_timer.py | 12 ++++----- plugins/plugin_tts_console.py | 8 +++--- plugins/plugin_tts_pyttsx.py | 10 ++++---- plugins/plugin_weatherowm.py | 8 +++--- plugins/plugin_yandex_rasp.py | 8 +++--- plugins_inactive/plugin_simpleyandexmusic.py | 6 ++--- plugins_inactive/plugin_tts_silero.py | 10 ++++---- plugins_inactive/plugin_wikipediasearch.py | 6 ++--- plugins_inactive/plugin_youtubesearch.py | 6 ++--- runvoiceasscmdline.py => runvacmdline.py | 6 ++--- runvoiceassvosk.py => runvavosk.py | 4 +-- voiceasscore.py => vacore.py | 26 +++----------------- 16 files changed, 68 insertions(+), 88 deletions(-) rename runvoiceasscmdline.py => runvacmdline.py (81%) rename runvoiceassvosk.py => runvavosk.py (98%) rename voiceasscore.py => vacore.py (82%) diff --git a/plugins/core.py b/plugins/core.py index b5f3323..6dc170e 100644 --- a/plugins/core.py +++ b/plugins/core.py @@ -1,10 +1,10 @@ # Core plugin # author: Vladislav Janvarev -from voiceasscore import VoiceAssCore +from vacore import VACore # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Core plugin", "version": "1.7", @@ -24,7 +24,7 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): #print(manifest["options"]) options = manifest["options"] #core.setup_assistant_voice(options["ttsIndex"]) diff --git a/plugins/plugin_greetings.py b/plugins/plugin_greetings.py index 22927cb..e5cdda5 100644 --- a/plugins/plugin_greetings.py +++ b/plugins/plugin_greetings.py @@ -2,10 +2,10 @@ # author: Vladislav Janvarev (inspired by EnjiRouz) import random -from voiceasscore import VoiceAssCore +from vacore import VACore # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Привет", "version": "1.0", @@ -17,7 +17,7 @@ def start(core:VoiceAssCore): } return manifest -def play_greetings(core:VoiceAssCore, phrase: str): +def play_greetings(core:VACore, phrase: str): """ Проигрывание случайной приветственной речи """ diff --git a/plugins/plugin_mediacmds.py b/plugins/plugin_mediacmds.py index 69c8dd0..1b2a44d 100644 --- a/plugins/plugin_mediacmds.py +++ b/plugins/plugin_mediacmds.py @@ -6,7 +6,7 @@ import time import os #from voiceassmain import play_voice_assistant_speech -from voiceasscore import VoiceAssCore +from vacore import VACore # опции useYandexMusicShortcuts = False @@ -14,7 +14,7 @@ useMPCHCRemote = False mpchc = None # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Команды управления мультимедия", "version": "1.1", @@ -46,14 +46,14 @@ def start(core:VoiceAssCore): return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): #print(manifest["options"]) global useYandexMusicShortcuts options = manifest["options"] useYandexMusicShortcuts = options["useYandexMusicShortcuts"] -def play_pause(core:VoiceAssCore, phrase: str): +def play_pause(core:VACore, phrase: str): print("Команда пауза") #pyautogui.keyDown("space") if useMPCHCRemote: @@ -66,7 +66,7 @@ def play_pause(core:VoiceAssCore, phrase: str): pyautogui.press("space") # универсально для всех -def play_next(core:VoiceAssCore, phrase: str): +def play_next(core:VACore, phrase: str): print("Команда дальше") if useMPCHCRemote: @@ -81,7 +81,7 @@ def play_next(core:VoiceAssCore, phrase: str): if useYandexMusicShortcuts: pyautogui.press("l") -def play_prev(core:VoiceAssCore, phrase: str): +def play_prev(core:VACore, phrase: str): print("Команда назад") if useMPCHCRemote: @@ -95,7 +95,7 @@ def play_prev(core:VoiceAssCore, phrase: str): if useYandexMusicShortcuts: pyautogui.press("k") -def toggle_mute(core:VoiceAssCore, phrase: str): +def toggle_mute(core:VACore, phrase: str): if useMPCHCRemote: try: mpchc.volume_mute() @@ -105,17 +105,17 @@ def toggle_mute(core:VoiceAssCore, phrase: str): pyautogui.press("volumemute") -def volume_upX(core:VoiceAssCore, phrase: str, param:int): +def volume_upX(core:VACore, phrase: str, param:int): for i in range(param): volume_up1(core,phrase) -def volume_downX(core:VoiceAssCore, phrase: str, param:int): +def volume_downX(core:VACore, phrase: str, param:int): for i in range(param): volume_down1(core,phrase) -def volume_up1(core:VoiceAssCore, phrase: str): +def volume_up1(core:VACore, phrase: str): if useMPCHCRemote: try: mpchc.volume_up() @@ -125,7 +125,7 @@ def volume_up1(core:VoiceAssCore, phrase: str): pyautogui.press("volumeup") -def volume_down1(core:VoiceAssCore, phrase: str): +def volume_down1(core:VACore, phrase: str): if useMPCHCRemote: try: mpchc.volume_down() @@ -135,7 +135,7 @@ def volume_down1(core:VoiceAssCore, phrase: str): pyautogui.press("volumedown") -def close(core:VoiceAssCore, phrase: str): +def close(core:VACore, phrase: str): if useMPCHCRemote: try: mpchc.exit() diff --git a/plugins/plugin_mpchcmult.py b/plugins/plugin_mpchcmult.py index acc926d..e33ddb0 100644 --- a/plugins/plugin_mpchcmult.py +++ b/plugins/plugin_mpchcmult.py @@ -4,13 +4,13 @@ import subprocess #from voiceassmain import play_voice_assistant_speech -from voiceasscore import VoiceAssCore +from vacore import VACore multPath = "" # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "MPC-HC проигрывание мультиков", "version": "1.2", @@ -27,7 +27,7 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): #print(manifest["options"]) global multPath options = manifest["options"] @@ -36,10 +36,10 @@ def start_with_options(core:VoiceAssCore,manifest:dict): return manifest -def run_player(core:VoiceAssCore, phrase: str): +def run_player(core:VACore, phrase: str): subprocess.Popen([core.mpcHcPath]) -def play_mult(core:VoiceAssCore, phrase: str): +def play_mult(core:VACore, phrase: str): if phrase == "": core.play_voice_assistant_speech("Пожалуйста, уточни какой именно мультик") # здесь надо вернуть контекст, чтобы не добавлять Ирина. но это позже diff --git a/plugins/plugin_timer.py b/plugins/plugin_timer.py index f46c8cc..8dfcd3a 100644 --- a/plugins/plugin_timer.py +++ b/plugins/plugin_timer.py @@ -4,7 +4,7 @@ import time import os -from voiceasscore import VoiceAssCore +from vacore import VACore import utils.num_to_text_ru as num_to_text female_units_min2 = ((u'минуту', u'минуты', u'минут'), 'f') @@ -16,7 +16,7 @@ female_units_sec = ((u'секунда', u'секунды', u'секунд'), 'f' modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Таймер", "version": "1.2", @@ -33,10 +33,10 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): pass -def set_timer(core:VoiceAssCore,phrase:str): +def set_timer(core:VACore, phrase:str): if phrase == "": # таймер по умолчанию - на 5 минут txt = num_to_text.num2text(5, female_units_min) @@ -89,11 +89,11 @@ def set_timer(core:VoiceAssCore,phrase:str): set_timer_real(core,1*60,txt) return -def set_timer_real(core:VoiceAssCore,num:int,txt:str): +def set_timer_real(core:VACore, num:int, txt:str): core.set_timer(num,(after_timer, txt)) core.play_voice_assistant_speech("Ставлю таймер на "+txt) -def after_timer(core:VoiceAssCore,txt:str): +def after_timer(core:VACore, txt:str): options = core.plugin_options(modname) for i in range(options["wavRepeatTimes"]): diff --git a/plugins/plugin_tts_console.py b/plugins/plugin_tts_console.py index bee9ecf..61583c5 100644 --- a/plugins/plugin_tts_console.py +++ b/plugins/plugin_tts_console.py @@ -3,13 +3,13 @@ import os -from voiceasscore import VoiceAssCore +from vacore import VACore import pyttsx3 modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "TTS console (for debug)", "version": "1.0", @@ -21,9 +21,9 @@ def start(core:VoiceAssCore): } return manifest -def init(core:VoiceAssCore): +def init(core:VACore): pass -def say(core:VoiceAssCore,text_to_speech:str): +def say(core:VACore, text_to_speech:str): # просто выводим текст в консоль print("TTS: {}".format(text_to_speech)) \ No newline at end of file diff --git a/plugins/plugin_tts_pyttsx.py b/plugins/plugin_tts_pyttsx.py index 19f46bc..c55aeb0 100644 --- a/plugins/plugin_tts_pyttsx.py +++ b/plugins/plugin_tts_pyttsx.py @@ -3,13 +3,13 @@ import os -from voiceasscore import VoiceAssCore +from vacore import VACore import pyttsx3 modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "TTS pyttsx", "version": "1.0", @@ -25,10 +25,10 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): pass -def init(core:VoiceAssCore): +def init(core:VACore): options = core.plugin_options(modname) core.ttsEngine = pyttsx3.init() @@ -56,7 +56,7 @@ def init(core:VoiceAssCore): core.ttsEngine.setProperty("voice", voices[options["sysId"]].id) core.ttsEngine.setProperty("volume", 1.0) -def say(core:VoiceAssCore,text_to_speech:str): +def say(core:VACore, text_to_speech:str): """ Проигрывание речи ответов голосового ассистента (без сохранения аудио) :param text_to_speech: текст, который нужно преобразовать в речь diff --git a/plugins/plugin_weatherowm.py b/plugins/plugin_weatherowm.py index 3da03c7..584be3b 100644 --- a/plugins/plugin_weatherowm.py +++ b/plugins/plugin_weatherowm.py @@ -5,12 +5,12 @@ import os -from voiceasscore import VoiceAssCore +from vacore import VACore modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Погода (open weather map)", "version": "1.0", @@ -32,7 +32,7 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): options = manifest["options"] @@ -67,7 +67,7 @@ def start_with_options(core:VoiceAssCore,manifest:dict): return -def run_weather(core:VoiceAssCore,phrase:str,addparam:str): +def run_weather(core:VACore, phrase:str, addparam:str): options = core.plugin_options(modname) diff --git a/plugins/plugin_yandex_rasp.py b/plugins/plugin_yandex_rasp.py index 7c352e0..a638e9e 100644 --- a/plugins/plugin_yandex_rasp.py +++ b/plugins/plugin_yandex_rasp.py @@ -3,12 +3,12 @@ import os -from voiceasscore import VoiceAssCore +from vacore import VACore modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Яндекс Расписания", "version": "1.0", @@ -28,10 +28,10 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): pass -def run_poezd(core:VoiceAssCore,phrase:str): +def run_poezd(core:VACore, phrase:str): options = core.plugin_options(modname) diff --git a/plugins_inactive/plugin_simpleyandexmusic.py b/plugins_inactive/plugin_simpleyandexmusic.py index 30672df..bdc191a 100644 --- a/plugins_inactive/plugin_simpleyandexmusic.py +++ b/plugins_inactive/plugin_simpleyandexmusic.py @@ -4,10 +4,10 @@ import pyautogui import time import os -from voiceasscore import VoiceAssCore +from vacore import VACore # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Яндекс Музыка", "version": "1.0", @@ -19,7 +19,7 @@ def start(core:VoiceAssCore): } return manifest -def run_yamus(core:VoiceAssCore,phrase:str): +def run_yamus(core:VACore, phrase:str): if core != None: core.play_voice_assistant_speech("Запускаю музыку") diff --git a/plugins_inactive/plugin_tts_silero.py b/plugins_inactive/plugin_tts_silero.py index d474a9e..94c5802 100644 --- a/plugins_inactive/plugin_tts_silero.py +++ b/plugins_inactive/plugin_tts_silero.py @@ -5,12 +5,12 @@ import os -from voiceasscore import VoiceAssCore +from vacore import VACore modname = os.path.basename(__file__)[:-3] # calculating modname # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "TTS silero", "version": "1.0", @@ -26,10 +26,10 @@ def start(core:VoiceAssCore): } return manifest -def start_with_options(core:VoiceAssCore,manifest:dict): +def start_with_options(core:VACore, manifest:dict): pass -def init(core:VoiceAssCore): +def init(core:VACore): options = core.plugin_options(modname) import os @@ -51,7 +51,7 @@ def init(core:VoiceAssCore): #core.model. -def say(core:VoiceAssCore,text_to_speech:str): +def say(core:VACore, text_to_speech:str): # simple way paths = core.model.save_wav(texts=[text_to_speech], sample_rate=16000) diff --git a/plugins_inactive/plugin_wikipediasearch.py b/plugins_inactive/plugin_wikipediasearch.py index 12cc000..e77a4b8 100644 --- a/plugins_inactive/plugin_wikipediasearch.py +++ b/plugins_inactive/plugin_wikipediasearch.py @@ -3,11 +3,11 @@ import time import os #from voiceassmain import play_voice_assistant_speech -from voiceasscore import VoiceAssCore +from vacore import VACore # based on EnjiRouz realization https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/app.py # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Википедия (поиск)", "version": "1.0", @@ -19,7 +19,7 @@ def start(core:VoiceAssCore): } return manifest -def run_wiki(core:VoiceAssCore,phrase:str): +def run_wiki(core:VACore, phrase:str): # if core != None: # core.play_voice_assistant_speech("Ищу на вики {}".format(phrase)) diff --git a/plugins_inactive/plugin_youtubesearch.py b/plugins_inactive/plugin_youtubesearch.py index 56afc3b..bfdba52 100644 --- a/plugins_inactive/plugin_youtubesearch.py +++ b/plugins_inactive/plugin_youtubesearch.py @@ -3,11 +3,11 @@ import time import os #from voiceassmain import play_voice_assistant_speech -from voiceasscore import VoiceAssCore +from vacore import VACore # based on EnjiRouz realization https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/app.py # функция на старте -def start(core:VoiceAssCore): +def start(core:VACore): manifest = { "name": "Ютуб (поиск)", "version": "1.0", @@ -19,7 +19,7 @@ def start(core:VoiceAssCore): } return manifest -def run_youtube(core:VoiceAssCore,phrase:str): +def run_youtube(core:VACore, phrase:str): if core != None: core.play_voice_assistant_speech("Ищу на ютуб {}".format(phrase)) diff --git a/runvoiceasscmdline.py b/runvacmdline.py similarity index 81% rename from runvoiceasscmdline.py rename to runvacmdline.py index cf481e0..6e584b2 100644 --- a/runvoiceasscmdline.py +++ b/runvacmdline.py @@ -1,13 +1,13 @@ import traceback -from voiceasscore import VoiceAssCore +from vacore import VACore import time # ------------------- main loop ------------------ if __name__ == "__main__": - cmd_core = VoiceAssCore() + cmd_core = VACore() cmd_core.init_with_plugins() - print("Command-line for VoiceAssCore.") + print("Command-line for VoiceAssistantCore.") print("Enter command (user text like 'привет') or 'exit'") # почему бы сразу не отладить какую-то команду? diff --git a/runvoiceassvosk.py b/runvavosk.py similarity index 98% rename from runvoiceassvosk.py rename to runvavosk.py index 4b32126..b10b99b 100644 --- a/runvoiceassvosk.py +++ b/runvavosk.py @@ -7,7 +7,7 @@ import sys import traceback import json -from voiceasscore import VoiceAssCore +from vacore import VACore mic_blocked = False @@ -87,7 +87,7 @@ if __name__ == "__main__": rec = vosk.KaldiRecognizer(model, args.samplerate) # initing core - core = VoiceAssCore() + core = VACore() #core.init_plugin("core") #core.init_plugins(["core"]) core.init_with_plugins() diff --git a/voiceasscore.py b/vacore.py similarity index 82% rename from voiceasscore.py rename to vacore.py index 75ce738..063f6de 100644 --- a/voiceasscore.py +++ b/vacore.py @@ -10,7 +10,7 @@ from jaa import JaaCore version = "2.0" -class VoiceAssCore(JaaCore): +class VACore(JaaCore): def __init__(self): JaaCore.__init__(self) @@ -20,29 +20,9 @@ class VoiceAssCore(JaaCore): self.timersDuration = [0,0,0,0,0,0,0,0] self.commands = { - #"привет|доброе утро": play_greetings, - #"мультик": play_mult, - - - # ("привет"): play_greetings, - # ("мультик"): play_mult, - # ("пауза"): play_pause, - # ("дальше", "вперед"): play_next, - # ("назад"): play_prev, - - # ("bye", "goodbye", "quit", "exit", "stop", "пока"): play_farewell_and_quit, - # ("search", "google", "find", "найди"): search_for_term_on_google, - # ("video", "youtube", "watch", "видео"): search_for_video_on_youtube, - # ("wikipedia", "definition", "about", "определение", "википедия"): search_for_definition_on_wikipedia, - # ("translate", "interpretation", "translation", "перевод", "перевести", "переведи"): get_translation, - # ("language", "язык"): change_language, - # ("weather", "forecast", "погода", "прогноз"): get_weather_forecast, - # ("facebook", "person", "run", "пробей", "контакт"): run_person_through_social_nets_databases, - # ("toss", "coin", "монета", "подбрось"): toss_coin, } self.ttss = { - } # more options @@ -65,9 +45,9 @@ class VoiceAssCore(JaaCore): def init_with_plugins(self): self.init_plugins(["core"]) if self.isOnline: - print("VoiceAssCore v{0}: run online".format(version)) + print("VoiceAssistantCore v{0}: run online".format(version)) else: - print("VoiceAssCore v{0}: run OFFLINE".format(version)) + print("VoiceAssistantCore v{0}: run OFFLINE".format(version)) print("TTS engines: ",self.ttss.keys()) print("Commands list: ",self.commands.keys()) print("Assistant names: ",self.voiceAssNames)