refactor: Improve code readability and structure across TTS modules
Some checks failed
Backend CI / lint (push) Failing after 10s
Backend CI / test (push) Failing after 1m36s

This commit is contained in:
JSC
2025-09-21 19:07:32 +02:00
parent 35b857fd0d
commit acdf191a5a
8 changed files with 106 additions and 56 deletions

View File

@@ -2,11 +2,10 @@
import asyncio
import io
from typing import Any
from gtts import gTTS
from ..base import TTSProvider
from app.services.tts.base import TTSProvider
class GTTSProvider(TTSProvider):
@@ -22,7 +21,7 @@ class GTTSProvider(TTSProvider):
"""Return the default file extension for this provider."""
return "mp3"
async def generate_speech(self, text: str, **options: Any) -> bytes:
async def generate_speech(self, text: str, **options: str | bool | float) -> bytes:
"""Generate speech from text using Google TTS.
Args:
@@ -38,7 +37,7 @@ class GTTSProvider(TTSProvider):
slow = options.get("slow", False)
# Run TTS generation in thread pool since gTTS is synchronous
def _generate():
def _generate() -> bytes:
tts = gTTS(text=text, lang=lang, tld=tld, slow=slow)
fp = io.BytesIO()
tts.write_to_fp(fp)
@@ -64,7 +63,7 @@ class GTTSProvider(TTSProvider):
"vi", "yo", "zh", "zh-cn", "zh-tw", "zu",
]
def get_option_schema(self) -> dict[str, Any]:
def get_option_schema(self) -> dict[str, dict[str, str | list[str] | bool]]:
"""Return schema for GTTS-specific options."""
return {
"lang": {