Skip to main content

Documentation Index

Fetch the complete documentation index at: https://assemblyai.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

In this guide, we’ll show you how to translate an AssemblyAI generated subtitle transcript. We will also be using the Googletrans Python library to implement the Google Translate API.

Get Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.

Step-by-Step Instructions

Install the relevant packages.
  1. AssemblyAI SDK
  2. Googletrans
pip install -U assemblyai googletrans
Import the assemblyai package and set the API key. Import Translator class from googletrans package.
import assemblyai as aai
from googletrans import Translator

aai.settings.api_key = "YOUR_API_KEY"
Create a Transcriber object.
config = aai.TranscriptionConfig(speech_models=["universal-3-pro", "universal-2"])
transcriber = aai.Transcriber()
Create a Translator object.
translator = Translator()
Use the Transcriber object’s transcribe method and pass in the audio file’s path as a parameter. The transcribe method saves the results of the transcription to the Transcriber object’s transcript attribute.
transcript = transcriber.transcribe("./my-audio.mp3", config)
Alternatively, you can pass in a path to an audio file saved on the internet.
transcript = transcriber.transcribe("https://example.org/audio.mp3", config)
Export SRT subtitles with the export_subtitles_srt method. Create a subtitle_transcript variable to translate in the next step.
subtitle_transcript = transcript.export_subtitles_srt()
Translate subtitle transcript to target language
translation = translator.translate(subtitle_transcript, dest='es')
Print results
print(translation.text)

Conclusion

Using the subtitles and transcripts generated by AssemblyAI, we can also generate translated alternatives using other translation APIs. The implementation logic will be similar with other solutions like DeepL, Yandex Translate and many more. To translate to other languages, find the full list of Supported Languages in the Further Documentations section.

Further Documentation

Googletrans Library Translation Supported Languages