Python Tutorial : Visualizing sound waves

Publicado el: 12 March 2020
en el canal de: DataCamp
11,833
80

Want to learn more? Take the full course at https://learn.datacamp.com/courses/sp... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---

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.

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.

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 everything is set up, we can see our plot by calling the show method.

Let's see it!

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.

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!

#DataCamp #PythonTutorial #SpokenLanguageProcessinginPython #SpokenLanguageProcessing


En esta página del sitio puede ver el video en línea Python Tutorial : Visualizing sound waves de Duración hora minuto segunda en buena calidad , que subió el usuario DataCamp 12 March 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 11,833 veces y le gustó 80 a los espectadores. Disfruta viendo!