draw a spectrogram

Before Xiaocheng introduced how to draw the waveform diagram of audio (referring to the amplitude diagram), the amplitude is a feature of the sound, which reflects the size of the sound energy.

Frequency, another characteristic of sound, reflects the pitch of the sound. For the intuitive analysis of frequency, means such as spectrogram may be used.

This article describes how to draw audio spectrograms through python's pyplot.

Spectrogram, that is, speech spectrogram, also called time-frequency diagram, the abscissa is time, and the ordinate is frequency.

Let's take a look first, a spectrogram drawn by audition looks like this:
Spectrogram example

Notice, do you see streaks with brightness?

These are called voiceprints, indicating that in a certain time area, the frequency is concentrated on a certain value. And, the frequency of concentration is represented by brightness.

The whole picture is a collection of voiceprints of frequencies.

Through the spectrogram, the content of the speech can be analyzed, such as initials, pitch and other data, and of course, the voiceprints in different time intervals can be compared to obtain more information.

The method of drawing a spectrogram is very similar to drawing a waveform diagram. Xiaocheng no longer posts the complete code. Readers can follow the WeChat public account of "Guangzhou Xiaocheng" and check the previous article introduction.

Here, only the code for the difference is given, please see the screenshot below:
The key code for drawing the spectrogram

After running (the operation method is the same as the previous introduction), you can see the spectrogram, and Xiaocheng provides several screenshots.

Spectrogram of a single channel:
single channel spectrogram

For another example, a dual-channel spectrogram:
Two-channel spectrogram

So far, the process and effect of drawing the spectrogram have been introduced.


To sum up, this article is a continuation of the previous "Drawing Audio Waveforms", which introduces the drawing of spectrograms. Compared with the drawing of waveforms, only simple code changes are required, and the difficulty factor is very low.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324924349&siteId=291194637