Identify Duplicate Dual Channel Files
In this guide, you’ll learn how to identify Dual Channel (Stereo) files that contain the same content on each channel. With AssemblyAI’s API, we support Dual Channel files by transcribing each channel individually, then intelligently combining the results into one transcript. If a file contains the same content on both channels, then you may end up with duplicate content in your transcript.
To programmatically identify duplicate channels, you can hash the audio content found on each channel and compare the hashes to quickly determine whether you should remove a channel and then submit the file for more accurate results.
Getting Started
To get started, you’ll need to install a few prerequisites:
Helper Functions
Now we’ll need to define a few helper functions before we set up our full workflow. The first one, load_audio
will load any audio file, regardless of format, and return each channel as a NumPy array.
Our next function, hash_audio_data
hashes each channel to return a SHA-256 hash.
Our next function, compare_audio_channels
lets us know via a flag if the audio channels are the same, with 1 meaning that they are the same, and 0 meaning they’re not.
Based on the result of this function, we now need a way to remove the duplicate content to avoid duplicate transcription results. To do this, we’ll define one final function, convert_to_mono_if_duplicate
that removes one of the audio channels and creates a new mono file that we can submit to AssemblyAI, returning the path to it. If the file contains different content on each channel, however, this function will instead return the original file path.
Combining with AssemblyAI
Now we can combine this workflow with AssemblyAI to programmatically catch files that could cause duplicate results and modify them before submitting them to AssemblyAI. To get started, you’ll need an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.
Now we’ll create a workflow that checks if we should convert a file before using AssemblyAI’s SDK to transcribe it.