Python Detect a WAV File is Compressed or not – Python Tutorial

By | December 4, 2023

When we are building a speaker verification model, we have to check a wav file is compressed or not. As to a compressed wav, the high frequency may be cut. For example:

python check a wav is compressed or not

In this tutorial, we will introduce you how to detect a wav file is compressed or not.

Here is the example code:

import wave

def is_compressed(wave_file):
    with, "rb") as f:
        compression_type = f.getcomptype()
        if compression_type == "NONE":
            return False
            return True

As to f.getcomptype(), it will return compression type (‘NONE’ is the only supported type).

Then, we can use is_compressed() function to detect a file is compressed or not.