From 0f35feeeeca0f5743f6e7e6e9f0c966359ec94a5 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Wed, 19 Mar 2025 20:40:30 +0000 Subject: [PATCH] Upload files to "www/html/_assets/js" --- www/html/_assets/js/assistant.js | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 www/html/_assets/js/assistant.js diff --git a/www/html/_assets/js/assistant.js b/www/html/_assets/js/assistant.js new file mode 100644 index 0000000..4ab5d2a --- /dev/null +++ b/www/html/_assets/js/assistant.js @@ -0,0 +1,93 @@ + +var Assistant = {} +Assistant.speak = function(text, chunkSize = 200) { + if ('speechSynthesis' in window) { + const speechSynthesis = window.speechSynthesis; + const chunks = []; + for (let i = 0; i < text.length; i += chunkSize) { + chunks.push(text.slice(i, i + chunkSize)); + } + + function speakNextChunk(index) { + if (index < chunks.length) { + const utterance = new SpeechSynthesisUtterance(chunks[index]); + utterance.onend = () => speakNextChunk(index + 1); // Speak the next chunk when the current one finishes. + window.speechSynthesis.cancel() + speechSynthesis.speak(utterance); + } + } + + speakNextChunk(0); // Start with the first chunk. + } else { + console.error('Speech synthesis is not supported in this browser.'); + } + } + + +// var Assistant = function (){ +// this._message = null +// this._message = new SpeechSynthesisUtterance() +// // this._voices = window.speechSynthesis.getVoices(); +// // var r = [] +// // this._voices.forEach(function(_item){ +// // if(_item.lang.match(/us|br|gb/i)){ +// // r.push(_item) +// // } +// // }) +// // this._voices = r +// this.speak = function(text,times){ +// var _message = null; +// if (window.speechSynthesis) { +// var _message = new SpeechSynthesisUtterance() +// var voices = window.speechSynthesis.getVoices(); +// var r = [] +// voices.forEach(function(_item){ +// if(_item.lang.match(/gb/i)){ +// r.push(_item) +// } +// }) +// voices = r +// } +// if ( _message != null) { + +// _message.text = text +// // _message.voice = voices[0] +// _message.volume = 1 +// _message.pitch = 1 +// window.speechSynthesis.speak(_message) +// } +// } +// this._speak = function (text,times){ +// // this._message = new SpeechSynthesisUtterance() +// // this._message.text = text +// // this._message.voice = this._voices[0] +// var _voices = [ ] +// window.speechSynthesis.getVoices().forEach(_item=>{ +// if(_item.lang.match(/au|gb/i)){ +// _voices.push(_item) +// } +// }) +// var _message = new SpeechSynthesisUtterance() +// _message.text = text +// _message.voiceURI = 'native' +// // alert(_message.voiceURI) +// // _message.volume = 1 +// window.speechSynthesis.cancel() +// if (times != null){ +// times = parseInt(times) +// // var _message = this._message +// var _index = 0 +// var _iHandler = setInterval(function(){ +// window.speechSynthesis.speak(_message) +// _index += 1 +// if (_index == times){ +// clearInterval(_iHandler) +// } +// },2500,times) +// }else{ +// window.speechSynthesis.speak(_message) +// } + +// } + +// } \ No newline at end of file