From 80282a6847d885046c6ae892a1ac40454ce5d1d4 Mon Sep 17 00:00:00 2001 From: Kristjan SCHMIDT <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 17 Jan 2022 00:29:45 +0100 Subject: [PATCH 1/5] First tests with TTS --- MMM-PublicTransportHafas.js | 3 +- README.md | 12 ++++++ core/PTHAFASTTS.js | 76 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 core/PTHAFASTTS.js diff --git a/MMM-PublicTransportHafas.js b/MMM-PublicTransportHafas.js index 4da408a..9d712f6 100755 --- a/MMM-PublicTransportHafas.js +++ b/MMM-PublicTransportHafas.js @@ -183,7 +183,8 @@ Module.register("MMM-PublicTransportHafas", { return [ "moment.js", this.file("core/PTHAFASDomBuilder.js"), - this.file("core/PTHAFASTableBodyBuilder.js") + this.file("core/PTHAFASTableBodyBuilder.js"), + this.file("core/PTHAFASTTS.js") ]; }, diff --git a/README.md b/README.md index 1aff413..72ae6c3 100755 --- a/README.md +++ b/README.md @@ -219,6 +219,18 @@ Alongside the departure time a small figure displays the delay as reported by th Delays are displayed as red. No delay or negative delays (the transport will arrive early) are displayed in green. If you want to customize that include the classes `pthHasDelay` and `pthIsTooEarly` in your custom css file and make the appropriate settings. +## Text To Speech + +This function is still in development. + +Add script to package.json: +`"start:tts": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron --enable-speech-dispatcher js/electron.js",` + +Start with: `npm run start:tts` + +Keys: + TODO + ## Technical background details To limit the server request only when the module is displayed and/or the user is present, the update will be stopped when no instance of the module are displayed (module hidden e.g. by a [MMM-Carousel](https://github.com/lawrence-jeff/MMM-Carousel), [MMM-Pages](https://github.com/edward-shen/MMM-pages) or [MMM-Remote-Control](https://github.com/Jopyth/MMM-Remote-Control)). The update will also be stopped by the use of a PIR sensor using the module [MMM-PIR-Sensor](https://github.com/paviro/MMM-PIR-Sensor) (that sends the notification 'USER_PRESENCE'). No special configuration is needed for this behaviour. diff --git a/core/PTHAFASTTS.js b/core/PTHAFASTTS.js new file mode 100644 index 0000000..6290af2 --- /dev/null +++ b/core/PTHAFASTTS.js @@ -0,0 +1,76 @@ +"use strict"; + +// Initialize new SpeechSynthesisUtterance object +let speech = new SpeechSynthesisUtterance(); + +// Set speech Language +speech.lang = config.language; + +function sayDepartures() { + // Time + sayTime(); + + // Set the text property with the value of the textarea + let pthWrappers = document.getElementsByClassName("pthWrapper"); + + for (let pthWrapper of pthWrappers) { + // Station + let station = pthWrapper.getElementsByTagName("header")[0]; + speech.text = speech.text + " Haltestelle " + station.innerText; + + let pthTable = pthWrapper.getElementsByClassName("pthTable")[0]; + + // Line + let lines = pthTable.getElementsByClassName("pthSign"); + for (let line of lines) { + line.innerText = "Linie " + line.innerText; + } + + // Direction + let directions = pthTable.getElementsByClassName("pthDirectionCell"); + for (let direction of directions) { + direction.innerText = "in Richtung " + direction.innerText; + } + + // Platform + let platforms = pthTable.getElementsByClassName("pthPlatformCell"); + for (let platform of platforms) { + if (platform.innerText !== "") { + platform.innerText = "Steig " + platform.innerText; + } + } + + let rows = pthTable.getElementsByTagName("tr"); + for (let row of rows) { + speech.text = speech.text + row.innerText.replaceAll("\n", " ") + ",\n"; + } + + speech.text = speech.text.replaceAll("\t", " ").replaceAll(" ", " "); + console.log(speech.text); + + // Start Speaking + speechSynthesis.speak(speech); + } +} + + +let speechHello = new SpeechSynthesisUtterance(); +speechHello.lang = config.language; + +function sayHello() { + let hello = "Guten Tag!"; + speechHello.text = hello; + speechSynthesis.speak(speechHello); +} + +function sayTime() { + let time = new Date(); + let timeString = + "Es ist " + time.getHours() + " Uhr " + time.getMinutes() + ",\n"; + speech.text = timeString; + speechSynthesis.speak(speech); + speech.text = ""; +} + +sayHello(); +sayTime(); From 58840ea87bc0f9e06cdbad6fbfcf13629ae718fe Mon Sep 17 00:00:00 2001 From: Kristjan SCHMIDT <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 17 Jan 2022 23:01:26 +0100 Subject: [PATCH 2/5] sayTime after sayHello --- core/PTHAFASTTS.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/PTHAFASTTS.js b/core/PTHAFASTTS.js index 6290af2..4367c4b 100644 --- a/core/PTHAFASTTS.js +++ b/core/PTHAFASTTS.js @@ -53,10 +53,13 @@ function sayDepartures() { } } - let speechHello = new SpeechSynthesisUtterance(); speechHello.lang = config.language; +speechHello.addEventListener("end", function (event) { + sayTime(); +}); + function sayHello() { let hello = "Guten Tag!"; speechHello.text = hello; @@ -73,4 +76,3 @@ function sayTime() { } sayHello(); -sayTime(); From d72c812dae16cf4f0bee99f45f389027343dc2d7 Mon Sep 17 00:00:00 2001 From: Kristjan SCHMIDT <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 17 Jan 2022 00:29:45 +0100 Subject: [PATCH 3/5] First tests with TTS --- MMM-PublicTransportHafas.js | 3 +- README.md | 12 ++++++ core/PTHAFASTTS.js | 76 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 core/PTHAFASTTS.js diff --git a/MMM-PublicTransportHafas.js b/MMM-PublicTransportHafas.js index 4da408a..9d712f6 100755 --- a/MMM-PublicTransportHafas.js +++ b/MMM-PublicTransportHafas.js @@ -183,7 +183,8 @@ Module.register("MMM-PublicTransportHafas", { return [ "moment.js", this.file("core/PTHAFASDomBuilder.js"), - this.file("core/PTHAFASTableBodyBuilder.js") + this.file("core/PTHAFASTableBodyBuilder.js"), + this.file("core/PTHAFASTTS.js") ]; }, diff --git a/README.md b/README.md index 1aff413..72ae6c3 100755 --- a/README.md +++ b/README.md @@ -219,6 +219,18 @@ Alongside the departure time a small figure displays the delay as reported by th Delays are displayed as red. No delay or negative delays (the transport will arrive early) are displayed in green. If you want to customize that include the classes `pthHasDelay` and `pthIsTooEarly` in your custom css file and make the appropriate settings. +## Text To Speech + +This function is still in development. + +Add script to package.json: +`"start:tts": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron --enable-speech-dispatcher js/electron.js",` + +Start with: `npm run start:tts` + +Keys: + TODO + ## Technical background details To limit the server request only when the module is displayed and/or the user is present, the update will be stopped when no instance of the module are displayed (module hidden e.g. by a [MMM-Carousel](https://github.com/lawrence-jeff/MMM-Carousel), [MMM-Pages](https://github.com/edward-shen/MMM-pages) or [MMM-Remote-Control](https://github.com/Jopyth/MMM-Remote-Control)). The update will also be stopped by the use of a PIR sensor using the module [MMM-PIR-Sensor](https://github.com/paviro/MMM-PIR-Sensor) (that sends the notification 'USER_PRESENCE'). No special configuration is needed for this behaviour. diff --git a/core/PTHAFASTTS.js b/core/PTHAFASTTS.js new file mode 100644 index 0000000..6290af2 --- /dev/null +++ b/core/PTHAFASTTS.js @@ -0,0 +1,76 @@ +"use strict"; + +// Initialize new SpeechSynthesisUtterance object +let speech = new SpeechSynthesisUtterance(); + +// Set speech Language +speech.lang = config.language; + +function sayDepartures() { + // Time + sayTime(); + + // Set the text property with the value of the textarea + let pthWrappers = document.getElementsByClassName("pthWrapper"); + + for (let pthWrapper of pthWrappers) { + // Station + let station = pthWrapper.getElementsByTagName("header")[0]; + speech.text = speech.text + " Haltestelle " + station.innerText; + + let pthTable = pthWrapper.getElementsByClassName("pthTable")[0]; + + // Line + let lines = pthTable.getElementsByClassName("pthSign"); + for (let line of lines) { + line.innerText = "Linie " + line.innerText; + } + + // Direction + let directions = pthTable.getElementsByClassName("pthDirectionCell"); + for (let direction of directions) { + direction.innerText = "in Richtung " + direction.innerText; + } + + // Platform + let platforms = pthTable.getElementsByClassName("pthPlatformCell"); + for (let platform of platforms) { + if (platform.innerText !== "") { + platform.innerText = "Steig " + platform.innerText; + } + } + + let rows = pthTable.getElementsByTagName("tr"); + for (let row of rows) { + speech.text = speech.text + row.innerText.replaceAll("\n", " ") + ",\n"; + } + + speech.text = speech.text.replaceAll("\t", " ").replaceAll(" ", " "); + console.log(speech.text); + + // Start Speaking + speechSynthesis.speak(speech); + } +} + + +let speechHello = new SpeechSynthesisUtterance(); +speechHello.lang = config.language; + +function sayHello() { + let hello = "Guten Tag!"; + speechHello.text = hello; + speechSynthesis.speak(speechHello); +} + +function sayTime() { + let time = new Date(); + let timeString = + "Es ist " + time.getHours() + " Uhr " + time.getMinutes() + ",\n"; + speech.text = timeString; + speechSynthesis.speak(speech); + speech.text = ""; +} + +sayHello(); +sayTime(); From 4686c3e0e94a4e20772aa9d99d4dc43bb3ffd9d8 Mon Sep 17 00:00:00 2001 From: Kristjan SCHMIDT <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 17 Jan 2022 23:01:26 +0100 Subject: [PATCH 4/5] sayTime after sayHello --- core/PTHAFASTTS.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/PTHAFASTTS.js b/core/PTHAFASTTS.js index 6290af2..4367c4b 100644 --- a/core/PTHAFASTTS.js +++ b/core/PTHAFASTTS.js @@ -53,10 +53,13 @@ function sayDepartures() { } } - let speechHello = new SpeechSynthesisUtterance(); speechHello.lang = config.language; +speechHello.addEventListener("end", function (event) { + sayTime(); +}); + function sayHello() { let hello = "Guten Tag!"; speechHello.text = hello; @@ -73,4 +76,3 @@ function sayTime() { } sayHello(); -sayTime(); From 1d561d60cd9d9fc687c94cf52a2fd5037efa3a8e Mon Sep 17 00:00:00 2001 From: Kristjan SCHMIDT <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Tue, 18 Jan 2022 00:04:42 +0100 Subject: [PATCH 5/5] Update --- core/PTHAFASTTS.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/PTHAFASTTS.js b/core/PTHAFASTTS.js index 4367c4b..2b0edd6 100644 --- a/core/PTHAFASTTS.js +++ b/core/PTHAFASTTS.js @@ -16,7 +16,7 @@ function sayDepartures() { for (let pthWrapper of pthWrappers) { // Station let station = pthWrapper.getElementsByTagName("header")[0]; - speech.text = speech.text + " Haltestelle " + station.innerText; + speech.text = speech.text + "\n. Haltestelle " + station.innerText + ".\n"; let pthTable = pthWrapper.getElementsByClassName("pthTable")[0]; @@ -43,14 +43,18 @@ function sayDepartures() { let rows = pthTable.getElementsByTagName("tr"); for (let row of rows) { speech.text = speech.text + row.innerText.replaceAll("\n", " ") + ",\n"; + speech.text = speech.text.replaceAll("str.", "straße"); + speech.text = speech.text.replaceAll("Str.", "Straße"); + speech.text = speech.text.replaceAll("STR.", "Straße"); } speech.text = speech.text.replaceAll("\t", " ").replaceAll(" ", " "); - console.log(speech.text); - - // Start Speaking - speechSynthesis.speak(speech); } + + console.log(speech.text); + + // Start Speaking + speechSynthesis.speak(speech); } let speechHello = new SpeechSynthesisUtterance();