Plot A Speaker Timeline with Matplotlib
In this guide, we’ll show you how to plot a speaker timeline with matplotlib, using results from the speaker diarization model.
Quickstart
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 the API key.
Create a TranscriptionConfig
object and set speaker labels to True
.
Create a Transcriber
object.
Use the Transcriber object’s transcribe
method and pass in the audio file’s path and config
object as parameters. The transcribe method saves the results of the transcription to the Transcriber
object’s transcript
attribute.
Extract the utterances from the transcript and set this to utterances
.
Import the matplotlib.pyplot
library. Then use the following plot_speaker_timeline
function which results in a plot image of the speaker timeline. This function extracts the start
and end
timestamps of each utterance
per speaker
and plots the data onto the horizontal bar chart. The X and Y axis are labelled accordingly.
Finally, call the plot_speaker_timeline
function passing utterances
as a parameter to see the plot image result.