Skip to content

Commit

Permalink
moved script out of html file, added better bootstrap instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamik Mukelyan committed Sep 1, 2017
1 parent 989e77c commit 43b5550
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 87 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ How to propose marriage with a puppy, a phone, and a Web Socket.


## Technical Notes
OpenSSL deprecation makes it difficult to get this project running on OS X in a virtualenv. Install dependencies in `requirements.txt` outside of a virtualenv and see [Flask-uWSGI-WebSocket](https://github.com/zeekay/flask-uwsgi-websocket) for some platform-dependent instructions.
OpenSSL deprecation makes it a little difficult to get this project running in a virtualenv. Instead, (1) install dependencies in `requirements.txt` outside of a virtualenv, (2) compile and link openssl, and (3) install uwsgi with openssl awareness. The following were tested on OS X.

1. `pip install -r requirements.txt`
2.
```
cd /usr/local/src
sudo curl --remote-name https://www.openssl.org/source/openssl-1.0.2l.tar.gz
sudo tar -xzvf openssl-1.0.2l.tar.gz
cd openssl-1.0.2l
sudo ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl-1.0.2l sharedmake depend
sudo make depend
sudo make
sudo make install
ln -s /usr/local/openssl-1.0.2l/bin/openssl /usr/local/bin/openssl
(close and open terminal)
```
3. `CFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" UWSGI_PROFILE_OVERRIDE=ssl=true pip install uwsgi -I --no-cache-dir`

## Non-technical Notes
Congrats Hamik and Vicky! - Garrett
85 changes: 1 addition & 84 deletions prop.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,4 @@
<span id="transcript"></span>
</div>

<script>

const STATIC_IP = '192.168.1.200';
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();

</script>
<script src="prop.js"></script>
80 changes: 80 additions & 0 deletions prop.js
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();
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
flask
Flask-uWSGI-WebSocket
uwsgi
gevent
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask import Flask
from flask_uwsgi_websocket import GeventWebSocket

PROPOSER_STMTS_FILE = 'modify.txt'
PROPOSER_STMTS_FILE = 'text_goes_here.txt'
POLLING_INTERVAL_SECS = 0.5

app = Flask(__name__)
Expand Down
1 change: 1 addition & 0 deletions text_goes_here.txt
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.

0 comments on commit 43b5550

Please sign in to comment.