Skip to content

Commit

Permalink
Add 'speakObjsQueue' for phonetic calls
Browse files Browse the repository at this point in the history
Queue for phonetic calls.

Also adds commas to phonetic calls for pauses between name / lap / time.
  • Loading branch information
ethomas997 committed Mar 26, 2018
1 parent 47a3573 commit 5f60c51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/delta5server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def heartbeat_thread_function():
'''Emits current rssi data.'''
while True:
SOCKET_IO.emit('heartbeat', INTERFACE.get_heartbeat_json())
gevent.sleep(0.500)
gevent.sleep(0.100)

def ms_from_race_start():
'''Return milliseconds since race start.'''
Expand Down
36 changes: 32 additions & 4 deletions src/delta5server/templates/race.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<audio id="buzzer" src="./static/audio/buzzer.mp3" type="audio/mp3"></audio>

<script type="text/javascript" charset="utf-8">

var speakObjsQueue = [];
var checkSpeakQueueFlag = true;

$(document).ready(function () {
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);

Expand Down Expand Up @@ -36,9 +40,27 @@
}
});

var heatbeatCounter = 0;

socket.on('heartbeat', function (msg) {
for (i = 0; i < msg.current_rssi.length; i++) {
$('.current_rssi_' + i).html(msg.current_rssi[i]);
if (speakObjsQueue.length > 0) {
var isSpeakingFlag = $().articulate('isSpeaking');
if (checkSpeakQueueFlag) {
if (!isSpeakingFlag) {
var obj = speakObjsQueue.shift();
if (speakObjsQueue.length > 0)
checkSpeakQueueFlag = false;
doSpeak(obj);
}
} //make sure previous speak has started before checking queue again
else if (isSpeakingFlag)
checkSpeakQueueFlag = true;
}
if (++heatbeatCounter >= 5) { //do RSSI updates less often than speak-queue checks
heatbeatCounter = 0;
for (i = 0; i < msg.current_rssi.length; i++) {
$('.current_rssi_' + i).html(msg.current_rssi[i]);
}
}
});

Expand Down Expand Up @@ -91,7 +113,7 @@
});

socket.on('phonetic_data', function (msg) {
var $ttstest = msg.pilot + " lap " + msg.lap + " " + msg.phonetic;
var $ttstest = msg.pilot + ", lap " + msg.lap + ", " + msg.phonetic;
speak('<div class="speech">' + $ttstest + '</div> div.speech');
})

Expand Down Expand Up @@ -175,7 +197,7 @@

var sellang = {{ lang_id }};

function speak(obj) {
function doSpeak(obj) {
switch (sellang) {
case 1:
$(obj).articulate('setVoice','name','Microsoft David Desktop - English (United States)').articulate('speak');
Expand Down Expand Up @@ -243,6 +265,12 @@
function ratefast(obj) {
$(obj).articulate('rate', 3.0);
};


function speak(obj) {
speakObjsQueue.push(obj);
};

</script>
{% endblock %} {% block content %}

Expand Down

0 comments on commit 5f60c51

Please sign in to comment.