TTS redeems, skip button, per-source chat placement
- Redeem variations can have a TTS voice: the viewer's text is cleaned (links out, repeats collapsed, max length, blocked words -> not read), spoken as "<name> says: ..." and shown as the big paper note; the variation's sound is not played when TTS is on (picker greyed out) - Settings: TTS max length, say-the-name, blocked words (never sent to overlay pages: db.getOverlaySettings) - Dashboard "Skip current alert" -> /alerts/skip -> overlay skips it - db.migrate()/addColumn: new columns on existing databases - Chat: ?chat=left,top,width,height and ?chatflow=up per browser source (e.g. the Intermission panel); default unchanged Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b5a81bdb15
commit
4fda6060bf
16 changed files with 228 additions and 28 deletions
|
|
@ -4,6 +4,7 @@
|
|||
const db = require('./db');
|
||||
const alerts = require('./alerts');
|
||||
const dispatch = require('./dispatch');
|
||||
const tts = require('./tts');
|
||||
|
||||
// relative weight per rarity (Twitch does not publish its numbers; tune here).
|
||||
// chance of a variation = its weight / sum of the weights of the trigger's ENABLED variations
|
||||
|
|
@ -37,7 +38,7 @@ const STYLE = {
|
|||
'auto_reward:send_highlighted_message': 'message', // big taped paper note with the message
|
||||
'power_up:message_effect': 'message', // same as highlight
|
||||
};
|
||||
const LINE = { emote: 'gigantified an emote!', emote_rain: 'is celebrating!', message: 'highlighted:' };
|
||||
const LINE = { emote: 'gigantified an emote!', emote_rain: 'is celebrating!', message: 'highlighted:', tts: 'says:' };
|
||||
const emoteUrl = id => id ? `https://static-cdn.jtvnw.net/emoticons/v2/${encodeURIComponent(id)}/default/dark/3.0` : null;
|
||||
|
||||
function pick(variations) {
|
||||
|
|
@ -49,16 +50,42 @@ function pick(variations) {
|
|||
}
|
||||
|
||||
function toAlert(v, { user, input, emote }) {
|
||||
const style = STYLE[`${v.kind}:${v.key}`] || 'cassette';
|
||||
const spoken = !!(v.tts_voice_id && input); // TTS variations are shown as the big paper note
|
||||
const style = spoken ? 'message' : (STYLE[`${v.kind}:${v.key}`] || 'cassette');
|
||||
const line = spoken ? LINE.tts : LINE[style];
|
||||
return {
|
||||
type: 'redeem', kind: v.kind, key: v.key, style,
|
||||
user, reward: v.title, variation: v.name, rarity: v.rarity, input: input || null,
|
||||
// special styles have their own wording unless the caption was customised
|
||||
caption: style !== 'cassette' && v.caption === 'redeemed it! ♡' ? LINE[style] : v.caption,
|
||||
sound: v.sound || null, volume: v.volume, polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote),
|
||||
caption: style !== 'cassette' && v.caption === 'redeemed it! ♡' ? line : v.caption,
|
||||
sound: spoken ? null : (v.sound || null), volume: v.volume, // TTS on: the voice replaces the sound polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote),
|
||||
};
|
||||
}
|
||||
|
||||
// TTS: clean the viewer's text, speak it with the variation's saved voice, attach { tts, tts_ms }.
|
||||
// Never throws: on any problem the alert still goes out, just without speech.
|
||||
async function addSpeech(v, alert) {
|
||||
try {
|
||||
const voice = db.getTtsVoice(v.tts_voice_id);
|
||||
if (!voice || !alert.input) return;
|
||||
const s = db.getSettings();
|
||||
const { text, blocked } = tts.prepareViewerText(alert.input, { maxChars: s.tts_max_chars, blocklist: s.tts_blocklist });
|
||||
if (blocked) {
|
||||
console.log(`[tts] blocked message from ${alert.user}`);
|
||||
alert.input = '(message removed)';
|
||||
return;
|
||||
}
|
||||
alert.input = text; // the note shows what is read
|
||||
if (!text) return;
|
||||
const say = s.tts_say_name && alert.user ? `${alert.user} says: ${text}` : text;
|
||||
const out = await tts.synth(voice.config, say);
|
||||
alert.tts = out.url;
|
||||
alert.tts_ms = out.durationMs;
|
||||
} catch (e) {
|
||||
console.warn(`[tts] ${alert.user}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// legacy action event type for the actions system / activity log
|
||||
const LEGACY = { reward: 'channel_points', auto_reward: 'auto_reward', power_up: 'power_up' };
|
||||
|
||||
|
|
@ -72,7 +99,8 @@ function handle(kind, key, title, { user, input, emote }, raw) {
|
|||
return null;
|
||||
}
|
||||
const alert = toAlert(v, { user, input, emote });
|
||||
alerts.send(alert, raw);
|
||||
if (v.tts_voice_id && input) addSpeech(v, alert).then(() => alerts.send(alert, raw)); // speech first, then the alert
|
||||
else alerts.send(alert, raw);
|
||||
return alert;
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +108,12 @@ function handle(kind, key, title, { user, input, emote }, raw) {
|
|||
function test({ id, kind, key }) {
|
||||
const v = id ? db.getVariation(id) : pick(db.getVariationsFor(kind, key));
|
||||
if (!v) return false;
|
||||
const input = ['send_highlighted_message', 'message_effect'].includes(v.key) ? 'this is what a highlighted message looks like on stream!'
|
||||
const input = v.tts_voice_id ? 'Hydrate check! Also, nice shot, I was totally not camping that container.'
|
||||
: ['send_highlighted_message', 'message_effect'].includes(v.key) ? 'this is what a highlighted message looks like on stream!'
|
||||
: v.kind === 'reward' ? 'test input' : null;
|
||||
alerts.sendTestAlert(toAlert({ ...v, enabled: 1 }, { user: 'ChickenWhisperer', input, emote: v.kind === 'power_up' ? '25' : null })); // 25 = Kappa
|
||||
const alert = toAlert({ ...v, enabled: 1 }, { user: 'ChickenWhisperer', input, emote: v.kind === 'power_up' ? '25' : null }); // 25 = Kappa
|
||||
if (v.tts_voice_id) addSpeech(v, alert).then(() => alerts.sendTestAlert(alert));
|
||||
else alerts.sendTestAlert(alert);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue