1
0
mirror of https://github.com/janvarev/Irene-Voice-Assistant.git synced 2025-11-29 22:58:09 +02:00

rename main classes to VACore. Use VA prefix everywhere

This commit is contained in:
janvarev
2021-12-15 12:53:52 +03:00
parent 89301dd924
commit 42b672e9f7
16 changed files with 68 additions and 88 deletions

View File

@@ -1,10 +1,10 @@
# Core plugin # Core plugin
# author: Vladislav Janvarev # author: Vladislav Janvarev
from voiceasscore import VoiceAssCore from vacore import VACore
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Core plugin", "name": "Core plugin",
"version": "1.7", "version": "1.7",
@@ -24,7 +24,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
#print(manifest["options"]) #print(manifest["options"])
options = manifest["options"] options = manifest["options"]
#core.setup_assistant_voice(options["ttsIndex"]) #core.setup_assistant_voice(options["ttsIndex"])

View File

@@ -2,10 +2,10 @@
# author: Vladislav Janvarev (inspired by EnjiRouz) # author: Vladislav Janvarev (inspired by EnjiRouz)
import random import random
from voiceasscore import VoiceAssCore from vacore import VACore
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Привет", "name": "Привет",
"version": "1.0", "version": "1.0",
@@ -17,7 +17,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def play_greetings(core:VoiceAssCore, phrase: str): def play_greetings(core:VACore, phrase: str):
""" """
Проигрывание случайной приветственной речи Проигрывание случайной приветственной речи
""" """

View File

@@ -6,7 +6,7 @@ import time
import os import os
#from voiceassmain import play_voice_assistant_speech #from voiceassmain import play_voice_assistant_speech
from voiceasscore import VoiceAssCore from vacore import VACore
# опции # опции
useYandexMusicShortcuts = False useYandexMusicShortcuts = False
@@ -14,7 +14,7 @@ useMPCHCRemote = False
mpchc = None mpchc = None
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Команды управления мультимедия", "name": "Команды управления мультимедия",
"version": "1.1", "version": "1.1",
@@ -46,14 +46,14 @@ def start(core:VoiceAssCore):
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
#print(manifest["options"]) #print(manifest["options"])
global useYandexMusicShortcuts global useYandexMusicShortcuts
options = manifest["options"] options = manifest["options"]
useYandexMusicShortcuts = options["useYandexMusicShortcuts"] useYandexMusicShortcuts = options["useYandexMusicShortcuts"]
def play_pause(core:VoiceAssCore, phrase: str): def play_pause(core:VACore, phrase: str):
print("Команда пауза") print("Команда пауза")
#pyautogui.keyDown("space") #pyautogui.keyDown("space")
if useMPCHCRemote: if useMPCHCRemote:
@@ -66,7 +66,7 @@ def play_pause(core:VoiceAssCore, phrase: str):
pyautogui.press("space") # универсально для всех pyautogui.press("space") # универсально для всех
def play_next(core:VoiceAssCore, phrase: str): def play_next(core:VACore, phrase: str):
print("Команда дальше") print("Команда дальше")
if useMPCHCRemote: if useMPCHCRemote:
@@ -81,7 +81,7 @@ def play_next(core:VoiceAssCore, phrase: str):
if useYandexMusicShortcuts: if useYandexMusicShortcuts:
pyautogui.press("l") pyautogui.press("l")
def play_prev(core:VoiceAssCore, phrase: str): def play_prev(core:VACore, phrase: str):
print("Команда назад") print("Команда назад")
if useMPCHCRemote: if useMPCHCRemote:
@@ -95,7 +95,7 @@ def play_prev(core:VoiceAssCore, phrase: str):
if useYandexMusicShortcuts: if useYandexMusicShortcuts:
pyautogui.press("k") pyautogui.press("k")
def toggle_mute(core:VoiceAssCore, phrase: str): def toggle_mute(core:VACore, phrase: str):
if useMPCHCRemote: if useMPCHCRemote:
try: try:
mpchc.volume_mute() mpchc.volume_mute()
@@ -105,17 +105,17 @@ def toggle_mute(core:VoiceAssCore, phrase: str):
pyautogui.press("volumemute") 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): for i in range(param):
volume_up1(core,phrase) 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): for i in range(param):
volume_down1(core,phrase) volume_down1(core,phrase)
def volume_up1(core:VoiceAssCore, phrase: str): def volume_up1(core:VACore, phrase: str):
if useMPCHCRemote: if useMPCHCRemote:
try: try:
mpchc.volume_up() mpchc.volume_up()
@@ -125,7 +125,7 @@ def volume_up1(core:VoiceAssCore, phrase: str):
pyautogui.press("volumeup") pyautogui.press("volumeup")
def volume_down1(core:VoiceAssCore, phrase: str): def volume_down1(core:VACore, phrase: str):
if useMPCHCRemote: if useMPCHCRemote:
try: try:
mpchc.volume_down() mpchc.volume_down()
@@ -135,7 +135,7 @@ def volume_down1(core:VoiceAssCore, phrase: str):
pyautogui.press("volumedown") pyautogui.press("volumedown")
def close(core:VoiceAssCore, phrase: str): def close(core:VACore, phrase: str):
if useMPCHCRemote: if useMPCHCRemote:
try: try:
mpchc.exit() mpchc.exit()

View File

@@ -4,13 +4,13 @@
import subprocess import subprocess
#from voiceassmain import play_voice_assistant_speech #from voiceassmain import play_voice_assistant_speech
from voiceasscore import VoiceAssCore from vacore import VACore
multPath = "" multPath = ""
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "MPC-HC проигрывание мультиков", "name": "MPC-HC проигрывание мультиков",
"version": "1.2", "version": "1.2",
@@ -27,7 +27,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
#print(manifest["options"]) #print(manifest["options"])
global multPath global multPath
options = manifest["options"] options = manifest["options"]
@@ -36,10 +36,10 @@ def start_with_options(core:VoiceAssCore,manifest:dict):
return manifest return manifest
def run_player(core:VoiceAssCore, phrase: str): def run_player(core:VACore, phrase: str):
subprocess.Popen([core.mpcHcPath]) subprocess.Popen([core.mpcHcPath])
def play_mult(core:VoiceAssCore, phrase: str): def play_mult(core:VACore, phrase: str):
if phrase == "": if phrase == "":
core.play_voice_assistant_speech("Пожалуйста, уточни какой именно мультик") core.play_voice_assistant_speech("Пожалуйста, уточни какой именно мультик")
# здесь надо вернуть контекст, чтобы не добавлять Ирина. но это позже # здесь надо вернуть контекст, чтобы не добавлять Ирина. но это позже

View File

@@ -4,7 +4,7 @@
import time import time
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
import utils.num_to_text_ru as num_to_text import utils.num_to_text_ru as num_to_text
female_units_min2 = ((u'минуту', u'минуты', u'минут'), 'f') 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 modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Таймер", "name": "Таймер",
"version": "1.2", "version": "1.2",
@@ -33,10 +33,10 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
pass pass
def set_timer(core:VoiceAssCore,phrase:str): def set_timer(core:VACore, phrase:str):
if phrase == "": if phrase == "":
# таймер по умолчанию - на 5 минут # таймер по умолчанию - на 5 минут
txt = num_to_text.num2text(5, female_units_min) 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) set_timer_real(core,1*60,txt)
return 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.set_timer(num,(after_timer, txt))
core.play_voice_assistant_speech("Ставлю таймер на "+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) options = core.plugin_options(modname)
for i in range(options["wavRepeatTimes"]): for i in range(options["wavRepeatTimes"]):

View File

@@ -3,13 +3,13 @@
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
import pyttsx3 import pyttsx3
modname = os.path.basename(__file__)[:-3] # calculating modname modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "TTS console (for debug)", "name": "TTS console (for debug)",
"version": "1.0", "version": "1.0",
@@ -21,9 +21,9 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def init(core:VoiceAssCore): def init(core:VACore):
pass pass
def say(core:VoiceAssCore,text_to_speech:str): def say(core:VACore, text_to_speech:str):
# просто выводим текст в консоль # просто выводим текст в консоль
print("TTS: {}".format(text_to_speech)) print("TTS: {}".format(text_to_speech))

View File

@@ -3,13 +3,13 @@
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
import pyttsx3 import pyttsx3
modname = os.path.basename(__file__)[:-3] # calculating modname modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "TTS pyttsx", "name": "TTS pyttsx",
"version": "1.0", "version": "1.0",
@@ -25,10 +25,10 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
pass pass
def init(core:VoiceAssCore): def init(core:VACore):
options = core.plugin_options(modname) options = core.plugin_options(modname)
core.ttsEngine = pyttsx3.init() core.ttsEngine = pyttsx3.init()
@@ -56,7 +56,7 @@ def init(core:VoiceAssCore):
core.ttsEngine.setProperty("voice", voices[options["sysId"]].id) core.ttsEngine.setProperty("voice", voices[options["sysId"]].id)
core.ttsEngine.setProperty("volume", 1.0) 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: текст, который нужно преобразовать в речь :param text_to_speech: текст, который нужно преобразовать в речь

View File

@@ -5,12 +5,12 @@
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
modname = os.path.basename(__file__)[:-3] # calculating modname modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Погода (open weather map)", "name": "Погода (open weather map)",
"version": "1.0", "version": "1.0",
@@ -32,7 +32,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
options = manifest["options"] options = manifest["options"]
@@ -67,7 +67,7 @@ def start_with_options(core:VoiceAssCore,manifest:dict):
return return
def run_weather(core:VoiceAssCore,phrase:str,addparam:str): def run_weather(core:VACore, phrase:str, addparam:str):
options = core.plugin_options(modname) options = core.plugin_options(modname)

View File

@@ -3,12 +3,12 @@
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
modname = os.path.basename(__file__)[:-3] # calculating modname modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Яндекс Расписания", "name": "Яндекс Расписания",
"version": "1.0", "version": "1.0",
@@ -28,10 +28,10 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
pass pass
def run_poezd(core:VoiceAssCore,phrase:str): def run_poezd(core:VACore, phrase:str):
options = core.plugin_options(modname) options = core.plugin_options(modname)

View File

@@ -4,10 +4,10 @@ import pyautogui
import time import time
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Яндекс Музыка", "name": "Яндекс Музыка",
"version": "1.0", "version": "1.0",
@@ -19,7 +19,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def run_yamus(core:VoiceAssCore,phrase:str): def run_yamus(core:VACore, phrase:str):
if core != None: if core != None:
core.play_voice_assistant_speech("Запускаю музыку") core.play_voice_assistant_speech("Запускаю музыку")

View File

@@ -5,12 +5,12 @@
import os import os
from voiceasscore import VoiceAssCore from vacore import VACore
modname = os.path.basename(__file__)[:-3] # calculating modname modname = os.path.basename(__file__)[:-3] # calculating modname
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "TTS silero", "name": "TTS silero",
"version": "1.0", "version": "1.0",
@@ -26,10 +26,10 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def start_with_options(core:VoiceAssCore,manifest:dict): def start_with_options(core:VACore, manifest:dict):
pass pass
def init(core:VoiceAssCore): def init(core:VACore):
options = core.plugin_options(modname) options = core.plugin_options(modname)
import os import os
@@ -51,7 +51,7 @@ def init(core:VoiceAssCore):
#core.model. #core.model.
def say(core:VoiceAssCore,text_to_speech:str): def say(core:VACore, text_to_speech:str):
# simple way # simple way
paths = core.model.save_wav(texts=[text_to_speech], paths = core.model.save_wav(texts=[text_to_speech],
sample_rate=16000) sample_rate=16000)

View File

@@ -3,11 +3,11 @@ import time
import os import os
#from voiceassmain import play_voice_assistant_speech #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 # based on EnjiRouz realization https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/app.py
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Википедия (поиск)", "name": "Википедия (поиск)",
"version": "1.0", "version": "1.0",
@@ -19,7 +19,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def run_wiki(core:VoiceAssCore,phrase:str): def run_wiki(core:VACore, phrase:str):
# if core != None: # if core != None:
# core.play_voice_assistant_speech("Ищу на вики {}".format(phrase)) # core.play_voice_assistant_speech("Ищу на вики {}".format(phrase))

View File

@@ -3,11 +3,11 @@ import time
import os import os
#from voiceassmain import play_voice_assistant_speech #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 # based on EnjiRouz realization https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/app.py
# функция на старте # функция на старте
def start(core:VoiceAssCore): def start(core:VACore):
manifest = { manifest = {
"name": "Ютуб (поиск)", "name": "Ютуб (поиск)",
"version": "1.0", "version": "1.0",
@@ -19,7 +19,7 @@ def start(core:VoiceAssCore):
} }
return manifest return manifest
def run_youtube(core:VoiceAssCore,phrase:str): def run_youtube(core:VACore, phrase:str):
if core != None: if core != None:
core.play_voice_assistant_speech("Ищу на ютуб {}".format(phrase)) core.play_voice_assistant_speech("Ищу на ютуб {}".format(phrase))

View File

@@ -1,13 +1,13 @@
import traceback import traceback
from voiceasscore import VoiceAssCore from vacore import VACore
import time import time
# ------------------- main loop ------------------ # ------------------- main loop ------------------
if __name__ == "__main__": if __name__ == "__main__":
cmd_core = VoiceAssCore() cmd_core = VACore()
cmd_core.init_with_plugins() cmd_core.init_with_plugins()
print("Command-line for VoiceAssCore.") print("Command-line for VoiceAssistantCore.")
print("Enter command (user text like 'привет') or 'exit'") print("Enter command (user text like 'привет') or 'exit'")
# почему бы сразу не отладить какую-то команду? # почему бы сразу не отладить какую-то команду?

View File

@@ -7,7 +7,7 @@ import sys
import traceback import traceback
import json import json
from voiceasscore import VoiceAssCore from vacore import VACore
mic_blocked = False mic_blocked = False
@@ -87,7 +87,7 @@ if __name__ == "__main__":
rec = vosk.KaldiRecognizer(model, args.samplerate) rec = vosk.KaldiRecognizer(model, args.samplerate)
# initing core # initing core
core = VoiceAssCore() core = VACore()
#core.init_plugin("core") #core.init_plugin("core")
#core.init_plugins(["core"]) #core.init_plugins(["core"])
core.init_with_plugins() core.init_with_plugins()

View File

@@ -10,7 +10,7 @@ from jaa import JaaCore
version = "2.0" version = "2.0"
class VoiceAssCore(JaaCore): class VACore(JaaCore):
def __init__(self): def __init__(self):
JaaCore.__init__(self) JaaCore.__init__(self)
@@ -20,29 +20,9 @@ class VoiceAssCore(JaaCore):
self.timersDuration = [0,0,0,0,0,0,0,0] self.timersDuration = [0,0,0,0,0,0,0,0]
self.commands = { 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 = { self.ttss = {
} }
# more options # more options
@@ -65,9 +45,9 @@ class VoiceAssCore(JaaCore):
def init_with_plugins(self): def init_with_plugins(self):
self.init_plugins(["core"]) self.init_plugins(["core"])
if self.isOnline: if self.isOnline:
print("VoiceAssCore v{0}: run online".format(version)) print("VoiceAssistantCore v{0}: run online".format(version))
else: else:
print("VoiceAssCore v{0}: run OFFLINE".format(version)) print("VoiceAssistantCore v{0}: run OFFLINE".format(version))
print("TTS engines: ",self.ttss.keys()) print("TTS engines: ",self.ttss.keys())
print("Commands list: ",self.commands.keys()) print("Commands list: ",self.commands.keys())
print("Assistant names: ",self.voiceAssNames) print("Assistant names: ",self.voiceAssNames)