refactor: Improve code readability and structure across TTS modules
This commit is contained in:
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user