Do More With Our SDKs

This guide will show you additional ways to make use of AssemblyAI’s Python and JavaScript SDKs.

Get Started

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.

How to Check and Update Your Version of the SDK

Sometimes errors are encountered because the version of the SDK you are using is not up to date. To see which version you are currently running, type this code in your terminal:

1pip show assemblyai

If this version is not the same as the current version of the Python SDK then you can update your version by typing this code in your terminal:

1pip install assemblyai --upgrade

How to Catch and Log Errors

Catching and logging errors to the console is an easy way help you understand what is going wrong if the code does not run correctly.

Underneath the line of code where the transcript is created, transcript = transcriber.transcribe(audio_url, config), add the following code to catch and log any errors to the terminal:

1if transcript.error:
2 print(transcript.error)

How to Log the Transcript JSON and Save it in a File

If using the error handling code above then add this below it, otherwise add it after the transcript is created, transcript = transcriber.transcribe(audio_url, config):

1json_file = open('transcript.json', 'w', encoding='utf8')
2json_str = json.dumps(transcript.json_response, ensure_ascii=False, indent=2)
3
4json_file.write(json_str)
5json_file.close()
6
7print(json_str)

How to Log the Transcript ID and Retrieve a Previously Created Transcript

To log the transcript ID for a transcription, after the transcript is created and below any error handling, add the following code:

To log the transcript ID for a transcription, after the transcript is created and below any error handling, add the following code:

1print(transcript.id)

Use the following code to retrieve a previous transcript:

1transcript = aai.Transcript.get_by_id("<TRANSCRIPT_ID>")
2
3print(transcript.text)

You can also retrieve multiple transcripts, which are then returned in a single TranscriptGroup object:

1transcript_group = aai.TranscriptGroup.get_by_ids(["<TRANSCRIPT_ID_1>", "<TRANSCRIPT_ID_2>"])
2
3for transcript in transcript_group:
4 print(transcript.text)