Cleanup SentenceBoundary support (#396)

- Default to SentenceBoundary
- Modify boundary argument to lowercase to match other options.
- Drop merge_cues support as SentenceBoundary renders it obsolete.

Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
rany2
2025-08-05 14:30:30 +03:00
committed by GitHub
parent 645c207cfd
commit c78e49d28e
5 changed files with 17 additions and 61 deletions

View File

@@ -19,14 +19,12 @@ from typing import (
Literal,
Optional,
Tuple,
TypedDict,
Union,
)
from xml.sax.saxutils import escape, unescape
import aiohttp
import certifi
from typing_extensions import NotRequired, Unpack
from .constants import DEFAULT_VOICE, SEC_MS_GEC_VERSION, WSS_HEADERS, WSS_URL
from .data_classes import TTSConfig
@@ -311,19 +309,12 @@ def ssml_headers_plus_data(request_id: str, timestamp: str, ssml: str) -> str:
)
class CommunicateRequest(TypedDict):
"""
A class to communicate with the service.
"""
Boundary: NotRequired[Literal["WordBoundary", "SentenceBoundary"]]
class Communicate:
"""
Communicate with the service.
"""
# pylint: disable=too-many-arguments
def __init__(
self,
text: str,
@@ -332,24 +323,13 @@ class Communicate:
rate: str = "+0%",
volume: str = "+0%",
pitch: str = "+0Hz",
boundary: Literal["WordBoundary", "SentenceBoundary"] = "SentenceBoundary",
connector: Optional[aiohttp.BaseConnector] = None,
proxy: Optional[str] = None,
connect_timeout: Optional[int] = 10,
receive_timeout: Optional[int] = 60,
**kwargs: Unpack[CommunicateRequest],
):
"""
Args:
boundary (str): The boundary to use for the TTS.
Defaults to "WordBoundary".
Valid values are "WordBoundary" and "SentenceBoundary".
If "WordBoundary", the TTS will return a word boundary for each word.
If "SentenceBoundary", the TTS will return a sentence boundary for each sentence.
Which is more friendly to Chinese users.
"""
# Validate TTS settings and store the TTSConfig object.
boundary = kwargs.get("Boundary", "WordBoundary")
self.tts_config = TTSConfig(voice, rate, volume, pitch, boundary)
# Validate the text parameter.