style: Format code for consistency and readability across TTS modules

This commit is contained in:
JSC
2025-09-21 18:05:20 +02:00
parent 50eeae4c62
commit d3b6e90262
11 changed files with 36 additions and 27 deletions

View File

@@ -33,6 +33,7 @@ class TTSService:
Args:
session: Database session
"""
self.session = session
self.sound_repo = SoundRepository(session)
@@ -51,6 +52,7 @@ class TTSService:
Args:
provider: TTS provider instance
"""
self.providers[provider.name] = provider
@@ -83,6 +85,7 @@ class TTSService:
Raises:
ValueError: If provider not found or text too long
Exception: If request creation fails
"""
provider_not_found_msg = f"Provider '{provider}' not found"
if provider not in self.providers:
@@ -164,7 +167,7 @@ class TTSService:
pass
async def _generate_tts_sync(
self, text: str, provider: str, user_id: int, options: dict[str, Any]
self, text: str, provider: str, user_id: int, options: dict[str, Any],
) -> Sound:
"""Generate TTS using a synchronous approach."""
# Generate the audio using the provider (avoid async issues by doing it directly)
@@ -200,7 +203,7 @@ class TTSService:
# Create Sound record with proper metadata
sound = await self._create_sound_record_complete(
original_path, text, provider, user_id
original_path, text, provider, user_id,
)
# Normalize the sound
@@ -209,7 +212,7 @@ class TTSService:
return sound
async def get_user_tts_history(
self, user_id: int, limit: int = 50, offset: int = 0
self, user_id: int, limit: int = 50, offset: int = 0,
) -> list[TTS]:
"""Get TTS history for a user.
@@ -220,12 +223,13 @@ class TTSService:
Returns:
List of TTS records
"""
result = await self.tts_repo.get_by_user_id(user_id, limit, offset)
return list(result)
async def _create_sound_record(
self, audio_path: Path, text: str, provider: str, user_id: int, file_hash: str
self, audio_path: Path, text: str, provider: str, user_id: int, file_hash: str,
) -> Sound:
"""Create a Sound record for the TTS audio."""
# Get audio metadata
@@ -253,7 +257,7 @@ class TTSService:
return sound
async def _create_sound_record_simple(
self, audio_path: Path, text: str, provider: str, user_id: int
self, audio_path: Path, text: str, provider: str, user_id: int,
) -> Sound:
"""Create a Sound record for the TTS audio with minimal processing."""
# Create sound data with basic info
@@ -278,7 +282,7 @@ class TTSService:
return sound
async def _create_sound_record_complete(
self, audio_path: Path, text: str, provider: str, user_id: int
self, audio_path: Path, text: str, provider: str, user_id: int,
) -> Sound:
"""Create a Sound record for the TTS audio with complete metadata."""
# Get audio metadata
@@ -328,7 +332,7 @@ class TTSService:
if result["status"] == "error":
print(
f"Warning: Failed to normalize TTS sound {sound_id}: {result.get('error')}"
f"Warning: Failed to normalize TTS sound {sound_id}: {result.get('error')}",
)
except Exception as e:
@@ -364,7 +368,7 @@ class TTSService:
# Check ownership
if tts.user_id != user_id:
raise PermissionError(
"You don't have permission to delete this TTS generation"
"You don't have permission to delete this TTS generation",
)
# If there's an associated sound, delete it and its files