Skip to main content

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 exception
  • ValidationError: Input validation errors
  • VideoProcessingError: Video processing failures
  • AIProcessingError: 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

  1. Fork the repository
  2. Clone your fork
  3. Create a virtual environment
  4. Install development dependencies
pip install -e ".[dev]"

Development Process

  1. Create a new branch
  2. Make your changes
  3. Write/update tests
  4. Update documentation
  5. 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

  1. Update CHANGELOG.md
  2. Ensure tests pass
  3. Update documentation
  4. 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

  1. User Input → Video URL
  2. URL → Video Information
  3. Video → Raw Captions
  4. Captions → AI Processing
  5. AI Output → Final Transcript

Design Principles

  1. Modularity

    • Separate concerns
    • Pluggable components
    • Easy extensions
  2. Robustness

    • Error handling
    • Retry logic
    • Validation
  3. Performance

    • Async operations
    • Caching
    • Rate limiting
  4. Maintainability

    • Clear structure
    • Documentation
    • Type safety

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youtube_transcript_generator-0.1.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youtube_transcript_generator-0.1.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file youtube_transcript_generator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for youtube_transcript_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e0543bd3f6385246c6d78164e229f03af863de916e10441cb4c2c3477e670ce
MD5 1ea3430c8de82112b8ad4149d99df306
BLAKE2b-256 6effb0c389b5f30439c8c156f2437853d442fa1e4fe5c5619421376058d525a8

See more details on using hashes here.

File details

Details for the file youtube_transcript_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for youtube_transcript_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02ccaef9a02da722754623ff984f548a10705273add75a64d78b37e2da65c63b
MD5 20cd71fbc138910b2c44808cb9109bea
BLAKE2b-256 76ec83a88943cfd9918e82a941e726ad5883e3ac6bd7348e6859731e3c3cdffc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page