In this tutorial you'll learn to add sound, and to make the sound play in response to an interaction from the person using your effect.
We’ll look at:
When you’ve got to grips with the basics of audio, take a look at the audio effect patches included in Spark AR Studio. They can be added to your project to distort audio clips or input from a device’s microphone.
Start by creating an audio playback controller. You can do this in the Assets panel:
It'll be listed in the Assets panel as audioPlaybackController0.
When an audio playback controller is selected in the Assets panel, you'll see its properties in the Inspector.
Add the audio file next to the option labeled Audio. To do this:
For sound to actually render in a scene, the audio playback controller has to be connected to an object called a speaker.
To add a speaker:
It’ll be listed in the Scene panel as speaker0:
Next apply the playback controller to the speaker:
You can also edit the speaker’s properties to adjust the volume of sound in the scene, using the slider next to Volume.
To add a looping sound adjust the properties of the playback controller:
You’ll now have a continuous looping sound in the scene!
Let's make this sound stop in response to a tap on the device screen.
In the Inspector there are circles with arrows on in next to Play, Loop and Reset. Clicking these will create patches, representing that property.
Click the circle next to Play to create a patch and open the Patch Editor.
Next create a Screen Tap patch. This is one of many interaction patches included in Spark AR Studio. It will detect when someone touches the screen of their device when using the effect.
To add this patch to your project:
You’ve now got 2 patches in the Patch Editor.
If we connect the output of the Screen Tap patch to the Play input port in the audio playback controller patch a Switch patch will be created automatically.
Joining these 3 patches together creates a switch that will turn the sound on or off each time the screen is tapped.
We can test this in the Simulator. Click the gear and select Simulate Touch, then click anywhere in the Simulator.
Find out more about playing sounds in response to interactivity.
In this tutorial, you've learned how to use the speaker and audio playback controller to add a continuous sound to your effect.
You've also learned to add some simple interactivity, making the sound stop when someone touches the device screen.