diff --git a/ttstoy/ttstoy.py b/ttstoy/ttstoy.py index 9a083de..ba099f4 100644 --- a/ttstoy/ttstoy.py +++ b/ttstoy/ttstoy.py @@ -2151,18 +2151,12 @@ class TtsToy(Cog): if voice is None: current = self._access_voice_for(ctx.guild.id, ctx.author.id, engine) current_label = self._access_voice_label(engine, current) - lines = [] - for v in pool: - lbl = self._access_voice_label(engine, v) - marker = ">" if v == current else " " - lines.append(f"{marker} {lbl}") - block = "\n".join(lines) + options = "\n".join(self._access_voice_label(engine, v) for v in pool) return await ctx.send( - f"**Accessibility voices** (engine: `{engine}`)\n" - f"Your voice: `{current_label}` (marked with `>` below)\n" - f"```\n{block}\n```\n" - f"Set yours: `{ctx.clean_prefix}ttstoy accessibility voice ` " - f"(or `auto`)" + f"Current voice: {current_label}\n\n" + f"list\n\n" + f"{options}\n\n" + f"{ctx.clean_prefix}ttstoy accessibility voice (voice name)" ) choice = voice.strip() @@ -2744,41 +2738,45 @@ class TtsToy(Cog): def _access_voice_label(engine: str, voice: str) -> str: """Short, user-facing name for a pool voice. - For piper, strip the `en_US-` locale prefix so `en_US-amy-medium` - displays and is typed as `amy-medium`. DECTalk names are already short. + For piper, strip the `en_US-` locale prefix AND the quality suffix + (`-medium`/`-low`/`-high`) so `en_US-hfc_male-medium` displays and is + typed as `hfc_male`. DECTalk names are already short. """ if engine == "piper" and voice: - return re.sub(r"^[a-z]{2}_[A-Z]{2}-", "", voice) + name = re.sub(r"^[a-z]{2}_[A-Z]{2}-", "", voice) + name = re.sub(r"-(low|medium|high)$", "", name) + return name return voice def _access_match_voice(self, engine: str, choice: str) -> Optional[str]: """Resolve a user-typed voice name to a full pool id, or None. - Accepts, case-insensitively: the full id (`en_US-amy-medium`), the - locale-stripped label (`amy-medium`), or the bare speaker name (`amy`, - matching the first pool voice whose label starts with it). This is what - lets people type `amy` instead of `en_US-amy-medium`. + Accepts, case-insensitively: the simplified name (`hfc_male`), the + locale-stripped form with quality (`hfc_male-medium`), the full id + (`en_US-hfc_male-medium`), or an unambiguous prefix. """ pool = self._access_voice_pool(engine) c = choice.strip().lower() + + def locale_stripped(v): + return re.sub(r"^[a-z]{2}_[A-Z]{2}-", "", v).lower() if engine == "piper" else v.lower() + # 1) exact full id for v in pool: if v.lower() == c: return v - # 2) exact locale-stripped label + # 2) exact simplified label (speaker only, e.g. 'hfc_male') for v in pool: if self._access_voice_label(engine, v).lower() == c: return v - # 3) bare speaker name: label up to the first '-' (piper) or whole name + # 3) exact locale-stripped form with quality (e.g. 'hfc_male-medium') for v in pool: - label = self._access_voice_label(engine, v).lower() - base = label.split("-", 1)[0] - if base == c: - return v - # 4) prefix match as a last resort (e.g. 'less' -> lessac-medium) - for v in pool: - if self._access_voice_label(engine, v).lower().startswith(c): + if locale_stripped(v) == c: return v + # 4) unambiguous prefix of the simplified label (e.g. 'kris' -> kristin) + matches = [v for v in pool if self._access_voice_label(engine, v).lower().startswith(c)] + if len(matches) == 1: + return matches[0] return None def _access_voice_for(self, guild_id: int, user_id: int, engine: str) -> str: