Visualizing sound waves
1. Visualizing sound waves
It took a few conversion steps but now you've seen what it takes to transform an audio file into numbers. Because of your efforts, we'll now be able to visualize our good morning sound wave using the plotting library MatPlotLib.2. Adding another sound wave
To add to the visualization we're creating, we'll bring in another sound wave, good afternoon. This will highlight the difference between two similar sound waves and set up the intuition for the rest of the course. Both the good morning and good afternoon audio files are 48 kHz or 48,000 frames per second. You'll see in future lessons, having your audio files at the same frame rate and ensuring the same data transformations are made on each of them is important. This is because, if they're different, we've got the potential for data mismatches, which will prevent us from further processing. In the previous lesson, we used the frame rate to calculate the time stamps of where each piece of audio information appears. Behind the scenes, we've done the same calculations with the good afternoon audio file as the good morning file. Now we've got both sound wave arrays and timestamps ready, we can plot them.3. Setting up a plot
To set up a plot, we first import the MatPlotLib pyplot module under the common alias pee-ell-tee. We can then start creating a plot by calling title on plt and passing it a string. The string will be the title of our plot. Then we can add some labels for the x and y axis' using the xlabel and ylabel methods. The x-axis will be the timestamps we've calculated, measured in seconds. And the y-axis is the amplitude or how much the sound wave displaces air particles as it moves through the air. A value of 0 indicates no sound at all. Now we've got the plot labels set up, we can add both of the sound waves. We'll make sure each of them has a label so we can differentiate them using a legend. And to make sure we can highlight the differences, we'll add an alpha parameter of zero point five to the good morning values, this is so they appear slightly transparent on the plot. Since we've given our data labels, we can create a legend by calling the legend method on our plot. And now every thing is set up, we can see our plot by calling the show method. Let's see it!4. Visualizing our sound waves
Woah, that looks nice. In the beginning, you can see how the two sound waves are similar where the word 'good' would be but then they begin to differ as morning and afternoon get uttered. These differences are what we'll be working with throughout the rest of the course as we convert sound wave integers to words.5. Time to visualize!
Now you've seen what it takes to import a sound wave, transform it from bytes to integers and then plot it, it's your turn to visualize some sound waves!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.