This tutorial will demonstrate how to add audio and video to a scene. First, we will see how to add sound to the world. Then, we'll add sound localized to an object in the world. Finally, we will apply a video as a texture to a model.
Note: this content is discussed in more detail in the reference section.
If you have trouble getting the code in this tutorial to work, you can find the complete example script multimedia.py in the \tutorials\multimedia directory.
First create an empty script and add the following initial code to it:
To add an audio file to your world, use the following line:
Here we've added the audio file 'bach_air.mid'. In general, Vizard will support any audio format that your computer supports. Once you've added a sound file, you can play it, pause it, or stop it. Next let's add the ability to play the file when we hit the 'p' key and stop it when we hit the 's' key.
Now run the script and try those keypresses. You can also start a sound file from any point or at any speed. Close the world and add a couple more lines to your script to make the sound file play in a loop at three times its normal speed.
Now run your script again and see how it sounds once you hit the 'p' key.
You can also add localized sound to objects in your world such that the sound appears to come from that object. In the next part of the script we'll add a quacking duck to the world. In the following code, the first two lines add the duck and set its orientation. The two lines after that create and then apply an action to the duck that moves it back and forth.
In the next line we'll add a quacking sound to the duck. By including the viz.STOP flag, we'll keep the duck from quacking until we're ready.
We'll use the 'q' key to start the duck's quacking. The play command will also loop the quacking sound.
Now run the script and hit 'q'. You should be able to hear the quack get louder and softer as he gets closer and further away.
Next, use the following line to add a video file to your world.
Then we'll need something to play the video on, like a screen, within our world. So, let's add a ball and then texture the ball with the video. We'll also add a couple lines so that the ball is in a position and orientation where we can see the video.
Finally, let's play the video on loop.
Now run your script again to see the video in action.