ttstoy: speak only ..-triggered messages in accessibility mode

Accessibility mode read every message in the voice channel side chat and
treated `..` as an opt-out, so ordinary chat was always spoken. Members now
trigger speech explicitly with `..`, and messages without the trigger are
never read.
This commit is contained in:
2026-11-04 18:33:30 -06:00
parent 5ca8cea1a7
commit 84feec2e2a
4 changed files with 32 additions and 20 deletions
+19 -11
View File
@@ -2069,13 +2069,14 @@ class TtsToy(Cog):
@ttstoy_group.group(name="accessibility", aliases=["access"], invoke_without_command=True)
async def accessibility_group(self, ctx: commands.Context):
"""Accessibility mode: auto-read the VC side chat with per-speaker voices."""
"""Accessibility mode: speak VC side-chat messages marked with `..`, per-speaker voices."""
if ctx.invoked_subcommand is None:
on = await self.config.accessibility_mode()
engine = await self.config.accessibility_engine()
names = await self.config.accessibility_announce_names()
await ctx.send(
f"Accessibility mode is **{'ON' if on else 'OFF'}** (engine: `{engine}`).\n"
f"Start a message with `..` to have it read aloud.\n"
f"- `{ctx.clean_prefix}ttstoy accessibility start`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility stop`\n"
f"- `{ctx.clean_prefix}ttstoy accessibility engine <dectalk|piper>`\n"
@@ -2096,7 +2097,8 @@ class TtsToy(Cog):
"**Accessibility mode started.**\n"
f"- Engine: `{engine}`\n"
"- Emoji SFX disabled (emojis read as text instead)\n"
"- Auto-reads the side chat of the voice channel the bot is in (no command prefix needed)\n"
"- Reads the side chat of the voice channel the bot is in, but only messages that start with `..`\n"
"- Ordinary chat is never spoken\n"
"- Each speaker keeps a distinct voice so they can be told apart (saved between sessions)\n"
f"- Change your own voice with `{ctx.clean_prefix}ttstoy accessibility voice`"
)
@@ -2757,7 +2759,7 @@ class TtsToy(Cog):
return self.tts_queues[guild_id]
# ---------------------------------------------------------------------
# ACCESSIBILITY AUTO-READ (VC side-chat, no command prefix)
# ACCESSIBILITY SPEECH ('..' trigger in the VC side chat)
# ---------------------------------------------------------------------
def _access_voice_pool(self, engine: str) -> list:
"""Return the list of selectable voices for the given accessibility engine."""
@@ -2878,15 +2880,18 @@ class TtsToy(Cog):
except RuntimeError:
pass # no running loop (shouldn't happen in the listener path)
def _access_describe_message(self, message: discord.Message) -> Optional[str]:
"""Build the spoken text for an accessibility auto-read of a VC side-chat message.
def _access_describe_message(self, message: discord.Message, text: Optional[str] = None) -> Optional[str]:
"""Build the spoken text for an accessibility read of a VC side-chat message.
Returns the raw content to speak, or None if there is nothing to read.
`text` is the message content after the '..' trigger, which the listener
strips before calling this. When it is omitted the whole message content
is used. Returns the text to speak, or None if there is nothing to read.
Attachments/embeds/links are announced instead of read:
"<username> sent a link" / "sent an image" / "sent a file"
No emoji, no em-dash.
"""
name = message.author.display_name
text = message.content if text is None else text
# Attachments take priority: classify image vs generic file
if message.attachments:
@@ -2901,10 +2906,10 @@ class TtsToy(Cog):
return f"{name} sent a file"
# A link in the text (or a link-only embed) is announced, not read
if URL_PATTERN.search(message.content or "") or message.embeds:
if URL_PATTERN.search(text or "") or message.embeds:
return f"{name} sent a link"
content = (message.content or "").strip()
content = (text or "").strip()
if not content:
return None
# No emoji anywhere: strip unicode emoji and custom/named emoji tokens.
@@ -3011,11 +3016,14 @@ class TtsToy(Cog):
if ctx.valid:
return
# Messages starting with '..' are intentionally not read aloud.
if (message.content or "").lstrip().startswith(".."):
# Opt-in per message: ordinary chat is never spoken. Only a message
# a member marks with the '..' trigger is read aloud.
raw = (message.content or "").lstrip()
if not raw.startswith(".."):
return
requested = raw[2:].lstrip()
spoken = self._access_describe_message(message)
spoken = self._access_describe_message(message, requested)
if not spoken:
return
+10 -6
View File
@@ -1,6 +1,6 @@
# TtsToy Accessibility
Accessibility mode reads messages from the text chat attached to the voice channel the bot is in, without requiring a command prefix. It exists so a member who cannot read the side chat can follow it by listening.
Accessibility mode speaks messages from the text chat attached to the voice channel the bot is in, but only the ones a member marks with the `..` trigger. Ordinary chat is never spoken. It exists so a member who cannot read the side chat can follow what a speaker deliberately marks for listening.
## Enabling
@@ -12,6 +12,10 @@ Accessibility mode reads messages from the text chat attached to the voice chann
Start and stop require the bot owner. Engine and name announcements also require the owner. Members choose their own voice with `[p]ttstoy accessibility voice`, which needs no permission.
## The `..` trigger
A message is spoken only when it starts with `..`. The trigger and the whitespace after it are dropped before speaking, so `..good game` is read as "good game". A message without the trigger is ignored, so normal conversation is never spoken.
## Conditions for a message to be read
All of these must hold:
@@ -21,7 +25,7 @@ All of these must hold:
3. The message is in that voice channel's text chat, which Discord exposes as a text channel with the same ID as the voice channel.
4. The message is not from a bot.
5. The message does not parse as a command, so `[p]tts` invocations are not read twice.
6. The message does not start with `..`, which is the opt-out prefix for members.
6. The message starts with `..`.
## What gets spoken
@@ -31,7 +35,7 @@ All of these must hold:
| Attachment that is an image | "<name> sent an image" |
| Other attachment | "<name> sent a file" |
| A URL anywhere in the text, or any embed | "<name> sent a link" |
| Only emoji, or only whitespace | Nothing |
| `..` alone, only emoji after it, or only whitespace | Nothing |
| Obvious keyboard mash or spam | Nothing |
The nonsense filter is conservative. It drops messages with a single character repeated over most of the text, one short token repeated five or more times, a long alphabetic run with almost no vowels, very low character variety over a long message, or a short unit repeated to fill the message. Short real messages such as "ok", "lol" or "brb" pass through.
@@ -64,9 +68,9 @@ Starting or stopping accessibility mode resets the name tracker and keeps stored
## Engine behavior
In accessibility mode, `[p]tts` also forces the accessibility engine and strips emoji, so a member invoking the command gets the same voice treatment as auto-read messages.
In accessibility mode, `[p]tts` also forces the accessibility engine and strips emoji, so a member invoking the command gets the same voice treatment as `..` triggered messages.
Auto-read uses the same rendering path as normal speech and the same per-guild queue. Music pauses for the clip and resumes afterward, using the queue restore logic described in [YTAudio](YTAudio).
Triggered speech uses the same rendering path as normal speech and the same per-guild queue. Music pauses for the clip and resumes afterward, using the queue restore logic described in [YTAudio](YTAudio).
The generated files are named `access-<message id>.mp3` in the cog data directory and are removed by the hourly cleanup.
@@ -80,7 +84,7 @@ The generated files are named `access-<message id>.mp3` in the cog data director
## Operational notes
- The bot must stay in the voice channel. If it is pulled out to show a mute notice, auto-read stops until it returns.
- The bot must stay in the voice channel. If it is pulled out to show a mute notice, triggered speech stops until it returns.
- Only one voice channel is served at a time, the one the bot occupies.
- The queue is per guild, so a long clip delays subsequent messages.
- Voice names are matched case-insensitively.
+2 -2
View File
@@ -125,8 +125,8 @@ Group `[p]ttstoy accessibility`, alias `[p]ttstoy access`.
| Command | Permission | Description |
|---|---|---|
| `[p]ttstoy accessibility` | Any member | Shows mode, engine and name announcement state |
| `[p]ttstoy accessibility start` | Owner | Enables auto-read |
| `[p]ttstoy accessibility stop` | Owner | Disables auto-read |
| `[p]ttstoy accessibility start` | Owner | Enables the `..` speak trigger |
| `[p]ttstoy accessibility stop` | Owner | Disables the `..` speak trigger |
| `[p]ttstoy accessibility engine` | Owner | Shows or sets `dectalk` or `piper`, alias `tts` |
| `[p]ttstoy accessibility names` | Owner | Shows or sets whether names are announced, alias `announcenames` |
| `[p]ttstoy accessibility voice [name]` | Any member, guild only | Shows the voice list or sets your voice, `auto` clears |
+1 -1
View File
@@ -1,6 +1,6 @@
# TtsToy Overview
Text to speech with six interchangeable engines, per-user cloned voices, emoji triggered sound effects, an accessibility mode that reads voice channel text chat aloud, and a companion web UI.
Text to speech with six interchangeable engines, per-user cloned voices, emoji triggered sound effects, an accessibility mode that reads `..`-prefixed voice channel text chat aloud, and a companion web UI.
The cog generates an MP3 for every request, posts it in the channel, and plays it in voice chat when the author is connected.