Skip to content

Commit

Permalink
Web demo update (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt200-ok authored Dec 23, 2024
1 parent fac1739 commit c509421
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion recipes/llm-voice-assistant/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@picovoice/cheetah-web": "^2.0.0",
"@picovoice/orca-web": "^1.0.0",
"@picovoice/picollm-web": "~1.2.0",
"@picovoice/picollm-web": "~1.2.3",
"@picovoice/porcupine-web": "^3.0.3",
"@picovoice/web-voice-processor": "^4.0.9"
},
Expand Down
17 changes: 12 additions & 5 deletions recipes/llm-voice-assistant/web/public/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ window.onload = () => {
let audioStream;
let streamCalls = 0;
let isDetected = false;
let isResponding = false;

try {
await Picovoice.init(accessKey.value,
Expand All @@ -106,6 +107,8 @@ window.onload = () => {
{
onDetection: () => {
isDetected = true;
isResponding = false;
audioStream.clear();
message.innerText = "Wake word detected, utter your request or question...";
humanElem = startHumanMessage();
},
Expand All @@ -115,21 +118,25 @@ window.onload = () => {
},
onEndpoint: () => {
isDetected = false;
isResponding = true;
message.innerHTML = "Generating <div class='loader'></div> say `Picovoice` to interrupt";
llmElem = startLLMMessage();
},
onText: (text) => {
addMessage(llmElem, text);
},
onStream: (pcm) => {
audioStream.stream(pcm);
if (streamCalls > 1) {
audioStream.play();
} else {
streamCalls++;
if (isResponding) {
audioStream.stream(pcm);
if (streamCalls > 1) {
audioStream.play();
} else {
streamCalls++;
}
}
},
onComplete: async (interrupted) => {
isResponding = false;
audioStream.play();
if (interrupted && isDetected) {
audioStream.clear();
Expand Down
8 changes: 4 additions & 4 deletions recipes/llm-voice-assistant/web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,10 @@
dependencies:
"@picovoice/web-utils" "=1.4.2"

"@picovoice/picollm-web@~1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@picovoice/picollm-web/-/picollm-web-1.2.0.tgz#346a62a81acb5f53073075766a036060daa9a512"
integrity sha512-vjnjrC30auuNBmpLu2plNk7BzSNtGKOWhx5+X6IHQYfVt00CnK23fYLxzS16CR6thGSinEixC44H61bgJLT4Ug==
"@picovoice/picollm-web@~1.2.3":
version "1.2.3"
resolved "https://registry.yarnpkg.com/@picovoice/picollm-web/-/picollm-web-1.2.3.tgz#765f52c55943c71dbb7c95492b93cda15e483999"
integrity sha512-QtiZTckN6UDlO5bVnR5ldhegb9h63szu4l3PknI7V4Qsz8w4AXaloRXlnOhK87oEC5Px2C56ve7+aiH9oSPcNQ==
dependencies:
"@picovoice/web-utils" "~1.4.3"

Expand Down

0 comments on commit c509421

Please sign in to comment.