Skip to main content

A python library to generate subtitles from a video

Project description

PySubtitle

PySubtitle is a Python library designed to automate the process of generating subtitles for video files. It extracts audio from video files, converts the audio to text using Google's speech recognition services, and generates VTT (Web Video Text Tracks) files for subtitles. This library is particularly useful for creating subtitles for videos in various languages, making content more accessible to a wider audience.

Features

  • Audio Extraction: Extracts audio from video files using ffmpeg.
  • Speech Recognition: Converts audio to text using Google Cloud Speech-to-Text API.
  • Subtitle Generation: Creates VTT files from the transcribed text, with accurate timing and synchronization.
  • Cross-Platform: Works on Windows, macOS, and Linux.

Prerequisites

Before installing and using this library, you need to ensure the following prerequisites are met:

  1. FFmpeg: This library requires ffmpeg to handle video and audio processing. Here's how you can install ffmpeg:

    On Ubuntu:

    sudo apt update
    sudo apt install ffmpeg
    

    On macOS:

    brew install ffmpeg
    

    On Windows:

    Download the binaries from FFmpeg Official Site and follow the installation instructions.

  2. Google Cloud Service Key: This library uses Google Cloud Speech-to-Text API for speech recognition. You need to set up a Google Cloud project and download a service key. Follow these steps:

    • Go to the Google Cloud Console.
    • Create a new project or select an existing one.
    • Enable the Speech-to-Text API for your project.
    • Go to "Credentials" and create a new service account key.
    • Download the JSON key file and set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file.

Installation

To install this library, use pip:

pip install PySubtitle

Usage

Here is a simple example of how to use this library:

from PySubtitle.audio_extraction import extract_audio
from PySubtitle.speech_recognition import audio_to_text
from PySubtitle.vtt_generation import generate_vtt
from PySubtitle.languages import Languages

# Path to your video file
video_path = 'path/to/your/video.mp4'

# Extract audio
audio_path = extract_audio(video_path)

# Convert audio to text
transcripts, durations = audio_to_text(audio_path, Languages.ENGLISH.value)

# Generate VTT file
vtt_file = 'output.vtt'
generate_vtt(transcripts, durations, vtt_file)

Contributing

Contributions are always welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

PySubtitle-0.1.2.tar.gz (10.6 MB view hashes)

Uploaded Source

Built Distribution

PySubtitle-0.1.2-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

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