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:
-
FFmpeg: This library requires
ffmpeg
to handle video and audio processing. Here's how you can installffmpeg
: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.
-
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
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
File details
Details for the file PySubtitle-0.1.2.tar.gz
.
File metadata
- Download URL: PySubtitle-0.1.2.tar.gz
- Upload date:
- Size: 10.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63210e1aa550425160f2cec7449ec547f1d9b8c7b37dfd272c75978460e4daa |
|
MD5 | ac1bfcef6f20636777a12160e4bf917c |
|
BLAKE2b-256 | 939eb230ca31e46764bde08977c25cb6bf7a987d09d5d48a1cc1f0fc8a3b1432 |
File details
Details for the file PySubtitle-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: PySubtitle-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ca3396a475e488359eb4f4e440f7604c65b4b5fd986482ef7d3c7ffd58e318b |
|
MD5 | 5e0b5e8fef25bf619c02cb23829b3054 |
|
BLAKE2b-256 | b88348afc235935aabc33c8b709bc0f02fbeaf4c0b956c1aa35e8bf20fdfe029 |