MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Sentences not loaded in hello-Lucy

    Scheduled Pinned Locked Moved Troubleshooting
    19 Posts 2 Posters 2.8k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N Offline
      Nicodil @sdetweil
      last edited by Nicodil

      @sdetweil Thanks! With your FIX i can now use this line again:

      Module.register(ModuleName, {
      

      So the ModuleName seems to be found again, BUT
      if i dont initialize var importedSentences=“”; in the 2nd line,
      i get the following error:
      15e1fe94-4878-436b-b7ae-f9530abef747-image.png

      It seems like sentences are still not loaded…

      S 1 Reply Last reply Reply Quote 0
      • S Do not disturb
        sdetweil @Nicodil
        last edited by sdetweil

        @nicodil I JUST tested and it worked…

        in the sources view
        find the module and source file (left nav) and put a stop (click the number on the left edge of the line) on line 27

        then hit f5, refesh page

        hover over the variable and expand the array
        Screenshot at 2021-04-13 09-54-11.png

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        N 1 Reply Last reply Reply Quote 0
        • N Offline
          Nicodil @sdetweil
          last edited by

          @sdetweil Thanks for your help! Here are my errors:

          1fc01a8f-ea05-48d7-a266-c508d314cf95-image.png

          S 1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil @Nicodil
            last edited by

            @nicodil so it seems u did NOT replace the line as per my instructions

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            N 1 Reply Last reply Reply Quote 0
            • N Offline
              Nicodil @sdetweil
              last edited by

              @sdetweil said in Sentences not loaded in hello-Lucy:

              u did NOT replace the line as per my instructions

              But i did, see my code here:

              "use strict";
              
              var importedSentences;                              /** Prepare variable to be populated from import. */
              function readTextFile(file, callback) {
              	var rawFile = new XMLHttpRequest();
              	rawFile.overrideMimeType("application/json");
              	rawFile.open("GET", file, true);
              	rawFile.onreadystatechange = function() {
              		if (rawFile.readyState === 4 && rawFile.status == "200") {
              			callback(rawFile.responseText);
              		}
              	};
              	rawFile.send(null);
              }
              const sfn= document.currentScript.src.substring(7,document.currentScript.src.lastIndexOf(document.currentScript.src.slice(7).includes('//')?'//':'/'))
              const localPath= sfn.substring(sfn.indexOf('modules'))
              const ModuleName=localPath.substring(localPath.lastIndexOf("/")+1)
              //console.log("localPath="+localPath+" modulename="+ModuleName);
              
              readTextFile(localPath+"/sentences.json", function(text){
              	var tempImport = JSON.parse(text);
              	importedSentences = tempImport;
              	 console.log("SENTENCE: "+importedSentences);
              });
              
              ////////////////////////////////////////////////////
              
              Module.register(ModuleName, {
              
              	icon: "fa-microphone-slash",
              	pulsing: true,
              	help: false,
              	timeout: null,
              	lucy: {
              		mode: "Sprich 'Hello Lucy'",
              		sentences: []
              	},
              
              	modules: [],
              	previouslyHidden: [],
              
              	defaults: {
              		timeout: 15,                                // time listening for a command/sentence when mic pulsing
              		defaultOnStartup: "Hello-Lucy",
              		keyword: "HELLO LUCY",                      // keyword to activate listening for a command/sentence
              		standByMethod: "DPMS",                      // 'DPMS' = anything else than RPi or 'PI'
              		sounds: ["a.mp3",  "b.mp3",  "c.mp3" , "d.mp3"], // welcome sounds at startup randomly chosen
              		startHideAll: false,                        // if true, all modules start as hidden
              		microphone: "default",                      // 
              		speed: 1000,                                // transition speed between show/no-show/show in milliseconds
              	    	pageOneModules: ["Hello-Lucy"],         // default modules to show on page one/startup
              		    pageTwoModules: [],                         // modules to show on page two
                  		pageThreeModules: [],                       // modules to show on page two
                  		pageFourModules: [],                        // modules to show on page two
                  		pageFiveModules: [],                        // modules to show on page two
                  		pageSixModules: [],                         // modules to show on page two
                  		pageSevenModules: [],                       // modules to show on page two
                  		pageEightModules: [],                       // modules to show on page two
                  		pageNineModules: [],                        // modules to show on page two
                  		pageTenModules: [],                         // modules to show on page two
              		    greetingSounds: [ "a.mp3",  "b.mp3",  "c.mp3" , "d.mp3"], // randomized greeting sounds
              				confirmationSound: "ding.mp3",               // when command is accepted. use your own or default
              				debug: true,                               // get debug information in console
              	},
              
              	poweredOff: false,
              
              	start() {
              		var combinedSentences = importedSentences.concat(this.lucy.sentences);
              		this.lucy.sentences = combinedSentences;
              		//Log.info(`Starting module: ${this.name}`);
              		this.mode = this.translate("INIT");
              		this.modules.push(this.lucy);
              		//Log.info(`${this.name} is waiting for lucy command registrations.`);
              	},
              
              	getStyles() {
              		return ["font-awesome.css", "Hello-Lucy.css"];
              	},
              
              	getTranslations() {
              		return {
              			en: "translations/en.json",
              			de: "translations/de.json",
              			id: "translations/id.json"
              		};
              	},
              
                // audible confirmation sound that Lucy understood the command
              	playConfirmationSound() {
              		var audio = new Audio(localPath+"/sounds/" + this.config.confirmationSound);
              		audio.play();
              	},
              
                // randomized greeting sounds
              	playGreetingSound() {
              		var random_file = this.config.sounds[Math.floor(Math.random() * this.config.sounds.length)];
              		var audio = new Audio(localPath+"/sounds/"+random_file);
              		audio.play();
              	},
              
              	getDom() {
              		//Log.log("lucy entered getDom")
              		const wrapper = document.createElement("div");
              		const lucy = document.createElement("div");
              		lucy.classList.add("small", "align-left");
              
              		const modeSpan = document.createElement("span");
              		const icon = document.createElement("i");
              		icon.classList.add("fa", this.icon, "icon");
              		if (this.pulsing) {
              			icon.classList.add("pulse");
              			modeSpan.innerHTML = "Command Please:"
              		}
              		else
              			modeSpan.innerHTML = this.mode;
              		lucy.appendChild(icon);
              		lucy.appendChild(modeSpan);
              
              		if (this.config.debug) {
              			const debug = document.createElement("div");
              			debug.innerHTML = this.debugInformation;
              			lucy.appendChild(debug);
              		}
              
              		const modules = document.querySelectorAll(".module");
              		for (let i = 0; i < modules.length; i += 1) {
              			if (!modules[i].classList.contains(this.name)) {
              				if (this.help) {
              					modules[i].classList.add(`${this.name}-blur`);
              				} else {
              					modules[i].classList.remove(`${this.name}-blur`);
              				}
              			}
              		}
              
              		if (this.help) {
              			lucy.classList.add(`${this.name}-blur`);
              			const modal = document.createElement("div");
              			modal.classList.add("modal");
              			this.appendHelp(modal);
              			wrapper.appendChild(modal);
              		}
              
              		wrapper.appendChild(lucy);
              
              		return wrapper;
              	},
              
              	notificationReceived(notification, payload, sender) {
              		//Log.log("lucy module notification received="+notification)
              		var self=this;
              		if (notification === "DOM_OBJECTS_CREATED") {
              			//Log.log("lucy module sending start")
              			this.sendSocketNotification("START", { config: this.config, modules: this.modules });
              		} else if (notification === "REGISTER_LUCY_MODULE") {
              			if (Object.prototype.hasOwnProperty.call(payload, "mode") && Object.prototype.hasOwnProperty.call(payload, "sentences")) {
              				this.modules.push(payload);
              		}
              		}
                     // randomly chosen startup greeting
              		if (notification === "DOM_OBJECTS_CREATED") {
              			this.playGreetingSound();
              		}
              
              		// @TheStigh to manage hide/show modules on startup
              		if (this.config.startHideAll) {
              			if (notification === "DOM_OBJECTS_CREATED") {
              				MM.getModules().enumerate((module) => {
              					module.hide(1000);
              				});
              			}
              		}
              
              		if (notification === "DOM_OBJECTS_CREATED"){
              			var showOnStart = MM.getModules().withClass(self.config.pageOneModules);
              			showOnStart.enumerate(function(module) {
              				var callback = function(){};
              				module.show(self.config.speed, callback);
              			});
              		}
              
              		if (notification === "DOM_OBJECTS_CREATED"){
              			var showOnStart = MM.getModules().withClass(self.config.defaultOnStartup);
              			showOnStart.enumerate(function(module) {
              				var callback = function(){};
              				module.show(self.config.speed, callback);
              			});
              		}
              
              		// to show page one on alert @TheStigh
              		if (notification === "SHOW_ALERT") {
              			var showOnStart = MM.getModules().withClass(self.config.pageOneModules);
              			showOnStart.enumerate(function(module) {
              				var callback = function(){};
              				module.show(self.config.speed, callback);
              			});
              		}
               	},
              
              	socketNotificationReceived(notification, payload) {
              		if (notification === "READY") {
              			this.icon = "fa-microphone";
              			this.mode = this.translate("NO_MODE")+ "'Hello Lucy'";
              			this.pulsing = false;
              
              		} else if (notification === "LISTENING") {
              			this.pulsing = true;
              
              		} else if (notification === "SLEEPING") {
              			this.pulsing = false;
              
              		} else if (notification === "ERROR") {
              			this.mode = notification;
              
              		} else if (notification === "LUCY") {
              			for (let i = 0; i < this.modules.length; i += 1) {
              				if (payload.mode === this.modules[i].mode) {
              					if (this.mode !== payload.mode) {
              						this.help = false;
              						this.sendNotification(`${notification}_MODE_CHANGED`, { old: this.mode, new: payload.mode });
              						this.mode = payload.mode;
              					}
              					if (this.mode !== "LUCY") {
              						this.sendNotification(`${notification}_${payload.mode}`, payload.sentence);
              					}
              					break;
              				}
              			}
              
              		} else if (notification === "HIDE_MODULES") {
              			this.playConfirmationSound();
              
              			MM.getModules().enumerate((module) => {
              				module.hide(1000);
              			});
              
              		} else if (notification === "SHOW_MODULES") {
              			this.playConfirmationSound();
              
              			MM.getModules().enumerate((module) => {
              				module.show(1000);
              			});
              
              		} else if (notification === "DEBUG") {
              			this.debugInformation = payload;
              
              		} else if (notification === "MODULE_STATUS") {
              			this.playConfirmationSound();
              
              			var hide = MM.getModules().withClass(payload.hide);
              			hide.enumerate(function(module) {
              				//Log.log("Hide "+ module.name);
              				var callback = function(){};
              				module.hide(self.config.speed, callback);
              			});
              
              			var show = MM.getModules().withClass(payload.show);
              			show.enumerate(function(module) {
              				//Log.log("Show "+ module.name);
              				var callback = function(){};
              				module.show(self.config.speed, callback);
              			});
              
              		} else if (notification === "MODULE_UPDATE") {
              			this.sendNotification(payload);
              			//console.log("sendNoti received :"+payload);
              
              		} else if (notification === "CLOSE_HELP") {
              			this.help = false;
              		} else if (notification === "OPEN_HELP") {
              			this.help = true;
              		}
              		this.updateDom(300);
              	},
              
              	appendHelp(appendTo) {
              		const listLabel = document.createElement("div");
              		listLabel.classList.add("medium");
              		// heading for help screen
              		listLabel.innerHTML = `${this.translate("Lucy Commands")}:`;
              		appendTo.appendChild(listLabel);
              
              		const list = document.createElement("ul");
              		for (let i = 0; i < this.lucy.sentences.length; i += 1) {
              			const item = document.createElement("li");
              			list.classList.add("xsmall");
              			item.innerHTML = this.lucy.sentences[i];
              			list.appendChild(item);
              		}
              		appendTo.appendChild(list);
              	}
              });
              
              
              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @Nicodil
                last edited by

                @nicodil ok, are you using https for mm?

                can u stop on the sfn= line and hover over the src

                document.currentScript.src

                I just need to see the beginning of the string

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • N Offline
                  Nicodil
                  last edited by Nicodil

                  @sdetweil Yes sure:
                  1cc0da69-f59c-4573-9e7d-317afedb0792-image.png

                  AND No file in this folder:
                  be6e932b-e6a7-449a-a02c-48e231918371-image.png

                  S 1 Reply Last reply Reply Quote 0
                  • S Do not disturb
                    sdetweil @Nicodil
                    last edited by

                    @nicodil that’s the right path.is sentences.json in the module folder?

                    computer says no

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    N 1 Reply Last reply Reply Quote 0
                    • N Offline
                      Nicodil @sdetweil
                      last edited by

                      @sdetweil Yes, i posted it in both folders, to get sure:

                      ee328471-b8e5-4e55-9d5a-b44dd1399b26-image.png

                      1 Reply Last reply Reply Quote 0
                      • N Offline
                        Nicodil
                        last edited by

                        It looks like it is reading now the sentences.json. Im not sure why, the error was not shown anymore after a few restarts and changes.

                        BUT still Lucy understands only nonsence, only the words in the words.json…
                        The Array of the sentences is there, like in your picture, so it is read.

                        She still cannot understand “Show modules” or “Hide Modules”, only words like “the”, “who” , …

                        Any idea?

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          Nicodil
                          last edited by Nicodil

                          @sdetweil Your changes creating some errors for some reason. Exactly the same line (15):

                          ef69f98d-4bd2-4ee0-984c-0085a5864c0b-image.png

                          S 1 Reply Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @Nicodil
                            last edited by

                            @nicodil Mykle has updated the repo

                            so you can git pull to update

                            but u need to restore the file first

                            in the module folder do

                            git checkout HelloLucy.js
                            

                            then

                            git pull
                            

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            N 1 Reply Last reply Reply Quote 0
                            • N Offline
                              Nicodil @sdetweil
                              last edited by

                              Hi @sdetweil ,
                              im sorry to say that but this is an error after the Update.

                              ab53487e-4eab-4527-8c51-82db9254ba62-image.png

                              S 1 Reply Last reply Reply Quote 0
                              • S Do not disturb
                                sdetweil @Nicodil
                                last edited by

                                @nicodil ok, so you will have to go into the developers window to help me

                                ctrl-shift-i
                                select the sources tab
                                find the module in the left nav, and Hello-Lucy.js
                                and click the number on the left column
                                for line 15 var sfn=

                                then hit f5 refresh
                                it will stop at line 15, then using the mouse hove over the .src of document.currentSrc.src

                                take a screen shot of that

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                N 1 Reply Last reply Reply Quote 0
                                • N Offline
                                  Nicodil @sdetweil
                                  last edited by

                                  @sdetweil said in Sentences not loaded in hello-Lucy:

                                  d the module in the left nav, and

                                  Thanks for your time and help!

                                  aa2ef5df-b4ec-4080-b1f0-483c318a6a82-image.png

                                  S 1 Reply Last reply Reply Quote 0
                                  • S Do not disturb
                                    sdetweil @Nicodil
                                    last edited by sdetweil

                                    @nicodil ok, then tap the button next o the blue arrow >

                                    then hover over sfn

                                    then put stops on line 9 and 22 and hit run (blue arrow)

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    N 1 Reply Last reply Reply Quote 0
                                    • N Offline
                                      Nicodil @sdetweil
                                      last edited by

                                      @sdetweil
                                      f8d02dbf-023d-4344-ac2e-88d9352e7baf-image.png

                                      3e519fa0-919d-45c9-911b-8ac11ccd84ec-image.png

                                      It works fine when i dont load the RemoteControl, no error -Module… But the error with the RemoteControl is pointing to line 15, thats strange…

                                      b2f65f49-11d7-4936-9dcc-20c23ba130a8-image.png

                                      1 Reply Last reply Reply Quote 0

                                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                      With your input, this post could be even better 💗

                                      Register Login
                                      • 1 / 1
                                      • First post
                                        Last post
                                      Enjoying MagicMirror? Please consider a donation!
                                      MagicMirror created by Michael Teeuw.
                                      Forum managed by Sam, technical setup by Karsten.
                                      This forum is using NodeBB as its core | Contributors
                                      Contact | Privacy Policy