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.
ffmpeg
.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 install ffmpeg
:
sudo apt update
sudo apt install ffmpeg
brew install ffmpeg
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:
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file.To install this library, use pip:
pip install PySubtitle
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)
Contributions are always welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.