Complete Video Translation Pipeline using NeMo ASR, NLLB, and TTS
A comprehensive Python-based pipeline for translating video content from one language to another. Extract audio → Transcribe (STT) → Translate → Synthesize (TTS) → Recompose video with new audio.
Overview
This project consists of six main modules:
Master Pipeline:
video_translation_pipeline.py - Orchestrates complete video translation workflow
Core Modules:
audio_extraction_from_video.py - Extracts audio tracks from video files
audio_to_asr_nemotron.py - Transcribes extracted audio using NeMo ASR (Speech-to-Text)
text_to_speech_tts.py - Converts text to speech using NeMo TTS models (Text-to-Speech)
nllb_translation.py - Translates text to other languages using NLLB model
download_model_nemotron.py - Downloads pre-trained Nemotron ASR model
download_model_nllb.py - Downloads NLLB (No Language Left Behind) translation model
Files Description
1. audio_extraction_from_video.py
Purpose: Extract audio from video files and save as standalone audio files.
1extract_audio_from_video(2 video_file_path,# Path to input video3 audio_file_path,# Path to save audio4 audio_codec='libmp3lame',# Audio codec (default: MP3)5 audio_bitrate='192k',# Audio bitrate (default: 192kbps)6 verbose=False# Show moviepy output7)
Usage Examples:
bash
1# Basic usage with defaults (MP3, 192kbps)2python audio_extraction_from_video.py input_video.mp4 output_audio.mp3
34# Custom codec and bitrate5python audio_extraction_from_video.py video.mp4 audio.wav libsndfile 320k
67# In Python8from audio_extraction_from_video import extract_audio_from_video
9extract_audio_from_video("movie.mkv", "soundtrack.mp3", audio_bitrate='256k')
Improvements Made:
✓ Validates video file existence and format
✓ Checks for audio track presence before processing
✓ Proper exception handling with informative error messages
✓ Guaranteed resource cleanup with try-finally blocks
✓ Logging system for tracking extraction progress
✓ Configurable output parameters for flexibility
✓ Command-line interface support with optional parameters
2. audio_to_asr_nemotron.py
Purpose: Transcribe audio files using NeMo's Conformer CTC ASR model (English only).
Key Features:
Model caching to avoid expensive reloads
Automatic GPU detection for faster inference
Audio format validation (MP3, WAV, FLAC, OGG, M4A)
Comprehensive error handling and logging
Optional output file saving
Command-line argument support
Function Signature:
python
1transcribe_audio(2 audio_file_path # Path to audio file to transcribe3)
Usage Examples:
bash
1# Basic usage - print to console2python audio_to_asr_nemotron.py input_video.mp4
34# Save transcription to file5python audio_to_asr_nemotron.py input_video.mp4 audio.mp3 transcription.txt
67# In Python8from audio_to_asr_nemotron import transcribe_audio, get_asr_model
910# First call loads model, subsequent calls use cached model11text1 = transcribe_audio("audio1.mp3")12text2 = transcribe_audio("audio2.mp3")# Uses cached model
Improvements Made:
✓ Single model loading with caching (eliminates repeated load overhead)
✓ GPU support for accelerated inference
✓ Audio file validation before transcription
✓ Graceful error handling with detailed logging
✓ Flexible output options (console or file)
✓ Better formatted output with visual separators
✓ Removed duplicate imports
✓ Refactored into reusable functions
3. text_to_speech_tts.py
Purpose: Convert text to natural-sounding speech audio using NeMo TTS (Text-to-Speech) models.
Key Features:
Support for multiple TTS models (Glow-TTS, FastPitch)
Vocoder support (HiFi-GAN for high-quality audio)
Pitch and speed control
Model caching for efficient reuse
GPU acceleration for faster synthesis
Batch processing for multiple texts
Comprehensive error handling and validation
Detailed logging for debugging
Function Signature:
python
1text_to_speech(2 text,# Text to convert to speech3 output_audio_path,# Path to save audio file4 model_name='glow_tts',# TTS model ('glow_tts' or 'fastpitch')5 vocoder_name='hifigan',# Vocoder model6 speaker=None,# Speaker ID (for multi-speaker models)7 pitch=1.0,# Pitch adjustment (0.5-2.0)8 speed=1.0# Speed adjustment (0.5-2.0)9)
Usage Examples:
bash
1# Basic text-to-speech2python text_to_speech_tts.py "Hello, this is a test." output.wav
34# Custom model5python text_to_speech_tts.py "Hello world" output.wav fastpitch
67# Batch processing in Python8from text_to_speech_tts import batch_text_to_speech
910texts =["Hello world", "How are you?", "Goodbye"]11outputs =["hello.wav", "how.wav", "goodbye.wav"]12batch_text_to_speech(texts, outputs)
Advanced Usage:
python
1from text_to_speech_tts import text_to_speech
23# Adjust pitch and speed4text_to_speech(5"Make this sound higher and faster",6"output.wav",7 pitch=1.3,# 30% higher pitch8 speed=1.2# 20% faster9)1011# Use FastPitch model (better control)12text_to_speech(13"This uses FastPitch",14"output.wav",15 model_name="fastpitch"16)
Purpose: Download the pre-trained Nemotron-3.5 ASR streaming model from Hugging Face.
Features:
Downloads Nemotron-3.5 ASR Streaming 0.6b model
Saves to nemotron-3.5-asr-streaming-0.6b/ directory
Model weights: ~600MB (distilled for efficiency)
Includes model configuration, tokenizer, and documentation
Model Details:
Architecture: Conformer CTC
Language: English
Streaming Support: Yes (processes audio chunks in real-time)
Quantization: Distilled 600M parameter model
5. download_model_nllb.py
Purpose: Download the NLLB-200 translation model for multi-language translation.
Features:
Downloads NLLB-200 distilled model
Supports 200+ languages
Model size: ~600MB
Enables machine translation capabilities
6. nllb_translation.py
Purpose: Translate text between 200+ languages using Meta's NLLB-200 model.
Key Features:
Supports 200+ languages with high-quality translation
Model caching for efficiency
GPU acceleration with automatic CPU fallback
Batch translation support
Input validation and error handling
Comprehensive logging
Multiple model variants available
Function Signature:
python
1translate_text(2 text,# Text to translate3 source_lang='english',# Source language4 target_lang='spanish',# Target language5 model_name='facebook/nllb-200-distilled-600M',# Model to use6 max_length=512# Max output length7)
1# Simple translation2python nllb_translation.py "Hello, how are you?" english spanish
34# Different language pair5python nllb_translation.py "Bonjour le monde" french english
67# From German to Japanese8python nllb_translation.py "Guten Tag" german japanese
Python API:
python
1from nllb_translation import translate_text, batch_translate
23# Single translation4result = translate_text("Hello world","english","spanish")5print(result)# "Hola mundo"67# Batch translation8texts =["Hello","Good morning","How are you?"]9results = batch_translate(texts,"english","french")1011# Use different model (higher quality)12result = translate_text(13"Complex text to translate",14"english",15"german",16 model_name="facebook/nllb-200-1.3B"# Better quality, slower17)1819# List all supported languages20from nllb_translation import list_supported_languages
21languages = list_supported_languages()22print(languages)
Model Variants:
Model
Size
Speed
Quality
Use Case
nllb-200-distilled-600M
~600MB
Fast
Good
Real-time, resource-constrained
nllb-200-1.3B
~2.6GB
Medium
Very Good
Balanced quality/speed
nllb-200-3.3B
~6.5GB
Slow
Excellent
Maximum quality
Improvements Made:
✓ Comprehensive language support dictionary (200+)
1attach_audio_to_video(2 video_path,# Input video3 audio_path,# New audio to attach4 output_path,# Output video path5 fps=24# Output frames per second6)
Key Improvements:
✓ Complete end-to-end automation
✓ Detailed step-by-step logging
✓ Automatic audio/video synchronization
✓ GPU acceleration detection
✓ Flexible model selection
✓ Intermediate file management
✓ Comprehensive error messages
Complete Pipeline Usage
⭐ MASTER PIPELINE: Complete Video Translation (One Command!)
bash
1# Translate English video to Spanish2python video_translation_pipeline.py input_video.mp4 output_spanish.mp4 english spanish
34# Translate to German with better quality5python video_translation_pipeline.py input.mp4 output_german.mp4 english german fastpitch
67# Use higher quality translation model8python video_translation_pipeline.py input.mp4 output.mp4 english spanish facebook/nllb-200-1.3B
910# Keep intermediate files for debugging11python video_translation_pipeline.py input.mp4 output.mp4 english spanish --keep
Loads the pre-trained ASR model (or uses cached version)
Extracts audio from the video
Transcribes the audio
Saves the transcription to a file
Text-to-Speech Pipeline:
bash
1# Simple text to speech2python text_to_speech_tts.py "Hello, welcome to the audio translation pipeline" output.wav
34# With custom voice characteristics5python text_to_speech_tts.py "This sounds more natural" output.wav fastpitch
Complete Audio-to-Text-to-Speech Pipeline:
python
1from audio_extraction_from_video import extract_audio_from_video
2from audio_to_asr_nemotron import transcribe_audio
3from text_to_speech_tts import text_to_speech
45# Step 1: Extract audio from video6extract_audio_from_video("my_video.mp4","extracted_audio.mp3")78# Step 2: Transcribe to text9transcription = transcribe_audio("extracted_audio.mp3")10print(f"Transcription: {transcription}")1112# Step 3: Convert text back to speech13text_to_speech(transcription,"recreated_speech.wav")
1from audio_extraction_from_video import extract_audio_from_video
2from audio_to_asr_nemotron import transcribe_audio
3from nllb_translation import translate_text
4from text_to_speech_tts import text_to_speech
56# Step 1: Extract audio from video7extract_audio_from_video("english_video.mp4","audio.mp3")89# Step 2: Transcribe audio to English text10transcription = transcribe_audio("audio.mp3")11print(f"English: {transcription}")1213# Step 3: Translate to Spanish14translation = translate_text(transcription,"english","spanish")15print(f"Spanish: {translation}")1617# Step 4: Convert Spanish text to speech18text_to_speech(translation,"spanish_speech.wav")1920# Result: Spanish audio file from English video!
Batch Translation Pipeline:
python
1from nllb_translation import batch_translate
23# Translate multiple lines4english_texts =[5"Hello, welcome to our service",6"How can we help you today?",7"Thank you for choosing us"8]910# Translate to multiple languages11for target_lang in["spanish","french","german"]:12 translations = batch_translate(english_texts,"english", target_lang)13for i,(original, translated)inenumerate(zip(english_texts, translations)):14print(f"{target_lang.upper()}{i+1}: {translated}")
Complete Multilingual Pipeline (Video → 3 Languages → Audio):
python
1from audio_extraction_from_video import extract_audio_from_video
2from audio_to_asr_nemotron import transcribe_audio
3from nllb_translation import translate_text
4from text_to_speech_tts import text_to_speech
56# Extract and transcribe7extract_audio_from_video("input_video.mp4","audio.mp3")8english_text = transcribe_audio("audio.mp3")910# Translate and create audio for multiple languages11target_languages =["spanish","french","german"]1213for lang in target_languages:14# Translate15 translated = translate_text(english_text,"english", lang)1617# Convert to speech18 output_file =f"output_{lang}.wav"19 text_to_speech(translated, output_file)2021print(f"✓ Created {output_file}")
1# Install required packages2pip install nemo-toolkit torch moviepy torchaudio
34# Or with conda (recommended for GPU support)5conda install pytorch torchvision torchaudio pytorch-cuda -c pytorch
6pip install nemo-toolkit moviepy
Note for TTS: The torchaudio package is required for text-to-speech functionality. Make sure it's installed.
GPU Setup (Optional but Recommended):
For NVIDIA GPUs, ensure CUDA is installed:
bash
1# Check CUDA availability2python -c "import torch; print(torch.cuda.is_available())"
Download Models:
bash
1# Download Nemotron ASR model2python download_model_nemotron.py
34# Download NLLB translation model (if needed)5python download_model_nllb.py
🚀 Quick Start
Basic video translation (30 seconds of setup):
bash
1# 1. Install dependencies (one time)2pip install nemo-toolkit torch moviepy torchaudio transformers
34# 2. Run the complete pipeline5python video_translation_pipeline.py input_video.mp4 output_video.mp4 english spanish
That's it! Your translated video will be saved to output_video.mp4.
Python API (for scripts):
python
1from video_translation_pipeline import translate_video
23# Translate English video to Spanish4translate_video(5"input_video.mp4",6"output_spanish.mp4",7"english",8"spanish"9)
Try different languages:
bash
1# English → German2python video_translation_pipeline.py video.mp4 video_german.mp4 english german
34# English → French5python video_translation_pipeline.py video.mp4 video_french.mp4 english french
67# English → Japanese8python video_translation_pipeline.py video.mp4 video_japanese.mp4 english japanese
910# English → Mandarin Chinese11python video_translation_pipeline.py video.mp4 video_chinese.mp4 english chinese_simplified
Error Handling
All functions include comprehensive error handling:
Common Errors and Solutions:
Error
Cause
Solution
FileNotFoundError
Video/audio file doesn't exist
Check file path and ensure file exists
ValueError: Unsupported format
Invalid file format
Use supported formats (MP4, WAV, etc.)
ValueError: Video has no audio
Video has no audio track
Ensure video has audio stream
RuntimeError: Could not load ASR model
Model download failed
Check internet connection, try again
CUDA out of memory
GPU memory insufficient
Use CPU or reduce batch size
Logging:
All operations produce timestamped logs:
2026-07-07 10:30:15,123 - INFO - Loading video: input.mp4
2026-07-07 10:30:16,456 - INFO - Audio duration: 120.50 seconds
2026-07-07 10:30:45,789 - INFO - Audio extraction completed successfully
Performance Notes
Model Caching:
First transcription call loads the model (~1-2 minutes)
Subsequent calls reuse cached model (~seconds per audio file)
1# Get a full list in your code2from nllb_translation import list_supported_languages
3languages = list_supported_languages()4print(languages)
Language Codes:
For command line, use the English name (lowercase):
bash
1python video_translation_pipeline.py input.mp4 output.mp4 english german
2python video_translation_pipeline.py input.mp4 output.mp4 french japanese
3python video_translation_pipeline.py input.mp4 output.mp4 spanish chinese_simplified
Supported Formats
Video Formats:
MP4, AVI, MKV, MOV, FLV, WMV, WebM, M4V
Audio Formats (Extraction Output):
MP3 (default), WAV, FLAC, OGG, M4A, and others supported by ffmpeg
Audio Formats (Transcription Input):
MP3, WAV, FLAC, OGG, M4A
Troubleshooting
Issue: "Module not found: nemo"
pip install nemo-toolkit
Issue: "CUDA out of memory"
The code will automatically fall back to CPU. No action needed.
Issue: Slow extraction
Check disk I/O performance
Ensure sufficient disk space
Consider using SSD instead of HDD
Issue: Poor transcription quality
Check audio quality and volume levels
Ensure audio is in English (Nemotron is English-only)