Tighten wake detection and keep short commands quiet

This commit is contained in:
2026-11-10 22:35:13 +03:00
parent 6b483c9c08
commit a27589447e
20 changed files with 833 additions and 92 deletions
+39
View File
@@ -0,0 +1,39 @@
const units = 'ноль один два три четыре пять шесть семь восемь девять десять одиннадцать двенадцать тринадцать четырнадцать пятнадцать шестнадцать семнадцать восемнадцать девятнадцать'.split(' ');
const tens = 'двадцать тридцать сорок пятьдесят шестьдесят семьдесят восемьдесят девяносто'.split(' ');
function volumeLevel(text) {
if (/^\d{1,3}$/.test(text)) return Number(text);
if (text === 'сто') return 100;
const words = text.split(' ');
if (words.length === 1 && units.includes(words[0])) return units.indexOf(words[0]);
const decade = tens.indexOf(words[0]);
if (decade === -1) return -1;
if (words.length === 1) return (decade + 2) * 10;
const unit = units.indexOf(words[1]);
return words.length === 2 && unit >= 1 && unit <= 9 ? (decade + 2) * 10 + unit : -1;
}
export function quickAction(transcript) {
const text = transcript.toLowerCase().replace(/[.,!?;:…\s]+/gu, ' ').trim()
.replace(/^алиса\s+/, '').replace(/^пожалуйста\s+|\s+пожалуйста$/g, '');
if (/^(?:пауза|на паузу|(?:поставь|поставить)(?: музыку| воспроизведение)? на паузу|(?:приостанови|выключи|останови) (?:музыку|воспроизведение))$/.test(text)) {
return {
name: 'spotify_control',
args: { action: 'pause' },
done: 'Музыка на паузе.',
failure: 'Не удалось поставить музыку на паузу.',
success: result => result?.accepted === true && ['paused', 'stopped'].includes(result.status),
};
}
const match = text.match(/^(?:(?:поставь|установи|сделай) )?громкость(?: на| до)? (.+?)(?: ?%| процент(?:а|ов)?)?$/);
if (!match) return null;
const level = volumeLevel(match[1]);
if (level < 0 || level > 100) return null;
return {
name: 'station_volume',
args: { level },
done: `Громкость ${level}%.`,
failure: 'Не удалось изменить громкость колонки.',
success: result => result?.ok === true && result.level === level,
};
}