Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio AudioService generate audio

From Leeroopedia
Knowledge Sources
Domains Audio, Generative_AI
Last Updated 2026-10-23 12:00 GMT

Overview

Service that batch-generates TTS narration audio for sentences using a multi-provider gateway with concurrency control and audio duration tracking.

Description

AudioService.generate_audio loads sentences by ID, creates a GatewayProvider from the user's API key (concurrency 5), and concurrently processes each sentence by calling GatewayProvider.generate_audio with the sentence content text and optional voice selection. Generated audio is uploaded to MinIO storage, and each sentence's audio_url and audio_duration are updated. Status is set to GENERATED_AUDIO.

The voice parameter may be formatted as model:voice_name to override the default voice from the model config.

Usage

Import when generating TTS narration audio for narrative sentences. Called by the content generation Celery task after image generation.

Code Reference

Source Location

Signature

class AudioService(BaseService):
    async def generate_audio(
        self,
        api_key_id: str,
        sentence_ids: List[str],
        voice: str = None,
        model: str = None
    ) -> dict:
        """
        Args:
            api_key_id: API key UUID
            sentence_ids: sentence UUIDs
            voice: voice style (format: 'model:voice_name')
            model: TTS model name

        Returns:
            Dict with total, success, failed
        """

Import

from src.services.audio import AudioService

I/O Contract

Inputs

Name Type Required Description
api_key_id str Yes API key UUID
sentence_ids List[str] Yes Sentence UUIDs to process
voice str No Voice ID (format: model:voice_name)
model str No TTS model name

Outputs

Name Type Description
return value dict {total, success, failed}
DB side effects — Updates Sentence.audio_url, Sentence.audio_duration; sets status to GENERATED_AUDIO

Usage Examples

Batch Audio Generation

from src.services.audio import AudioService

service = AudioService(db_session)
result = await service.generate_audio(
    api_key_id="key-uuid",
    sentence_ids=["sent-1", "sent-2"],
    voice="alloy",
    model="tts-1",
)
print(f"Audio generated: {result['success']}/{result['total']}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment