- Guides
- Audio
Audio
This guide walks you through how to play sound in your Lens. It covers importing a sound resource, adding the Audio
component to the scene and playing the sound.
Sound Best Practices
When preparing your sound resource for Lens Studio, keep the following optimization recommendations in mind:
- Use the MP3 format
- Use mono instead of stereo
- Use sounds that are < 15 seconds
Playing Sound
Sounds are added to a scene using an Audio
component added to an object. Sounds are then played using a short playback script.
Tip
Your Lens can play multiple sounds simultaneously (e.g. looping background ambience paired with event based sound effects).
Import the Sound
To import your sound, drag and drop your audio files into the Resources
panel.

Add the Audio Component
Next, create an object with an Audio
component. Press "+"
button at the Objects
panel and select Empty Object
.
With the new object selected, add an Audio
component in the Inspector
panel. Select + Add Component ->
Audio
.
Reference your imported sound by clicking on the Choose Audio Track
field and selecting your imported sound.

Autoplay Loop

If you want your sound to play and loop automatically, check the Autoplay Loop
checkbox. This is great for looping music or background ambience.
Play the Sound
For all other audio use cases, create a Script that will play the sound.
In the Resources
panel, select + ->
Script
. With the newly added script selected, head to the Inspector
panel to replace the text in your script resource with the following code:
// Play Audio
// @input Component.AudioComponent audio
script.audio.play( 1 );
Tip
The play function takes in the number of times you want the sound to play as the input parameter. If you want the sound to play indefinitely, pass in -1 .
Connect the Script
We can now use this script to play the sound in the Audio
component we created earlier.
With our object selected, add a Script
component in the Inspector
panel. Select + Add Component ->
Script
. Click the + Add Script
field and select the script resource we just created. Set the script to run on the Lens Turned On
event. Finally, bind the Audio
field to the Audio
component.

Previewing the Sound
Press the refresh button in the Preview
panel and you should be able to hear your sound.
Related Guides
Please refer to the guides below for additional information:
Still Looking for help?
Visit Support