🎥

Subtitle Creation with Assembly AI

Aug 24, 2024

Creating Subtitles for Videos Using Assembly AI

Overview

  • AI can learn to use digital tools for natural language processing tasks with few or zero-shot settings.
  • Assembly AI allows you to quickly add subtitles to videos using a few lines of code.

Getting Started

  1. Install the Assembly AI SDK
    • Open terminal and execute: pip install Assembly AI
  2. Obtain an API Key

Writing the Code

  • In your Python file, import Assembly AI: import Assembly AI as AAI
  • Set your Assembly AI API key: AAI.api_key = 'your_api_key'
  • Create a transcription job:
    • Create a transcriber object via Assembly AI and pass the video/audio file to it.
    • Example video: 4K video, 1.18 GB.
    • For faster upload, extract audio using QuickTime Player (File > Export as Audio Only) to get an 8.7 MB file.

Transcription and Exporting Subtitles

  • Once transcription is ready, export subtitles: transcriber.export_subtitles(format='srt') # or 'vtt'
  • Optionally, specify max characters per caption (default is between 80-100).
  • Open a file to write the subtitles: with open('subtitles.srt', 'w') as file: file.write(transcribed_subtitles)

Final Steps

  • Check the generated subtitles file:
    • Can be opened with any text editor.
    • Timed subtitles will be accepted by platforms like YouTube and VLC player.

Conclusion

  • Subtitles can be generated with just a few lines of code.
  • For further inquiries or to learn more, refer to the Assembly AI documentation or SDK documentation on GitHub.

Additional Resources

  • Links to documentation will be provided in the description below.