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), }; } if (text === 'громче' || text === 'тише') return { name: 'station_volume', args: { delta: text === 'громче' ? 10 : -10 }, done: 'Готово.', failure: 'Не удалось изменить громкость.', success: result => result?.ok === true, }; const playback = { 'продолжи': 'resume', 'продолжай': 'resume', 'играй': 'resume', 'дальше':'next', 'следующий трек':'next', 'назад':'previous', 'предыдущий трек':'previous' }[text]; if (playback) return { name: 'spotify_control', args: { action: playback }, done: 'Готово.', failure: 'Не удалось выполнить команду Spotify.', success: result => result?.accepted === true, }; 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, }; }