-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved script out of html file, added better bootstrap instructions
- Loading branch information
Hamik Mukelyan
committed
Sep 1, 2017
1 parent
989e77c
commit 43b5550
Showing
6 changed files
with
100 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const STATIC_IP = 'localhost'; | ||
const PORT = '8080'; | ||
const WS_ADDRESS = 'ws:https://' + STATIC_IP + ':' + PORT + '/prop'; | ||
const SPEECH_RATE_MULTIPLIER = 1.15; | ||
const LANG = 'en'; | ||
const BREAK = '<br>'; | ||
|
||
synth = window.speechSynthesis; | ||
|
||
// Get all the voices available to this browser (but NB this probably works | ||
// best in Chrome) | ||
function getBrowserVoices() { | ||
if(typeof speechSynthesis === 'undefined') { | ||
return; | ||
} | ||
|
||
voices = speechSynthesis.getVoices(); | ||
|
||
// Define each option in the dropdown menu for voices | ||
voices.forEach(function (voice) { | ||
|
||
// Skip languages we don't want | ||
if (voice.lang.indexOf(LANG) === -1) { | ||
return; | ||
} | ||
|
||
dropdownItem = document.createElement('option'); | ||
dropdownItem.textContent = voice.name; | ||
|
||
dropdownItem.setAttribute('name', voice.name); | ||
document.getElementById('dropdown').appendChild(dropdownItem); | ||
}); | ||
} | ||
|
||
getBrowserVoices(); | ||
if (speechSynthesis.onvoiceschanged !== undefined) { | ||
speechSynthesis.onvoiceschanged = getBrowserVoices; | ||
} | ||
|
||
// Establish a websocket connection with the proposer's server | ||
function newWS() { | ||
ws = new WebSocket(WS_ADDRESS); | ||
|
||
ws.onopen = function(evt) { | ||
console.log('Connected to websocket.'); | ||
} | ||
|
||
ws.onmessage = function(evt) { | ||
|
||
// Get and log the message from the proposer | ||
var prompt = evt.data; | ||
transcript.innerHTML += prompt + BREAK; | ||
console.log('msg: ' + prompt); | ||
|
||
|
||
var msg = new SpeechSynthesisUtterance(); | ||
msg.text = prompt; | ||
|
||
// Set the voice and rate of speech | ||
speaker = document.getElementById("dropdown").value; | ||
console.log('speaker: ' + speaker); | ||
voices.forEach(function (voice) { | ||
if(voice.name === document.getElementById("dropdown").value) { | ||
msg.voice = voice; | ||
msg.rate = SPEECH_RATE_MULTIPLIER; | ||
} | ||
}); | ||
|
||
msg.onend = function(e) { | ||
console.log('done speaking'); | ||
}; | ||
|
||
// Hack to make sure Chrome speaks every message | ||
setTimeout( | ||
function(){ | ||
synth.speak(msg); | ||
}, 1); | ||
} | ||
} | ||
newWS(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
flask | ||
Flask-uWSGI-WebSocket | ||
uwsgi | ||
gevent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
This file is polled for changes. | ||
Its last line is sent down the websocket when the last line is changed. | ||
So this is the line that would be sent to the browser. | ||
|