Use Automatic Language Detection as a Separate Step From Transcription
In this guide, we’ll show you how to perform automatic language detection separately from the transcription process. For the transcription, the file then gets then routed to either our Best or Nano model class, depending on the supported language.
This workflow is designed to be cost-effective, slicing the first 60 seconds of audio and running it through Nano ALD, which detects 99 languages, at a cost of $0.002 per transcript for this language detection workflow (not including the total transcription cost).
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 SDK:
Import the assemblyai
package and set your API key:
Create a set with all supported languages for Best. You can find them in our documentation here.
Define a Transcriber
. Note that here we don’t pass in a global TranscriptionConfig
, but later apply different ones during the transcribe()
call.
Define two helper functions:
detect_language()
performs language detection on the first 60 seconds of the audio using Nano and returns the language code.transcribe_file()
performs the transcription. For this, the identified language is applied and either Best or Nano is used depending on the supported language.
Test the code with different audio files. For each file, we apply both helper functions sequentially to first identify the language and then transcribe the file.