Background music and sound are important parts of any 3D application. In this tutorial, we’ll add background music and sounds, and create reactive sound effects.
You’ll learn about:
- How to add background music
- Ambient sounds
- Control sound settings
- State Machine
Before you begin, you should have completed the following tasks and tutorials:
- Sign in to Amazon Sumerian with your AWS account
- Amazon Sumerian Interface tutorial
- Sumerian Basics: Creating a TV Room
- Material Fundamentals tutorial
- State Machine Basics tutorial
Step 1: Create or Open a Scene
From the Dashboard, create a new scene or open an existing one. We will be using a scene from a previous tutorial, Material Fundamentals.
Step 2: Add Background Music
To add background sound or music, we must add it to an empty Entity.
From the Create Entity menu, select Entity under the Others category.
Add a new component in the Inspector panel, and then select Sound.
Drag and drop an audio file into the Drop Sound input, or browse and import audio you choose.
Note: Audio files cannot exceed 10 MB.
To edit the settings of your Sound component, click the edit button (pencil icon). This populates a new panel with all your audio settings.
You can adjust the volume and select/deselect three other settings, as shown.
- Loop: Puts your audio file on repeat and loops it when the scene is in play mode.
- Auto Play: Plays your audio file automatically when the scene goes into play mode.
- 3D Audio: Puts your audio file into 3D scene. For virtual reality, this enables the sound to come from a specific location. This is best tested by adding a Sound component to an Empty entity and placing it somewhere in the scene. If the Empty entity is behind the user, the sound will come from behind. If it’s in front of the user, the sound will come from the direction they’re facing. The sound will also get louder/softer as the user approaches or creates distance between themselves and the Translation (i.e., location) of the entity. If this setting isn’t selected, the sound will originate from no specific location.
Step 3: Add Sound Effects
To add responsive sound effects, use the State Machine. We will add a sound effect to play when an entity is clicked. We will use the Sphere from the Material Fundamentals tutorial. However, you can use any visible entity.
Using Sound Component
To add a sound effect to a scene that’s responsive to a click, we need to follow the same process in Step 2 above. However, we need to add the sound, or audio file, to the the entity that’s producing the sound. For this exercise, the Sphere will make a sound effect when it is clicked. Therefore, we need to add a sound file to the Sphere entity.
- Select the Sphere entity.
- Add a Sound component to the Sphere entity.
- Drag an audio file onto the Sound component’s Drop Sound input, or browse to locate it.
Audio files in a Sound component will be accessible in the State Machine.
Using the State Machine to add Responsive Sound Effect
Select the Sphere in the Entities panel, and then add a new State Machine component. To learn more about the State Machine, see the State Machine Basics tutorial.
In the state graph, use the default State 1 and rename it “Play Sound Effect”. Then choose Add Action.
In the Add Action menu, search for and then add the Play Sound action.
In the Inspector panel, choose the sound you want to play from the Sound menu. We selected our own My Sound.mp3 file.
Add another State, name it “Click”, and then choose Add Action. In the Add Action menu, search for and then add Click/Tap on entity.
In the Inspector panel, be sure to set the Click state as the default by clicking Set As Initial State.
Finally, add two transitions between both states by clicking on an action and dragging an arrow to the other state.