Skip to content

Commit ac1b51e

Browse files
Merge pull request #347 from project-alice-assistant/new-interface
New interface #307
2 parents 5f6a15a + 900344d commit ac1b51e

File tree

504 files changed

+26360
-48352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

504 files changed

+26360
-48352
lines changed

ProjectAlice.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ version: 1.22
1717
################################################
1818

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

2222
# If you place this file into /boot after a first initialization it won't overwrite your settings unless you set this to yes
2323
forceRewrite: no

configTemplate.json

+33-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"beforeUpdate": "injectAsound",
3838
"category" : "audio",
3939
"parent" : {
40-
"config" : "disableSoundAndMic",
40+
"config" : "disableSound",
4141
"condition": "isnot",
4242
"value" : true
4343
}
@@ -59,7 +59,7 @@
5959
"onInit" : "populateAudioOutputConfig",
6060
"onUpdate" : "AudioServer.updateAudioDevices",
6161
"parent" : {
62-
"config" : "disableSoundAndMic",
62+
"config" : "disableSound",
6363
"condition": "isnot",
6464
"value" : true
6565
}
@@ -74,7 +74,7 @@
7474
"onInit" : "populateAudioInputConfig",
7575
"onUpdate" : "AudioServer.updateAudioDevices",
7676
"parent" : {
77-
"config" : "disableSoundAndMic",
77+
"config" : "disableCapture",
7878
"condition": "isnot",
7979
"value" : true
8080
}
@@ -138,14 +138,22 @@
138138
"value" : false
139139
}
140140
},
141-
"disableSoundAndMic" : {
141+
"disableSound" : {
142142
"defaultValue": false,
143143
"dataType" : "boolean",
144144
"isSensitive" : false,
145-
"description" : "If this device is a server without sound and mic, turn this to true",
145+
"description" : "Disable sound playback",
146146
"onUpdate" : "enableDisableSound",
147147
"category" : "audio"
148148
},
149+
"disableCapture" : {
150+
"defaultValue": false,
151+
"dataType" : "boolean",
152+
"isSensitive" : false,
153+
"description" : "Disable sound capture",
154+
"onUpdate" : "enableDisableCapture",
155+
"category" : "audio"
156+
},
149157
"notUnderstoodRetries" : {
150158
"defaultValue": 3,
151159
"dataType" : "integer",
@@ -300,7 +308,12 @@
300308
"dataType" : "boolean",
301309
"isSensitive" : false,
302310
"description" : "Only available with Amazon Polly",
303-
"category" : "tts"
311+
"category" : "tts",
312+
"parent" : {
313+
"config" : "tts",
314+
"condition": "is",
315+
"value" : "amazon"
316+
}
304317
},
305318
"newDeviceBroadcastPort" : {
306319
"defaultValue": 12354,
@@ -745,29 +758,39 @@
745758
"dataType" : "boolean",
746759
"isSensitive" : false,
747760
"description" : "Activates the web interface to be reached by browsing to x.x.x.x:webInterfacePort, e.g. 192.168.1.2:5000",
748-
"category" : "system"
761+
"category" : "interface",
762+
"onUpdate" : "WebUIManager.restart"
749763
},
750764
"webInterfacePort" : {
751765
"defaultValue": 5000,
752766
"dataType" : "integer",
753767
"isSensitive" : false,
754768
"description" : "Change the web interface port to be used",
755-
"category" : "system"
769+
"category" : "interface",
770+
"onUpdate" : "WebUIManager.restart"
771+
},
772+
"apiPort" : {
773+
"defaultValue": 5001,
774+
"dataType" : "integer",
775+
"isSensitive" : false,
776+
"description" : "Change the port the api is bound to",
777+
"category" : "interface",
778+
"onUpdate" : "ApiManager.restart"
756779
},
757780
"scenariosActive" : {
758781
"defaultValue": false,
759782
"dataType" : "boolean",
760783
"isSensitive" : false,
761784
"description" : "Activates the scenarios support on the webinterface, using Node-RED.",
762-
"category" : "scenarios",
785+
"category" : "interface",
763786
"onUpdate" : "NodeRedManager.toggle"
764787
},
765788
"dontStopNodeRed" : {
766789
"defaultValue": false,
767790
"dataType" : "boolean",
768791
"isSensitive" : false,
769792
"description" : "If activated, Node-RED won't be stopped when Alice is shut down.",
770-
"category" : "scenarios",
793+
"category" : "interface",
771794
"parent" : {
772795
"config" : "scenariosActive",
773796
"condition": "is",

core/Initializer.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,11 @@ def initProjectAlice(self) -> bool: # NOSONAR
538538
break
539539

540540
if not audioHardware:
541-
confs['disableSoundAndMic'] = True
541+
confs['disableSound'] = True
542+
confs['disableCapture'] = True
542543
else:
543-
confs['disableSoundAndMic'] = False
544+
confs['disableSound'] = False
545+
confs['disableCapture'] = False
544546

545547
hlcServiceFilePath = Path('/etc/systemd/system/hermesledcontrol.service')
546548
if initConfs['useHLC']:

core/ProjectAlice.py

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55

66
from core.base.SuperManager import SuperManager
7+
from core.base.model.StateType import StateType
78
from core.base.model.Version import Version
89
from core.commons import constants
910
from core.commons.model.Singleton import Singleton
@@ -93,10 +94,21 @@ def wipeAll(self):
9394

9495
def updateProjectAlice(self):
9596
self._logger.logInfo('Checking for core updates')
97+
STATE = 'projectalice.core.updating'
98+
state = self._superManager.stateManager.getState(STATE)
99+
if not state:
100+
self._superManager.stateManager.register(STATE, initialState=StateType.RUNNING)
101+
elif state.currentState == StateType.RUNNING:
102+
self._logger.logInfo('Update cancelled, already running')
103+
return
104+
105+
self._superManager.stateManager.setState(STATE, newState=StateType.RUNNING)
106+
96107
self._isUpdating = True
97108
req = requests.get(url=f'{constants.GITHUB_API_URL}/ProjectAlice/branches', auth=SuperManager.getInstance().configManager.getGithubAuth())
98109
if req.status_code != 200:
99110
self._logger.logWarning('Failed checking for updates')
111+
self._superManager.stateManager.setState(STATE, newState=StateType.ERROR)
100112
return
101113

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

147+
self._superManager.stateManager.setState(STATE, newState=StateType.FINISHED)
148+
135149
if currentHash != newHash:
136150
self._logger.logWarning('New Alice version installed, need to restart...')
137151
self.doRestart()

core/ProjectAliceExceptions.py

+7
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,10 @@ def __init__(self, message: str = None):
147147
super().__init__(message)
148148
self._logger.logWarning(f'A vital configuration --{message}-- is missing. Make sure the following configurations are set: {" / ".join(SuperManager.getInstance().configManager.vitalConfigs)}')
149149
SuperManager.getInstance().projectAlice.onStop()
150+
151+
152+
class StateAlreadyRegistered(ProjectAliceException):
153+
154+
def __init__(self, message: str = None):
155+
super().__init__()
156+
self._logger.logWarning(message)

core/asr/ASRManager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ def decodeStream(self, session: DialogSession):
148148
text = self._translator.translate(text=text, src=language, dest='en').text
149149
self.logDebug(f'Asr translated to: {text}')
150150

151-
self.MqttManager.publish(topic=constants.TOPIC_TEXT_CAPTURED, payload={'sessionId': session.sessionId, 'text': text, 'siteId': session.siteId, 'likelihood': result.likelihood, 'seconds': result.processingTime})
151+
self.MqttManager.publish(topic=constants.TOPIC_TEXT_CAPTURED, payload={'sessionId': session.sessionId, 'text': text, 'device': session.siteId, 'likelihood': result.likelihood, 'seconds': result.processingTime})
152152
else:
153153
self.MqttManager.playSound(
154154
soundFilename='error',
155155
location=Path(f'system/sounds/{self.LanguageManager.activeLanguage}'),
156-
siteId=session.siteId,
156+
device=session.siteId,
157157
sessionId=session.sessionId
158158
)
159159

core/base/AssistantManager.py

+15
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from typing import Dict, Generator
66

77
from core.base.model.Manager import Manager
8+
from core.base.model.StateType import StateType
89

910

1011
class AssistantManager(Manager):
12+
STATE = 'projectalice.core.training'
1113

1214
def __init__(self):
1315
super().__init__()
@@ -35,6 +37,10 @@ def checkAssistant(self, forceRetrain: bool = False):
3537
if forceRetrain:
3638
self.logInfo('Forced assistant training')
3739
self.train()
40+
self.DialogTemplateManager.clearCache(rebuild=False)
41+
self.DialogTemplateManager.train()
42+
self.NluManager.clearCache()
43+
self.NluManager.train()
3844
elif not self._assistantPath.exists():
3945
self.logInfo('Assistant not found')
4046
self.train()
@@ -120,6 +126,15 @@ def checkConsistency(self) -> bool:
120126
def train(self):
121127
self.logInfo('Training assistant')
122128

129+
state = self.StateManager.getState(self.STATE)
130+
if not state:
131+
self.StateManager.register(self.STATE, initialState=StateType.RUNNING)
132+
elif state.currentState == StateType.RUNNING:
133+
self._logger.logInfo('Training cancelled, already running')
134+
return
135+
136+
self.StateManager.setState(self.STATE, newState=StateType.RUNNING)
137+
123138
try:
124139
assistant = self.newAssistant()
125140
intents = dict()

core/base/ConfigManager.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ def updateSkillConfigurationFile(self, skillName: str, key: str, value: typing.A
251251
# Cast value to template defined type
252252
vartype = self._skillsTemplateConfigurations[skillName][key]['dataType']
253253
if vartype == 'boolean':
254-
if value.lower() in {'on', 'yes', 'true', 'active'}:
255-
value = True
256-
elif value.lower() in {'off', 'no', 'false', 'inactive'}:
257-
value = False
254+
if not isinstance(value, bool):
255+
if value.lower() in {'on', 'yes', 'true', 'active'}:
256+
value = True
257+
elif value.lower() in {'off', 'no', 'false', 'inactive'}:
258+
value = False
258259
elif vartype == 'integer':
259260
try:
260261
value = int(value)
@@ -542,8 +543,11 @@ def getAliceConfigType(self, confName: str) -> typing.Optional[str]:
542543

543544

544545
def isAliceConfHidden(self, confName: str) -> bool:
545-
return confName in self._aliceTemplateConfigurations and \
546-
self._aliceTemplateConfigurations.get('display') == 'hidden'
546+
return self._aliceTemplateConfigurations.get(confName, dict()).get('display', '') == 'hidden'
547+
548+
549+
def isAliceConfSensitive(self, confName: str) -> bool:
550+
return self._aliceTemplateConfigurations.get(confName, dict()).get('isSensitive', False)
547551

548552

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

654658

655659
def enableDisableSound(self):
656-
if self.getAliceConfigByName('disableSoundAndMic'):
657-
self.WakewordManager.disableEngine()
660+
if self.getAliceConfigByName('disableSound'):
658661
self.AudioServer.onStop()
659662
else:
660-
self.WakewordManager.enableEngine()
661663
self.AudioServer.onStart()
662664

663665

666+
def enableDisableCapture(self):
667+
if self.getAliceConfigByName('disableCapture'):
668+
self.WakewordManager.disableEngine()
669+
else:
670+
self.WakewordManager.enableEngine()
671+
672+
664673
def restartWakewordEngine(self):
665674
self.WakewordManager.restartEngine()
666675

@@ -706,7 +715,7 @@ def populateAudioInputConfig(self):
706715
devices = self._listAudioDevices()
707716
self.updateAliceConfigDefinitionValues(setting='inputDevice', value=devices)
708717
except:
709-
if not self.getAliceConfigByName('disableSoundAndMic'):
718+
if not self.getAliceConfigByName('disableCapture'):
710719
self.logWarning('No audio input device found')
711720

712721

@@ -715,7 +724,7 @@ def populateAudioOutputConfig(self):
715724
devices = self._listAudioDevices()
716725
self.updateAliceConfigDefinitionValues(setting='outputDevice', value=devices)
717726
except:
718-
if not self.getAliceConfigByName('disableSoundAndMic'):
727+
if not self.getAliceConfigByName('disableSound'):
719728
self.logWarning('No audio output device found')
720729

721730

0 commit comments

Comments
 (0)