Retrieving Audio Data

In addition to sensing mouse-pointer and keyboard data, collisions, distance, and other stage and sprite properties and working with the timer, Scratch also provides access to a pair of sensing blocks, shown in Figure 6.13, that allow you to sense sound input from the computer’s microphone (if it has one) and to use that input within your Scratch applications.

Figure 6.13. These sensing blocks are used to report on how loud a sound is being played.


The first of these two sensing blocks retrieves a number, from 1 to 100, representing the volume of the computer’s microphone, and the second code block retrieves a true/false value, depending on whether a sound value of 30 or greater is detected through the computer’s microphone.

The following example demonstrates how to create a script that plays an audio file named pop whenever a loud sound is detected through the computer’s microphone.

Both of the code blocks shown in Figure 6.13 are monitor blocks, so if you want, you can display their results on the stage, as demonstrated in Figure 6.14.

Figure 6.14. Using monitors to keep track of the loudness of audio playback and input.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.199.250