Shadows97 / PySubtitle

It is a project for generate subtitle file for video
MIT License
7 stars 2 forks source link

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

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.