aboutsummaryrefslogtreecommitdiff
path: root/app/converter/clients/speakers.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-26 01:43:41 -0400
committerhistoria <historiavg@proton.me>2026-08-26 01:43:41 -0400
commitacbd9ff2c91182d96c57ffb57bee6e9b3fcbcbd4 (patch)
treee336c11f2a57cff5566e249aa5d5477a3dc63c55 /app/converter/clients/speakers.py
parent104a0d65c1ba37847c15b64212b7fec8ba371ccb (diff)
downloadtts-audiobook-generator-acbd9ff2c91182d96c57ffb57bee6e9b3fcbcbd4.tar.gz
refactor: split tts.py into per-backend packages
Diffstat (limited to 'app/converter/clients/speakers.py')
-rw-r--r--app/converter/clients/speakers.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/converter/clients/speakers.py b/app/converter/clients/speakers.py
new file mode 100644
index 0000000..eecd52a
--- /dev/null
+++ b/app/converter/clients/speakers.py
@@ -0,0 +1,57 @@
+"""Qwen3-TTS built-in speaker names and their wire (display) forms."""
+
+from typing import Optional
+
+from .. import config
+
+# Built-in CustomVoice speaker names for the Qwen3-TTS family. Shared by the
+# qwen-tts demo backend (config.SPEAKER, the qwen setup/form) and the
+# audio.cpp audiocpp backend's CustomVoice entry (the Convert form's Speaker
+# picker). Entries are the canonical/config form; speaker_display_name()
+# maps them to the wire (display) form via SPEAKER_DISPLAY_NAMES below.
+QWEN3_TTS_SPEAKERS = ("Vivian", "Serena", "Uncle_Fu", "Dylan", "Eric",
+ "Ryan", "Aiden", "Ono_Anna", "Sohee")
+
+# Canonical speaker names -> display names used by the qwen-tts demo.
+SPEAKER_DISPLAY_NAMES = {
+ "ryan": "Ryan",
+ "serena": "Serena",
+ "vivian": "Vivian",
+ "uncle_fu": "Uncle Fu",
+ "aiden": "Aiden",
+ "ono_anna": "Ono Anna",
+ "sohee": "Sohee",
+ "eric": "Eric",
+ "dylan": "Dylan",
+}
+
+
+def speaker_display_name_for(name: str) -> str:
+ """Return the wire (display) form of a Qwen3-TTS CustomVoice speaker NAME.
+
+ Accepts either the canonical/config form (e.g. "uncle_fu", "Uncle_Fu")
+ or the display form ("Uncle Fu"), case-insensitively; unknown names pass
+ through unchanged. Used by AudioCppTTSClient to normalize the --voice /
+ Speaker-picker value into what audiocpp_server expects in the request's
+ voice field.
+ """
+ return SPEAKER_DISPLAY_NAMES.get((name or "").lower(), name)
+
+
+def is_builtin_speaker(name: Optional[str]) -> bool:
+ """True when NAME is one of the Qwen3-TTS CustomVoice built-in speakers.
+
+ Matches case-insensitively across the canonical ("Uncle_Fu"), display
+ ("Uncle Fu") and shorthand ("uncle_fu") forms, so the --voice flag and
+ the Convert form's Speaker picker resolve to the same set.
+ """
+ if not name:
+ return False
+ norm = name.lower().replace("_", " ").replace("-", " ")
+ return any(norm == speaker.lower().replace("_", " ")
+ for speaker in QWEN3_TTS_SPEAKERS)
+
+
+def speaker_display_name() -> str:
+ """Return the display name for the configured custom speaker."""
+ return speaker_display_name_for(config.SPEAKER)