Update engine
This commit is contained in:
@@ -401,6 +401,9 @@
|
||||
|
||||
const targetSampleRate = 16000;
|
||||
const playbackStopRampSec = 0.008;
|
||||
const appId = "assistant_demo";
|
||||
const channel = "web_client";
|
||||
const configVersionId = "local-dev";
|
||||
|
||||
function logLine(type, text, data) {
|
||||
const time = new Date().toLocaleTimeString();
|
||||
@@ -604,15 +607,35 @@
|
||||
logLine("sys", `→ ${cmd.type}`, cmd);
|
||||
}
|
||||
|
||||
function eventIdsSuffix(event) {
|
||||
const data = event && typeof event.data === "object" && event.data ? event.data : {};
|
||||
const keys = ["turn_id", "utterance_id", "response_id", "tool_call_id", "tts_id"];
|
||||
const parts = [];
|
||||
for (const key of keys) {
|
||||
const value = data[key] || event[key];
|
||||
if (value) parts.push(`${key}=${value}`);
|
||||
}
|
||||
return parts.length ? ` [${parts.join(" ")}]` : "";
|
||||
}
|
||||
|
||||
function handleEvent(event) {
|
||||
const type = event.type || "unknown";
|
||||
logLine("event", type, event);
|
||||
const ids = eventIdsSuffix(event);
|
||||
logLine("event", `${type}${ids}`, event);
|
||||
if (type === "hello.ack") {
|
||||
sendCommand({
|
||||
type: "session.start",
|
||||
audio: { encoding: "pcm_s16le", sample_rate_hz: targetSampleRate, channels: 1 },
|
||||
metadata: {
|
||||
appId,
|
||||
channel,
|
||||
configVersionId,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (type === "config.resolved") {
|
||||
logLine("sys", "config.resolved", event.config || {});
|
||||
}
|
||||
if (type === "transcript.final") {
|
||||
if (event.text) {
|
||||
setInterim("You", "");
|
||||
|
||||
Reference in New Issue
Block a user