The ContentTranslationEngine automates video translation by transcribing audio, translating text, generating new audio via a VoiceModule, and rendering the final video.
To use it, you must provide:
- A
VoiceModule instance. - A
src_url (a local file path or a YouTube/YouTube Shorts link). - A
target_language (from the Language enum). - An optional
use_captions boolean (set to True to include timed text captions in the output video).
Workflow:
- Initialize the engine with the required parameters.
- Call
makeContent() to execute the translation pipeline. This method is a generator that yields step numbers and logs. - Call
get_video_output_path() to retrieve the location of the rendered video.
from shortGPT.config.api_db import ApiKeyManager, ApiProvider
from shortGPT.engine.content_translation_engine import ContentTranslationEngine
from shortGPT.config.languages import Language
from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule, EDGE_TTS_VOICENAME_MAPPING
# Set API Keys
ApiKeyManager.set_api_key(ApiProvider.OPENAI, "your_openai_key")
ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, "your_eleven_labs_key")
# Configure the Voice Module
voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.SPANISH]['male']
voice_module = EdgeTTSVoiceModule(voice_name)
# Configure Content Engine
src_url = "https://www.youtube.com/watch?v=QQz5hj8y1TE"
target_language = Language.SPANISH
use_captions = False
content_engine = ContentTranslationEngine(voice_module, src_url, target_language, use_captions)
# Generate Content
for step_num, step_logs in content_engine.makeContent():
print(f" {step_logs}")
# Get Video Output Path
print(content_engine.get_video_output_path())