TTS blocklist: starter list of slurs/TOS phrases, whole-word matching
- src/tts-blocklist.txt: slurs, self-harm/threat phrases, sexual violence, hate slogans (no normal swearing); merged into Settings once (tts_blocklist_seeded), editable there afterwards - Matching is now whole words/phrases with plurals, look-alike swaps and spaced-out letters, so raccoon / spicy / therapist / grape are fine Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cf90b6be54
commit
9e356b0875
5 changed files with 90 additions and 11 deletions
|
|
@ -139,8 +139,9 @@ Chat (`?parts=chat`) is `public/chat/chat.css` + `public/chat/chat.js` (window.H
|
||||||
|
|
||||||
Builder page to make named TTS voices, used by redeem variations (Redeems page: "TTS: <voice>" per variation).
|
Builder page to make named TTS voices, used by redeem variations (Redeems page: "TTS: <voice>" per variation).
|
||||||
- Redeem with a TTS voice + viewer text: `redeems.addSpeech()` cleans the text (`tts.prepareViewerText`: links out,
|
- Redeem with a TTS voice + viewer text: `redeems.addSpeech()` cleans the text (`tts.prepareViewerText`: links out,
|
||||||
repeats collapsed, cut to `settings.tts_max_chars` at a word, `settings.tts_blocklist` -> nothing read, note says
|
repeats collapsed, cut to `settings.tts_max_chars` at a word, `settings.tts_blocklist` -> nothing read, letter says
|
||||||
"(message removed)"), synthesizes "<user> says: <text>" (`tts_say_name`), and only then sends the alert with
|
"(message removed)"; whole-word matching with plurals, look-alike swaps and spaced-out letters; starter list
|
||||||
|
`src/tts-blocklist.txt` is merged into the setting once, `tts_blocklist_seeded`), synthesizes "<user> says: <text>" (`tts_say_name`), and only then sends the alert with
|
||||||
`tts` (URL), `tts_ms`, `tts_env` (loudness per 40 ms, `tts.loudness()`) and `tts_prefix` (words said before the message).
|
`tts` (URL), `tts_ms`, `tts_env` (loudness per 40 ms, `tts.loudness()`) and `tts_prefix` (words said before the message).
|
||||||
Shown as the envelope letter (style `tts`, `public/alerts/fx.js` envelope(), CSS in fx.css): flap opens, the letter rises
|
Shown as the envelope letter (style `tts`, `public/alerts/fx.js` envelope(), CSS in fx.css): flap opens, the letter rises
|
||||||
out and settles in front ~80px from the top, words ink in as spoken (timing estimated from tts_env; if the voice
|
out and settles in front ~80px from the top, words ink in as spoken (timing estimated from tts_env; if the voice
|
||||||
|
|
|
||||||
17
src/db.js
17
src/db.js
|
|
@ -12,6 +12,7 @@ function init() {
|
||||||
createSchema();
|
createSchema();
|
||||||
migrate();
|
migrate();
|
||||||
seedSettings();
|
seedSettings();
|
||||||
|
seedTtsBlocklist();
|
||||||
seedVariations();
|
seedVariations();
|
||||||
console.log(`[db] Initialised — path: ${DB_PATH}`);
|
console.log(`[db] Initialised — path: ${DB_PATH}`);
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +137,20 @@ function migrate() {
|
||||||
addColumn('settings', 'tts_max_chars', 'INTEGER DEFAULT 200'); // longer redeem text is cut
|
addColumn('settings', 'tts_max_chars', 'INTEGER DEFAULT 200'); // longer redeem text is cut
|
||||||
addColumn('settings', 'tts_blocklist', "TEXT DEFAULT ''"); // words/phrases, one per line or comma-separated
|
addColumn('settings', 'tts_blocklist', "TEXT DEFAULT ''"); // words/phrases, one per line or comma-separated
|
||||||
addColumn('settings', 'tts_say_name', 'INTEGER DEFAULT 1'); // "<name> says: ..." before the message
|
addColumn('settings', 'tts_say_name', 'INTEGER DEFAULT 1'); // "<name> says: ..." before the message
|
||||||
|
addColumn('settings', 'tts_blocklist_seeded', 'INTEGER DEFAULT 0'); // starter list copied in once
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the starter TTS blocklist (src/tts-blocklist.txt) into the settings ONCE; after that it is the user's list
|
||||||
|
// (clearing or editing it in Settings is respected).
|
||||||
|
function seedTtsBlocklist() {
|
||||||
|
const s = db.prepare('SELECT tts_blocklist, tts_blocklist_seeded FROM settings WHERE id = 1').get();
|
||||||
|
if (!s || s.tts_blocklist_seeded) return;
|
||||||
|
const starter = require('fs').readFileSync(require('path').join(__dirname, 'tts-blocklist.txt'), 'utf8')
|
||||||
|
.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
||||||
|
const mine = String(s.tts_blocklist || '').split(/[\n,]/).map(w => w.trim()).filter(Boolean);
|
||||||
|
const merged = [...mine, ...starter.filter(w => !mine.some(m => m.toLowerCase() === w.toLowerCase()))];
|
||||||
|
db.prepare('UPDATE settings SET tts_blocklist = ?, tts_blocklist_seeded = 1 WHERE id = 1').run(merged.join('\n'));
|
||||||
|
console.log(`[db] TTS blocklist: added ${merged.length - mine.length} starter words`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function seedSettings() {
|
function seedSettings() {
|
||||||
|
|
@ -190,7 +205,7 @@ function getSettings() {
|
||||||
|
|
||||||
// what overlay pages get: everything except server-only values (the overlay URL is public)
|
// what overlay pages get: everything except server-only values (the overlay URL is public)
|
||||||
function getOverlaySettings() {
|
function getOverlaySettings() {
|
||||||
const { tts_blocklist, ...rest } = getSettings();
|
const { tts_blocklist, tts_blocklist_seeded, ...rest } = getSettings();
|
||||||
return rest;
|
return rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
56
src/tts-blocklist.txt
Normal file
56
src/tts-blocklist.txt
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# Starter TTS blocklist: slurs and phrases that can get a channel in trouble under Twitch's rules when read aloud.
|
||||||
|
# Copied ONCE into Settings -> TTS redeems -> Blocked words (on first start after this was added); edit it there.
|
||||||
|
# Matching (src/tts.js prepareViewerText): whole words, not case-sensitive, plurals (-s/-es/-z) included,
|
||||||
|
# simple swaps (0->o 1->i 3->e 4->a 5->s 7->t @->a $->s) and spaced-out letters (k y s) caught.
|
||||||
|
# Normal swearing is deliberately not here.
|
||||||
|
|
||||||
|
# racial / ethnic slurs
|
||||||
|
nigger
|
||||||
|
nigga
|
||||||
|
sandnigger
|
||||||
|
chink
|
||||||
|
gook
|
||||||
|
spic
|
||||||
|
wetback
|
||||||
|
beaner
|
||||||
|
kike
|
||||||
|
raghead
|
||||||
|
towelhead
|
||||||
|
coon
|
||||||
|
jigaboo
|
||||||
|
porch monkey
|
||||||
|
paki
|
||||||
|
|
||||||
|
# homophobic / transphobic
|
||||||
|
faggot
|
||||||
|
fag
|
||||||
|
dyke
|
||||||
|
tranny
|
||||||
|
shemale
|
||||||
|
|
||||||
|
# ableist
|
||||||
|
retard
|
||||||
|
retarded
|
||||||
|
|
||||||
|
# self-harm / threats
|
||||||
|
kys
|
||||||
|
kill yourself
|
||||||
|
kill urself
|
||||||
|
kill your self
|
||||||
|
neck yourself
|
||||||
|
hang yourself
|
||||||
|
go die
|
||||||
|
|
||||||
|
# sexual violence / minors
|
||||||
|
rape
|
||||||
|
rapist
|
||||||
|
pedo
|
||||||
|
pedophile
|
||||||
|
child porn
|
||||||
|
|
||||||
|
# hate slogans
|
||||||
|
heil hitler
|
||||||
|
sieg heil
|
||||||
|
1488
|
||||||
|
white power
|
||||||
|
gas the jews
|
||||||
21
src/tts.js
21
src/tts.js
|
|
@ -87,7 +87,15 @@ function cleanText(text) {
|
||||||
// Returns { text, blocked }. blocked = a blocklist word was found: do not read anything.
|
// Returns { text, blocked }. blocked = a blocklist word was found: do not read anything.
|
||||||
const LEET = { 0: 'o', 1: 'i', 3: 'e', 4: 'a', 5: 's', 7: 't', '@': 'a', $: 's', '!': 'i' };
|
const LEET = { 0: 'o', 1: 'i', 3: 'e', 4: 'a', 5: 's', 7: 't', '@': 'a', $: 's', '!': 'i' };
|
||||||
function parseBlocklist(list) {
|
function parseBlocklist(list) {
|
||||||
return String(list || '').split(/[\n,]/).map(w => w.trim().toLowerCase()).filter(Boolean);
|
return String(list || '').split(/[\n,]/).map(w => w.trim().toLowerCase()).filter(w => w && !w.startsWith('#'));
|
||||||
|
}
|
||||||
|
// lowercase, look-alike swaps, spaced-out letters joined ("k y s" -> "kys"), only letters/digits, single spaces
|
||||||
|
function normalizeForMatch(text) {
|
||||||
|
return ' ' + String(text).toLowerCase()
|
||||||
|
.replace(/[013457@$!]/g, c => LEET[c] || c)
|
||||||
|
.replace(/(^|[^a-z0-9\u00c0-\u024f])((?:[a-z][\s.\-_*]+){2,}[a-z])(?![a-z])/g, (_, pre, letters) => pre + letters.replace(/[^a-z]/g, ''))
|
||||||
|
.replace(/([a-z])\1{2,}/g, '$1') // niiiice -> nice
|
||||||
|
.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ').trim() + ' ';
|
||||||
}
|
}
|
||||||
function prepareViewerText(input, { maxChars = 200, blocklist = '' } = {}) {
|
function prepareViewerText(input, { maxChars = 200, blocklist = '' } = {}) {
|
||||||
let t = cleanText(input)
|
let t = cleanText(input)
|
||||||
|
|
@ -98,13 +106,12 @@ function prepareViewerText(input, { maxChars = 200, blocklist = '' } = {}) {
|
||||||
.replace(/\s+/g, ' ').trim();
|
.replace(/\s+/g, ' ').trim();
|
||||||
const max = Math.max(20, Math.min(MAX_CHARS, maxChars | 0 || 200));
|
const max = Math.max(20, Math.min(MAX_CHARS, maxChars | 0 || 200));
|
||||||
if (t.length > max) t = t.slice(0, max).replace(/\s+\S*$/, '') + '…';
|
if (t.length > max) t = t.slice(0, max).replace(/\s+\S*$/, '') + '…';
|
||||||
const plain = t.toLowerCase().replace(/[013457@$!]/g, c => LEET[c] || c);
|
// whole words/phrases only (so "raccoon", "spicy", "therapist" are fine), plurals included
|
||||||
const words = ' ' + plain.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ') + ' ';
|
const hay = normalizeForMatch(t);
|
||||||
const squashed = plain.replace(/[^a-z\u00c0-\u024f]+/g, '');
|
|
||||||
const blocked = parseBlocklist(blocklist).some(w => {
|
const blocked = parseBlocklist(blocklist).some(w => {
|
||||||
const ww = w.replace(/[013457@$!]/g, c => LEET[c] || c);
|
const term = normalizeForMatch(w).trim();
|
||||||
return ww.length >= 4 ? squashed.includes(ww.replace(/[^a-z\u00c0-\u024f]+/g, '')) // longer words: also when spaced out
|
if (!term) return false;
|
||||||
: words.includes(' ' + ww.replace(/[^a-z0-9\u00c0-\u024f]+/g, ' ').trim() + ' ');
|
return new RegExp(` ${term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:s|es|z)? `).test(hay);
|
||||||
});
|
});
|
||||||
return { text: t, blocked };
|
return { text: t, blocked };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
<label>
|
<label>
|
||||||
Blocked words
|
Blocked words
|
||||||
<textarea name="tts_blocklist" rows="4" placeholder="one per line, or comma-separated"><%= settings.tts_blocklist %></textarea>
|
<textarea name="tts_blocklist" rows="4" placeholder="one per line, or comma-separated"><%= settings.tts_blocklist %></textarea>
|
||||||
<small>If a message contains one, nothing is read and the note shows "(message removed)". Not case-sensitive; also catches simple swaps like 0→o, $→s, and spaced-out letters for words of 4+ letters. Links are always removed.</small>
|
<small>If a message contains one, nothing is read and the letter shows "(message removed)". Whole words and phrases, not case-sensitive, plurals included; also catches swaps like 0→o, $→s and spaced-out letters (k y s). Starts with a list of slurs and Twitch-risky phrases (normal swearing is allowed); edit freely. Links are always removed.</small>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<h3>Custom CSS / JS</h3>
|
<h3>Custom CSS / JS</h3>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue