Improve voice turns, local commands and Spotify controls
This commit is contained in:
+6
-3
@@ -14,7 +14,7 @@ export function handleTurn(client, store) {
|
||||
let state = 'waiting', stt, tts, bytes = 0, received = 0, messages = 0, ended = false, terminal = false, wake = false;
|
||||
let pending = [];
|
||||
let pendingBytes = 0;
|
||||
const timeout = setTimeout(() => fail('timeout'), 120000);
|
||||
let timeout = setTimeout(() => fail('timeout'), 120000);
|
||||
const send = obj => { if (client.readyState === WebSocket.OPEN) client.send(JSON.stringify(obj)); };
|
||||
function cleanup() {
|
||||
clearTimeout(timeout);
|
||||
@@ -47,7 +47,7 @@ export function handleTurn(client, store) {
|
||||
text = text.replace(/^[«"“]?алиса(?:[»"”.,!?…:;\s–—-]+|$)/iu, '');
|
||||
if (!text) return complete('', '');
|
||||
}
|
||||
if (!text) return fail('empty_transcript');
|
||||
if (!text || /^(?:стоп|хватит)[.!?…]*$/iu.test(text)) return complete('', '');
|
||||
send({ type: 'transcript', text });
|
||||
try {
|
||||
const action = quickAction(text);
|
||||
@@ -103,6 +103,8 @@ export function handleTurn(client, store) {
|
||||
if (!pendingBytes) return fail('empty_audio');
|
||||
ended = true;
|
||||
state = 'processing';
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fail('response_timeout'), 45000);
|
||||
sendChunk(Buffer.concat(pending, pendingBytes), true);
|
||||
pending = [];
|
||||
pendingBytes = 0;
|
||||
@@ -111,5 +113,6 @@ export function handleTurn(client, store) {
|
||||
});
|
||||
client.on('error', () => { if (!terminal) { terminal = true; cleanup(); } });
|
||||
client.on('close', () => { if (!terminal) { terminal = true; cleanup(); } });
|
||||
send({ type: 'ready' });
|
||||
const { followUpMs, activationSound } = store.getSettings();
|
||||
send({ type: 'ready', followUpMs, activationSound });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user