Skip to content

Commit

Permalink
Fixed getStats handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Fleming committed Jun 17, 2024
1 parent 26bec99 commit 97fe7b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion chat/static/chat/js/speechApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions chat/static/chat/js/streaming-client-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -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
}
}
Expand Down
Binary file modified db.sqlite3
Binary file not shown.

0 comments on commit 97fe7b4

Please sign in to comment.