ttstoy: add an accessibility toggle for announcing posted media
Accessibility mode always announced images, files and links posted without the `..` trigger. Owners can now turn that off with `ttstoy accessibility posts <on|off>`, leaving only triggered messages read aloud.
This commit is contained in:
+43
-5
@@ -427,6 +427,7 @@ class TtsToy(Cog):
|
||||
accessibility_mode=False,
|
||||
accessibility_engine="dectalk", # "dectalk" or "piper" for auto-read + forced TTS
|
||||
accessibility_announce_names=True, # say "Name said:" before a speaker's message
|
||||
accessibility_announce_posts=True, # announce images/files/links posted without the trigger
|
||||
vox_pack="vox",
|
||||
webui_tts_channel_id=None, # channel to post web UI TTS transcripts/audio
|
||||
webui_public_url="https://ttstoy.kingstons-scrapyard.net", # public URL shown in login DMs
|
||||
@@ -2074,13 +2075,16 @@ class TtsToy(Cog):
|
||||
on = await self.config.accessibility_mode()
|
||||
engine = await self.config.accessibility_engine()
|
||||
names = await self.config.accessibility_announce_names()
|
||||
posts = await self.config.accessibility_announce_posts()
|
||||
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 (images, files and links are announced automatically).\n"
|
||||
f"Start a message with `..` to have it read aloud"
|
||||
f"{' (images, files and links are announced automatically)' if posts else ''}.\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"
|
||||
f"- `{ctx.clean_prefix}ttstoy accessibility names <on|off>` (currently **{'ON' if names else 'OFF'}**)\n"
|
||||
f"- `{ctx.clean_prefix}ttstoy accessibility posts <on|off>` (currently **{'ON' if posts else 'OFF'}**)\n"
|
||||
f"- `{ctx.clean_prefix}ttstoy accessibility voice [name]`"
|
||||
)
|
||||
|
||||
@@ -2098,8 +2102,12 @@ class TtsToy(Cog):
|
||||
f"- Engine: `{engine}`\n"
|
||||
"- Emoji SFX disabled (emojis read as text instead)\n"
|
||||
"- Reads the side chat of the voice channel the bot is in, but only messages that start with `..`\n"
|
||||
+ (
|
||||
"- Images, files and links are still announced without the trigger\n"
|
||||
"- Ordinary text is never spoken\n"
|
||||
if await self.config.accessibility_announce_posts()
|
||||
else "- Images, files and links are only announced when triggered with `..`\n"
|
||||
)
|
||||
+ "- Ordinary text 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`"
|
||||
)
|
||||
@@ -2163,6 +2171,32 @@ class TtsToy(Cog):
|
||||
f"**Speaker names {'will' if enabled else 'will not'} be read** before each message."
|
||||
)
|
||||
|
||||
@accessibility_group.command(name="posts", aliases=["announceposts"])
|
||||
@commands.is_owner()
|
||||
async def accessibility_posts(self, ctx: commands.Context, state: Optional[str] = None):
|
||||
"""
|
||||
Show or set whether posted images, files and links are announced.
|
||||
|
||||
- `[p]ttstoy accessibility posts` -> show the current setting
|
||||
- `[p]ttstoy accessibility posts on` -> announce them without the `..` trigger
|
||||
- `[p]ttstoy accessibility posts off` -> stay silent unless triggered with `..`
|
||||
"""
|
||||
if state is None:
|
||||
current = await self.config.accessibility_announce_posts()
|
||||
return await ctx.send(
|
||||
f"Announcing posted images, files and links: **{'ON' if current else 'OFF'}**\n"
|
||||
f"Set with `{ctx.clean_prefix}ttstoy accessibility posts <on|off>`"
|
||||
)
|
||||
|
||||
state = state.strip().lower()
|
||||
if state not in ("on", "off"):
|
||||
return await ctx.send("Use `on` or `off`.")
|
||||
enabled = state == "on"
|
||||
await self.config.accessibility_announce_posts.set(enabled)
|
||||
await ctx.send(
|
||||
f"**Posted images, files and links {'will' if enabled else 'will not'} be announced**."
|
||||
)
|
||||
|
||||
@accessibility_group.command(name="voice")
|
||||
@commands.guild_only()
|
||||
async def accessibility_voice(self, ctx: commands.Context, *, voice: Optional[str] = None):
|
||||
@@ -3030,12 +3064,16 @@ class TtsToy(Cog):
|
||||
|
||||
# Opt-in per message: ordinary text is never spoken. Only a message
|
||||
# a member marks with the '..' trigger is read aloud, except for
|
||||
# images, files and links, which are announced without it so a
|
||||
# listener still hears that something was posted.
|
||||
# images, files and links, which are announced without it (when
|
||||
# `accessibility posts` is on) so a listener still hears that
|
||||
# something was posted.
|
||||
raw = (message.content or "").lstrip()
|
||||
if raw.startswith(".."):
|
||||
requested = raw[2:].lstrip()
|
||||
elif self._access_is_post_announcement(message):
|
||||
elif (
|
||||
await self.config.accessibility_announce_posts()
|
||||
and self._access_is_post_announcement(message)
|
||||
):
|
||||
requested = raw
|
||||
else:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user