diff --git a/chat/static/chat/js/speechApi.js b/chat/static/chat/js/speechApi.js index 1e33d1a..4655e4a 100644 --- a/chat/static/chat/js/speechApi.js +++ b/chat/static/chat/js/speechApi.js @@ -129,7 +129,6 @@ if ('webkitSpeechRecognition' in window) { if (["START", "INTRO"].includes(command.value)) { enableSpeech() myHandler() - window.startStats(streamingCallback, stats_delay) } else { sleeping = false if (!listening) { @@ -185,6 +184,7 @@ async function speak(text) { if (useAvatar) { try { + window.startStats(streamingCallback, stats_delay) await window.talk(text, speakNoVideo) } catch (e) { window.log("🞙 Error retrieving video: " + e) diff --git a/chat/static/chat/js/streaming-client-api.js b/chat/static/chat/js/streaming-client-api.js index 77a4896..d41bbc6 100644 --- a/chat/static/chat/js/streaming-client-api.js +++ b/chat/static/chat/js/streaming-client-api.js @@ -18,6 +18,7 @@ let lastBytesReceived = 0 let bytesSent = 0 let isPlaying = false let statsStarted = false +let triggered = false const talkVideo = document.getElementById("talk-video") talkVideo.setAttribute("playsinline", "") @@ -193,25 +194,40 @@ window.startStats = (callback, frequency) => { (report) => report?.type == "inbound-rtp" && report.kind == "video" ) - if (!hasStarted && inbound?.bytesReceived > lastBytesReceived) { + if (!triggered) { + lastBytesReceived = inbound?.bytesReceived + triggered = true + + window.log("▭ Playing has started") + return + } + + if (triggered && !hasStarted && inbound?.bytesReceived > lastBytesReceived) { lastBytesReceived = inbound?.bytesReceived hasStarted = true - window.log(`▭ Playing has started`) + window.log("▭ Playing was triggered") return } - if (hasStarted) { + if (hasStarted) { + window.log("▭ hasStarted is true") + if (inbound?.bytesReceived > lastBytesReceived) { isPlaying = true window.log( `▭ Bytes Received: ${lastBytesReceived} ${inbound?.bytesReceived}` ) + lastBytesReceived = inbound?.bytesReceived callback(false) // still playing } else { isPlaying = false + hasStarted = false + triggered = false + window.log("▭ Stopped Playing") + window.stopStats() callback(true) // done playing } } diff --git a/db.sqlite3 b/db.sqlite3 index e1ad48e..fbf7f65 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ