A Python package to generate AI-powered transcripts from YouTube videos
Project description
README.md
YouTube Transcript Generator
A powerful, AI-enhanced YouTube transcript generator using Gemini Pro. Generate high-quality transcripts with advanced features like speaker detection, multi-language support, and custom formatting.
Features
- 🎯 High-accuracy transcription using AI enhancement
- 🌍 Multi-language support with translation capabilities
- 👥 Speaker detection and labeling
- ⏱️ Timestamp preservation and formatting
- 🎨 Custom output formats (TXT, SRT, VTT, JSON, MD)
- 🚀 Async processing for better performance
- 📊 Quality metrics and confidence scoring
- 💾 Caching support for better efficiency
- 🛡️ Comprehensive error handling
- 📝 Detailed logging system
Installation
pip install youtube-transcript-generator
Quick Start
from youtube_transcript_generator import TranscriptGenerator
async def main():
generator = TranscriptGenerator()
result = await generator.generate_transcript(
"https://youtube.com/watch?v=your_video_id",
options=TranscriptionOptions(
target_language="en",
enhance_formatting=True
)
)
print(result.transcript)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
CLI Usage
# Generate transcript
yt-transcript generate https://youtube.com/watch?v=your_video_id -o transcript.txt
# With options
yt-transcript generate https://youtube.com/watch?v=your_video_id \
--language es \
--format srt \
--timestamps \
--speakers
Configuration
Create a .env file:
GEMINI_API_KEY=your_gemini_api_key
YOUTUBE_API_KEY=your_youtube_api_key # Optional
DEBUG=False
LOG_LEVEL=INFO
Documentation
Visit our documentation for detailed information.
Contributing
We welcome contributions! Please see our contributing guidelines.
License
MIT License - see LICENSE for details.
API.md
API Documentation
Core Components
TranscriptGenerator
The main class for generating transcripts.
class TranscriptGenerator:
async def generate_transcript(
video_url: str,
options: Optional[TranscriptionOptions] = None
) -> TranscriptionResult:
"""Generate transcript for a YouTube video."""
TranscriptionOptions
Configure transcript generation:
class TranscriptionOptions(BaseModel):
target_language: Optional[str] = None
enhance_formatting: bool = True
include_timestamps: bool = False
detect_speakers: bool = False
custom_formatting: Optional[dict] = None
VideoInfo
Video information model:
class VideoInfo(BaseModel):
video_id: str
title: str
duration: int
language: Optional[str]
captions_available: bool
url: str
author: str
view_count: Optional[int]
metadata: dict
Error Handling
The library defines several exception classes:
TranscriptionError: Base exceptionValidationError: Input validation errorsVideoProcessingError: Video processing failuresAIProcessingError: AI processing issues
Examples
Basic Usage
from youtube_transcript_generator import TranscriptGenerator
generator = TranscriptGenerator()
result = await generator.generate_transcript("https://youtube.com/watch?v=...")
print(result.transcript)
Advanced Usage
options = TranscriptionOptions(
target_language="es",
enhance_formatting=True,
include_timestamps=True,
detect_speakers=True,
custom_formatting={"format": "srt"}
)
result = await generator.generate_transcript(
"https://youtube.com/watch?v=...",
options=options
)
Enhanced Usage
As a module
runner = TranscriptRunner()
output_files = await runner.process_video(
"https://youtube.com/watch?v=VIDEO_ID",
{
'save_json': True,
'save_srt': True,
'save_vtt': True,
'save_txt': True,
'include_timestamps': True
}
)
As command line tool
python runner.py "https://youtube.com/watch?v=VIDEO_ID" \
--formats json,srt,vtt,txt \
--timestamps \
--output-dir my_transcripts
CONTRIBUTING.md
Contributing Guidelines
Getting Started
- Fork the repository
- Clone your fork
- Create a virtual environment
- Install development dependencies
pip install -e ".[dev]"
Development Process
- Create a new branch
- Make your changes
- Write/update tests
- Update documentation
- Submit a pull request
Code Style
- Follow PEP 8
- Use type hints
- Write docstrings (Google style)
- Keep functions focused and small
- Add comments for complex logic
Testing
Run tests:
pytest
With coverage:
pytest --cov=youtube_transcript_generator
Documentation
- Update API documentation for new features
- Add examples for new functionality
- Keep README.md up to date
Pull Request Process
- Update CHANGELOG.md
- Ensure tests pass
- Update documentation
- Wait for review
architecture.md
Architecture Overview
Core Components
TranscriptGenerator
The main orchestrator that:
- Coordinates video processing
- Manages AI enhancement
- Handles output formatting
YouTubeClient
Responsible for:
- Video information retrieval
- Caption downloading
- Format conversion
AI Processor
Handles:
- Transcript enhancement
- Language processing
- Quality validation
Data Flow
- User Input → Video URL
- URL → Video Information
- Video → Raw Captions
- Captions → AI Processing
- AI Output → Final Transcript
Design Principles
-
Modularity
- Separate concerns
- Pluggable components
- Easy extensions
-
Robustness
- Error handling
- Retry logic
- Validation
-
Performance
- Async operations
- Caching
- Rate limiting
-
Maintainability
- Clear structure
- Documentation
- Type safety
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file youtube_transcript_generator-0.1.0.tar.gz.
File metadata
- Download URL: youtube_transcript_generator-0.1.0.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e0543bd3f6385246c6d78164e229f03af863de916e10441cb4c2c3477e670ce
|
|
| MD5 |
1ea3430c8de82112b8ad4149d99df306
|
|
| BLAKE2b-256 |
6effb0c389b5f30439c8c156f2437853d442fa1e4fe5c5619421376058d525a8
|
File details
Details for the file youtube_transcript_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: youtube_transcript_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02ccaef9a02da722754623ff984f548a10705273add75a64d78b37e2da65c63b
|
|
| MD5 |
20cd71fbc138910b2c44808cb9109bea
|
|
| BLAKE2b-256 |
76ec83a88943cfd9918e82a941e726ad5883e3ac6bd7348e6859731e3c3cdffc
|