Skip to content

Commit

Permalink
Merge pull request #347 from project-alice-assistant/new-interface
Browse files Browse the repository at this point in the history
New interface #307
  • Loading branch information
Psychokiller1888 committed Jan 22, 2021
2 parents 5f6a15a + 900344d commit ac1b51e
Show file tree
Hide file tree
Showing 504 changed files with 26,360 additions and 48,352 deletions.
2 changes: 1 addition & 1 deletion ProjectAlice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version: 1.22
################################################

# How to prevent frequent errors:
# Always add a space after the ":" (e.g. deviceName: default instead of deviceName:default)
# Always add a space after the ":" (e.g. deviceType: default instead of deviceType:default)

# If you place this file into /boot after a first initialization it won't overwrite your settings unless you set this to yes
forceRewrite: no
Expand Down
43 changes: 33 additions & 10 deletions configTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"beforeUpdate": "injectAsound",
"category" : "audio",
"parent" : {
"config" : "disableSoundAndMic",
"config" : "disableSound",
"condition": "isnot",
"value" : true
}
Expand All @@ -59,7 +59,7 @@
"onInit" : "populateAudioOutputConfig",
"onUpdate" : "AudioServer.updateAudioDevices",
"parent" : {
"config" : "disableSoundAndMic",
"config" : "disableSound",
"condition": "isnot",
"value" : true
}
Expand All @@ -74,7 +74,7 @@
"onInit" : "populateAudioInputConfig",
"onUpdate" : "AudioServer.updateAudioDevices",
"parent" : {
"config" : "disableSoundAndMic",
"config" : "disableCapture",
"condition": "isnot",
"value" : true
}
Expand Down Expand Up @@ -138,14 +138,22 @@
"value" : false
}
},
"disableSoundAndMic" : {
"disableSound" : {
"defaultValue": false,
"dataType" : "boolean",
"isSensitive" : false,
"description" : "If this device is a server without sound and mic, turn this to true",
"description" : "Disable sound playback",
"onUpdate" : "enableDisableSound",
"category" : "audio"
},
"disableCapture" : {
"defaultValue": false,
"dataType" : "boolean",
"isSensitive" : false,
"description" : "Disable sound capture",
"onUpdate" : "enableDisableCapture",
"category" : "audio"
},
"notUnderstoodRetries" : {
"defaultValue": 3,
"dataType" : "integer",
Expand Down Expand Up @@ -300,7 +308,12 @@
"dataType" : "boolean",
"isSensitive" : false,
"description" : "Only available with Amazon Polly",
"category" : "tts"
"category" : "tts",
"parent" : {
"config" : "tts",
"condition": "is",
"value" : "amazon"
}
},
"newDeviceBroadcastPort" : {
"defaultValue": 12354,
Expand Down Expand Up @@ -745,29 +758,39 @@
"dataType" : "boolean",
"isSensitive" : false,
"description" : "Activates the web interface to be reached by browsing to x.x.x.x:webInterfacePort, e.g. 192.168.1.2:5000",
"category" : "system"
"category" : "interface",
"onUpdate" : "WebUIManager.restart"
},
"webInterfacePort" : {
"defaultValue": 5000,
"dataType" : "integer",
"isSensitive" : false,
"description" : "Change the web interface port to be used",
"category" : "system"
"category" : "interface",
"onUpdate" : "WebUIManager.restart"
},
"apiPort" : {
"defaultValue": 5001,
"dataType" : "integer",
"isSensitive" : false,
"description" : "Change the port the api is bound to",
"category" : "interface",
"onUpdate" : "ApiManager.restart"
},
"scenariosActive" : {
"defaultValue": false,
"dataType" : "boolean",
"isSensitive" : false,
"description" : "Activates the scenarios support on the webinterface, using Node-RED.",
"category" : "scenarios",
"category" : "interface",
"onUpdate" : "NodeRedManager.toggle"
},
"dontStopNodeRed" : {
"defaultValue": false,
"dataType" : "boolean",
"isSensitive" : false,
"description" : "If activated, Node-RED won't be stopped when Alice is shut down.",
"category" : "scenarios",
"category" : "interface",
"parent" : {
"config" : "scenariosActive",
"condition": "is",
Expand Down
6 changes: 4 additions & 2 deletions core/Initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,11 @@ def initProjectAlice(self) -> bool: # NOSONAR
break

if not audioHardware:
confs['disableSoundAndMic'] = True
confs['disableSound'] = True
confs['disableCapture'] = True
else:
confs['disableSoundAndMic'] = False
confs['disableSound'] = False
confs['disableCapture'] = False

hlcServiceFilePath = Path('/etc/systemd/system/hermesledcontrol.service')
if initConfs['useHLC']:
Expand Down
14 changes: 14 additions & 0 deletions core/ProjectAlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests

from core.base.SuperManager import SuperManager
from core.base.model.StateType import StateType
from core.base.model.Version import Version
from core.commons import constants
from core.commons.model.Singleton import Singleton
Expand Down Expand Up @@ -93,10 +94,21 @@ def wipeAll(self):

def updateProjectAlice(self):
self._logger.logInfo('Checking for core updates')
STATE = 'projectalice.core.updating'
state = self._superManager.stateManager.getState(STATE)
if not state:
self._superManager.stateManager.register(STATE, initialState=StateType.RUNNING)
elif state.currentState == StateType.RUNNING:
self._logger.logInfo('Update cancelled, already running')
return

self._superManager.stateManager.setState(STATE, newState=StateType.RUNNING)

self._isUpdating = True
req = requests.get(url=f'{constants.GITHUB_API_URL}/ProjectAlice/branches', auth=SuperManager.getInstance().configManager.getGithubAuth())
if req.status_code != 200:
self._logger.logWarning('Failed checking for updates')
self._superManager.stateManager.setState(STATE, newState=StateType.ERROR)
return

userUpdatePref = SuperManager.getInstance().configManager.getAliceConfigByName('aliceUpdateChannel')
Expand Down Expand Up @@ -132,6 +144,8 @@ def updateProjectAlice(self):
# Remove install tickets
[file.unlink() for file in Path(commons.rootDir(), 'system/skillInstallTickets').glob('*') if file.is_file()]

self._superManager.stateManager.setState(STATE, newState=StateType.FINISHED)

if currentHash != newHash:
self._logger.logWarning('New Alice version installed, need to restart...')
self.doRestart()
Expand Down
7 changes: 7 additions & 0 deletions core/ProjectAliceExceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,10 @@ def __init__(self, message: str = None):
super().__init__(message)
self._logger.logWarning(f'A vital configuration --{message}-- is missing. Make sure the following configurations are set: {" / ".join(SuperManager.getInstance().configManager.vitalConfigs)}')
SuperManager.getInstance().projectAlice.onStop()


class StateAlreadyRegistered(ProjectAliceException):

def __init__(self, message: str = None):
super().__init__()
self._logger.logWarning(message)
4 changes: 2 additions & 2 deletions core/asr/ASRManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ def decodeStream(self, session: DialogSession):
text = self._translator.translate(text=text, src=language, dest='en').text
self.logDebug(f'Asr translated to: {text}')

self.MqttManager.publish(topic=constants.TOPIC_TEXT_CAPTURED, payload={'sessionId': session.sessionId, 'text': text, 'siteId': session.siteId, 'likelihood': result.likelihood, 'seconds': result.processingTime})
self.MqttManager.publish(topic=constants.TOPIC_TEXT_CAPTURED, payload={'sessionId': session.sessionId, 'text': text, 'device': session.siteId, 'likelihood': result.likelihood, 'seconds': result.processingTime})
else:
self.MqttManager.playSound(
soundFilename='error',
location=Path(f'system/sounds/{self.LanguageManager.activeLanguage}'),
siteId=session.siteId,
device=session.siteId,
sessionId=session.sessionId
)

Expand Down
15 changes: 15 additions & 0 deletions core/base/AssistantManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from typing import Dict, Generator

from core.base.model.Manager import Manager
from core.base.model.StateType import StateType


class AssistantManager(Manager):
STATE = 'projectalice.core.training'

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -35,6 +37,10 @@ def checkAssistant(self, forceRetrain: bool = False):
if forceRetrain:
self.logInfo('Forced assistant training')
self.train()
self.DialogTemplateManager.clearCache(rebuild=False)
self.DialogTemplateManager.train()
self.NluManager.clearCache()
self.NluManager.train()
elif not self._assistantPath.exists():
self.logInfo('Assistant not found')
self.train()
Expand Down Expand Up @@ -120,6 +126,15 @@ def checkConsistency(self) -> bool:
def train(self):
self.logInfo('Training assistant')

state = self.StateManager.getState(self.STATE)
if not state:
self.StateManager.register(self.STATE, initialState=StateType.RUNNING)
elif state.currentState == StateType.RUNNING:
self._logger.logInfo('Training cancelled, already running')
return

self.StateManager.setState(self.STATE, newState=StateType.RUNNING)

try:
assistant = self.newAssistant()
intents = dict()
Expand Down
31 changes: 20 additions & 11 deletions core/base/ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ def updateSkillConfigurationFile(self, skillName: str, key: str, value: typing.A
# Cast value to template defined type
vartype = self._skillsTemplateConfigurations[skillName][key]['dataType']
if vartype == 'boolean':
if value.lower() in {'on', 'yes', 'true', 'active'}:
value = True
elif value.lower() in {'off', 'no', 'false', 'inactive'}:
value = False
if not isinstance(value, bool):
if value.lower() in {'on', 'yes', 'true', 'active'}:
value = True
elif value.lower() in {'off', 'no', 'false', 'inactive'}:
value = False
elif vartype == 'integer':
try:
value = int(value)
Expand Down Expand Up @@ -542,8 +543,11 @@ def getAliceConfigType(self, confName: str) -> typing.Optional[str]:


def isAliceConfHidden(self, confName: str) -> bool:
return confName in self._aliceTemplateConfigurations and \
self._aliceTemplateConfigurations.get('display') == 'hidden'
return self._aliceTemplateConfigurations.get(confName, dict()).get('display', '') == 'hidden'


def isAliceConfSensitive(self, confName: str) -> bool:
return self._aliceTemplateConfigurations.get(confName, dict()).get('isSensitive', False)


def getAliceConfUpdatePreProcessing(self, confName: str) -> typing.Optional[str]:
Expand Down Expand Up @@ -653,14 +657,19 @@ def updateAdminPinCode(self):


def enableDisableSound(self):
if self.getAliceConfigByName('disableSoundAndMic'):
self.WakewordManager.disableEngine()
if self.getAliceConfigByName('disableSound'):
self.AudioServer.onStop()
else:
self.WakewordManager.enableEngine()
self.AudioServer.onStart()


def enableDisableCapture(self):
if self.getAliceConfigByName('disableCapture'):
self.WakewordManager.disableEngine()
else:
self.WakewordManager.enableEngine()


def restartWakewordEngine(self):
self.WakewordManager.restartEngine()

Expand Down Expand Up @@ -706,7 +715,7 @@ def populateAudioInputConfig(self):
devices = self._listAudioDevices()
self.updateAliceConfigDefinitionValues(setting='inputDevice', value=devices)
except:
if not self.getAliceConfigByName('disableSoundAndMic'):
if not self.getAliceConfigByName('disableCapture'):
self.logWarning('No audio input device found')


Expand All @@ -715,7 +724,7 @@ def populateAudioOutputConfig(self):
devices = self._listAudioDevices()
self.updateAliceConfigDefinitionValues(setting='outputDevice', value=devices)
except:
if not self.getAliceConfigByName('disableSoundAndMic'):
if not self.getAliceConfigByName('disableSound'):
self.logWarning('No audio output device found')


Expand Down
Loading

0 comments on commit ac1b51e

Please sign in to comment.