Skip to content

Commit 723c687

Browse files
committed
improved 'notify' action and TTS one-time-language
1 parent c40cf07 commit 723c687

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

www/scripts/sepiaFW.local.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ function sepiaFW_build_strings(){
119119
StringsDE.clearHistory = 'Verlauf löschen';
120120
StringsDE.history = 'Verlauf';
121121
StringsDE.newMessages = 'Neue Nachrichten';
122+
StringsDE.message = 'Nachricht';
123+
StringsDE.notification = 'Benachrichtigung';
122124
StringsDE.reload = 'Neu laden';
123125
StringsDE.newWindow = 'Neues Fenster';
124126
StringsDE.mySepiaClients = 'My Clients';
@@ -168,7 +170,8 @@ function sepiaFW_build_strings(){
168170
StringsDE.opening_link = "Link wird geöffnet.";
169171
StringsDE.no_music_playing = "Kannst du was hören? Wahrscheinlich wurde keine Musik gefunden.";
170172
StringsDE.remote_action = "Remote-Zugriff";
171-
StringsDE.remote_action_audio_stream = "Habe einen Audio Stream via Remote-Zugriff empfangen. Stream wird gestartet.";
173+
StringsDE.remote_action_audio_stream = "ich habe einen Audio Stream via Remote-Zugriff empfangen. Stream wird gestartet.";
174+
StringsDE.remote_action_notify = "ich habe eine Benachrichtigung für dich.";
172175
StringsDE.read_article = "Artikel lesen";
173176
StringsDE.choose_device_for_music = "Wähle ein Gerät auf dem du die Musik abspielen willst";
174177
StringsDE.choose_device_for_action = "Auf welchem Gerät soll die Aktion ausgeführt werden?";
@@ -327,6 +330,8 @@ function sepiaFW_build_strings(){
327330
StringsEN.clearHistory = 'Clear history';
328331
StringsEN.history = 'History';
329332
StringsEN.newMessages = "New messages";
333+
StringsEN.message = 'Message';
334+
StringsEN.notification = 'Notification';
330335
StringsEN.reload = 'Reload';
331336
StringsEN.newWindow = 'New window';
332337
StringsEN.mySepiaClients = 'Meine Clients';
@@ -377,6 +382,7 @@ function sepiaFW_build_strings(){
377382
StringsEN.no_music_playing = "Can you hear something? Probably no music found.";
378383
StringsEN.remote_action = "Remote access";
379384
StringsEN.remote_action_audio_stream = "I've received an audio stream via remote access. Starting now.";
385+
StringsEN.remote_action_notify = "I have a message for you.";
380386
StringsEN.read_article = "Read article";
381387
StringsEN.choose_device_for_music = "Choose a device to play your music on";
382388
StringsEN.choose_device_for_action = "On which device should the action be executed?";
@@ -427,17 +433,19 @@ function sepiaFW_build_strings(){
427433
var StringsLocale = {};
428434

429435
//get string
430-
StringsLocale.g = function(name){
431-
if (SepiaFW.config.appLanguage.toLowerCase() === "de"){
436+
StringsLocale.g = function(name, lang){
437+
var langCode = (lang || SepiaFW.config.appLanguage).toLowerCase();
438+
if (langCode == "de"){
432439
return StringsDE[name];
433440
}else{
434441
return StringsEN[name];
435442
}
436443
}
437444

438445
//write string
439-
StringsLocale.w = function(name){
440-
if (SepiaFW.config.appLanguage.toLowerCase() === "de"){
446+
StringsLocale.w = function(name, lang){
447+
var langCode = (lang || SepiaFW.config.appLanguage).toLowerCase();
448+
if (langCode == "de"){
441449
document.write(StringsDE[name]);
442450
}else{
443451
document.write(StringsEN[name]);

www/scripts/sepiaFW.speechSynthesis.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function sepiaFW_build_speech_synthesis(Speech, sepiaSessionId){
285285
//set a voice
286286
Speech.setVoice = function(newVoice){
287287
//console.error("TRACE SET VOICE - v: " + newVoice); //DEBUG
288-
if (!voices || !voices.length || !voices.filter(function(v){ return v.name = newVoice; })){
288+
if (!voices || !voices.length || !voices.filter(function(v){ return v.name == newVoice; })){
289289
//console.error("VOICE NOT FOUND, setting empty"); //DEBUG
290290
newVoice = "";
291291
}
@@ -774,13 +774,20 @@ function sepiaFW_build_speech_synthesis(Speech, sepiaSessionId){
774774

775775
//get audio URL
776776
Speech.sepiaTTS.getURL = function(message, successCallback, errorCallback, options){
777-
//TODO: implement 'options.oneTimeVoice' and 'options.oneTimeLanguage'
777+
if (!options) options = {};
778+
var lang = Speech.getLanguage();
779+
var voice = Speech.sepiaTTS.settings.voice;
780+
//use 'options.oneTimeVoice' and 'options.oneTimeLanguage'?
781+
if (options.oneTimeVoice && options.oneTimeVoice.name){
782+
voice = options.oneTimeVoice.name;
783+
lang = options.oneTimeLanguage;
784+
}
778785
var apiUrl = SepiaFW.config.assistAPI + "tts";
779786
var submitData = {
780787
text: message,
781-
lang: Speech.getLanguage(),
788+
lang: lang,
782789
mood: ((SepiaFW.assistant)? SepiaFW.assistant.getMood() : Speech.sepiaTTS.settings.mood),
783-
voice: Speech.sepiaTTS.settings.voice,
790+
voice: voice,
784791
gender: Speech.sepiaTTS.settings.gender,
785792
speed: Speech.sepiaTTS.settings.speed,
786793
tone: Speech.sepiaTTS.settings.tone,
@@ -883,7 +890,7 @@ function sepiaFW_build_speech_synthesis(Speech, sepiaSessionId){
883890
}
884891

885892
Speech.maryTTS.getURL = function(message, successCallback, errorCallback, options){
886-
//TODO: implement 'options.oneTimeVoice' and 'options.oneTimeLanguage'
893+
if (!options) options = {};
887894
if (!Speech.voiceCustomServer){
888895
var err = {name: "MissingServerInfo", message: "Custom Mary-TTS API is missing server URL."};
889896
SepiaFW.debug.error("Speech.maryTTS - getURL ERROR: " + JSON.stringify(err));
@@ -915,11 +922,18 @@ function sepiaFW_build_speech_synthesis(Speech, sepiaSessionId){
915922
}
916923
}
917924
//console.error("Speech.maryTTS.settings.voice", Speech.maryTTS.settings.voice); //DEBUG
918-
var voiceInfo = Speech.maryTTS.settings.voice.split(/\s+/g); //example: "dfki-spike-hsmm en_GB male hmm"
925+
var voiceName;
926+
//use 'options.oneTimeVoice' and 'options.oneTimeLanguage'?
927+
if (options.oneTimeVoice && options.oneTimeVoice.name){
928+
voiceName = options.oneTimeVoice.name;
929+
}else{
930+
voiceName = Speech.maryTTS.settings.voice;
931+
}
932+
var voiceInfo = voiceName.split(/\s+/g); //example: "dfki-spike-hsmm en_GB male hmm"
919933
var apiUrl = Speech.voiceCustomServer.replace(/\/$/, "") + "/process"
920934
+ "?INPUT_TYPE=TEXT" + "&OUTPUT_TYPE=AUDIO" + "&AUDIO=WAVE_FILE"
921935
+ "&LOCALE=" + encodeURIComponent(voiceInfo[1])
922-
+ "&VOICE=" + encodeURIComponent(voiceInfo[0]) //Larynx special: + ";hifi_gan:vctk_small"
936+
+ "&VOICE=" + encodeURIComponent(voiceInfo[0]) //TODO: Larynx special: + ";hifi_gan:vctk_small"
923937
+ "&INPUT_TEXT=" + encodeURIComponent(message)
924938
;
925939
SepiaFW.debug.info("Speech.maryTTS - getURL SUCCESS: " + apiUrl);
@@ -958,7 +972,7 @@ function sepiaFW_build_speech_synthesis(Speech, sepiaSessionId){
958972
voicesArray.push({
959973
//default webSpeech voice format:
960974
default: true,
961-
lang: vInfo[1],
975+
lang: vInfo[1].replace(/[_]/g, "-"), //make sure this has correct format xx-XX
962976
localService: false,
963977
name: vString,
964978
voiceURI: vString

www/scripts/sepiaFW.webSocket.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,9 +2314,29 @@ function sepiaFW_build_webSocket_client(sepiaSessionId){
23142314
//handle
23152315
if (action.type == "assistant_message"){
23162316
if (action.text){
2317+
if (!action.language) action.language = SepiaFW.speech.getLanguage();
2318+
action.text = action.text.replace(/\.$/, "") + "."; //make sure we end with "." (important for some TTS)
2319+
var orgMsg = action.text;
2320+
if (!action.skipIntro){
2321+
action.text = SepiaFW.account.getUserName() + ", "
2322+
+ SepiaFW.local.g('remote_action_notify', action.language).trim() + " "
2323+
+ action.text;
2324+
}
2325+
var actionFun = function(){
2326+
SepiaFW.ui.showCustomChatMessage(orgMsg, {
2327+
sender: SepiaFW.local.g("notification"), //SepiaFW.assistant.name,
2328+
//senderType: 'assistant',
2329+
channelId: 'info'
2330+
});
2331+
}
23172332
SepiaFW.assistant.waitForOpportunitySayLocalTextAndRunAction(
23182333
//localizedText, actionFun, fallbackAction, maxWait, speakOptions:
2319-
action.text, function(){}, undefined, 10000, {oneTimeLanguage: action.language}
2334+
action.text, function(){
2335+
actionFun();
2336+
}, function(){
2337+
SepiaFW.ui.showInfo(SepiaFW.local.g("notification"), false);
2338+
actionFun();
2339+
}, 15000, {oneTimeLanguage: action.language}
23202340
);
23212341
//use instead? SepiaFW.events.setProActiveBackgroundNotification(action)
23222342
//TODO: add intro text? add notification? add something in the chat!

0 commit comments

Comments
 (0)