This guide will show you how to use AssemblyAI’s API to resubmit a request using a default language if the Automatic Language Detection’s language_confidence is below a certain threshold.
Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for an AssemblyAI account and get your API key from your dashboard.
Install the SDK:
Import the assemblyai package and set the API key.
Define a default_language, which should be set to the language code that will be used to rerun the transcript if language detection runs with low language_confidence.
Define an audio_url that is set to a link to the audio file. Define and set the parameters audio: audioUrl and language_detection: true. We also need to define our language_confidence_threshold. For the purposes of this example, we’ll set it to 0.8, representing 80% confidence.
If a transcript ends up with a language_confidence below this value, the transcript will error out and will return the transcript using the default_language.
You can handle the error safely by checking the error message and rerunning the transcript with the language_code set to the default_language.
The error handling flow works as follows:
language_confidence being below thresholddefault_language as the language_codeWhen rerunning with the default language, the configuration is updated to:
language_detectionlanguage_confidence_thresholdlanguage_code to the default_languageYou will not be charged for the first transcript if there is an error. You will only be charged for the transcript that processes successfully.