diff --git a/README.md b/README.md index 0aca6bd1..a430e60c 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Open the app with the following **supported browsers** and many more. - Screen Sharing to present documents, slides, and more ... - File Sharing, share any files to your participants in the room - Chat with Emoji Picker to show you feeling and the possibility to Save the conversations +- Speech recognition, ability to identify a person based on their voiceprint. - Advance collaborative whiteboard for the teachers - Select Microphone - Speaker and Video source - Recording your Screen, Audio, or Video diff --git a/public/js/Room.js b/public/js/Room.js index b0e6b1fb..fc0455cd 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -93,6 +93,8 @@ function initClient() { setTippy('participantsRefreshBtn', 'Refresh', 'top'); setTippy('chatMessage', 'Press enter to send', 'top-start'); setTippy('chatSendButton', 'Send', 'top'); + setTippy('chatSpeechStartButton', 'Start speech recognition', 'top'); + setTippy('chatSpeechStopButton', 'Stop speech recognition', 'top'); setTippy('chatEmojiButton', 'Emoji', 'top'); setTippy('chatCloseEmojiButton', 'Close emoji', 'top'); setTippy('chatCleanButton', 'Clean', 'bottom'); @@ -469,6 +471,9 @@ function roomIsReady() { show(chatButton); show(chatSendButton); show(chatEmojiButton); + if (isWebkitSpeechRecognitionSupported) { + show(chatSpeechStartButton); + } if (DetectRTC.isMobileDevice) { show(swapCameraButton); setChatSize(); @@ -633,6 +638,12 @@ function handleButtons() { chatCloseEmojiButton.onclick = () => { rc.toggleChatEmoji(); }; + chatSpeechStartButton.onclick = () => { + startSpeech(true); + }; + chatSpeechStopButton.onclick = () => { + startSpeech(false); + }; fullScreenButton.onclick = () => { rc.toggleFullScreen(); }; diff --git a/public/js/SpeechRec.js b/public/js/SpeechRec.js new file mode 100644 index 00000000..17e2cdc8 --- /dev/null +++ b/public/js/SpeechRec.js @@ -0,0 +1,44 @@ +let isWebkitSpeechRecognitionSupported = false; +let recognition; + +if ('webkitSpeechRecognition' in window) { + recognition = new webkitSpeechRecognition(); + + recognition.maxAlternatives = 1; + recognition.continuous = true; + + recognition.onstart = function () { + console.log('Start speech recognition'); + hide(chatSpeechStartButton); + show(chatSpeechStopButton); + }; + + recognition.onresult = (e) => { + let current = e.resultIndex; + let transcript = e.results[current][0].transcript; + chatMessage.value = transcript; + }; + + recognition.onerror = function (event) { + console.warn('Speech recognition error', event.error); + }; + + recognition.onend = function () { + console.log('Stop speech recognition'); + show(chatSpeechStartButton); + hide(chatSpeechStopButton); + }; + + isWebkitSpeechRecognitionSupported = true; + console.info('Browser supports webkitSpeechRecognition'); +} else { + console.warn('This browser not supports webkitSpeechRecognition'); +} + +function startSpeech(action) { + if (action) { + recognition.start(); + } else { + recognition.stop(); + } +} diff --git a/public/view/Room.html b/public/view/Room.html index 69066152..d3cc479c 100644 --- a/public/view/Room.html +++ b/public/view/Room.html @@ -75,6 +75,7 @@ + @@ -336,6 +337,12 @@ access to use this app. + +