Audio

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Object 1 Object 2

COVID-19 Support:
We’re providing all users three months of complimentary access to Unity Learn Premium, from
March 19 to June 20, 2020.
Projects
Courses
Tutorials
Learn Live
Topics

Premium

Working with Audio Components - 2019.3


Tutorial
Beginner
20 Mins
Overview
Details
2
Your progress
Where am I?
1.
Working with Audio Components
2.
What are Audio Clips?
3.
Preparing and Importing Audio Files
4.
Adding an Audio Source Component
5.
Adding an Audio Listener Component
6.
Conclusion
Summary
Unity’s audio system is flexible and powerful. It can import most standard audio file formats and
has sophisticated features for playing sounds in 3D space, optionally with effects like echo and
filtering applied. Unity can also record audio from any available microphone on a user’s machine
for use, storage and transmission. In this tutorial, you will learn about the different components and
how they can be used.
Recommended Unity versions
2019.3 and Above
Topics we'll cover
Audio
Industry
AEC
Automotive
Film
Games
Language
English

Tutorial
Working with Audio Components - 2019.3
2

1.Working with Audio Components


If you are using Unity 2019.2 or below, click here.

Remaining Time -5:26


1x
2.What are Audio Clips?
Unity imports audio files as Audio Clips. To use an Audio Clip in a Scene, you must first attach it to
a GameObject. A GameObject with sound attached to it is an Audio Source — think of it like a
speaker. An Audio Source’s sound is picked up by an Audio Listener (the microphone), which is
usually attached to the main camera, and played through the computer’s speakers. Sounds can be
modified with Audio Effects to take into account things like where the Audio Listener is located in
relation to the sound or a GameObject’s role in a Scene. (Figure 01)
Figure 01: Import settings for an audio clip in the Inspector
3.Preparing and Importing Audio Files
Unity supports AIFF, WAV, MP3, and Ogg file formats and mono, stereo, and multichannel audio
with up to eight channels. Live audio can also be recorded directly during gameplay using a
microphone connected to a user’s computer.
In Unity, an audio file can be saved at different sample rates. The lowest you’d want is 11025Hz,
with 22050Hz or 48000Hz being ideal. A higher sample rate will result in larger files. For AIFF and
WAV audio files, make sure the bit depth is 32-bit and not floating point.

1. Create or save an audio file using the settings necessary for Unity.
2. Import your audio files into your Unity Project. Audio files can be imported into a project much
like other files: either drag the audio file into the Project panel, or place the audio file in the Assets
directory of the Unity Project directory.
Note: Importing an audio file creates a container for the audio data called an Audio Clip.
3. In the Project panel, select the imported Audio asset.
4. In the Inspector panel, change import settings if necessary. For example, if your audio file has
two tracks for stereo, you can select Force to Mono if stereo separation isn’t needed. There are also
platform-specific settings for each type of build. (Figure 02)

Figure 02: Change the import settings in the Inspector panel.


5. At the bottom of the Inspector panel is a waveform preview of the imported audio file. You can
preview the audio by pressing play. (Figure 03)

Figure 03: The waveform preview of an audio file in the Inspector panel.

4.Adding an Audio Source Component


An Audio Source GameObject component plays back an audio clip in a Scene. To play, the
component needs an assigned audio clip. The audio clip is the actual sound file that will be played
back. The Source is a controller for starting and stopping playback of the audio file and modifying
other audio properties. (Figure 04)

Figure 04: Parameters of the Audio Source in the Inspector panel


To add an Audio Source Component:
1. Select GameObject menu > Audio > Audio Source. This will create a GameObject in the
Scene, with an Audio Source component attached.
2. Assign the previously imported audio file to the Audio Clip property of the Audio Source
Component in the Inspector. You can do this by dragging the audio clip from the Project panel into
the Audio Clip property field, or click the radio button next to the property field and selecting the
audio clip from the Assets window. (Figure 05)

Figure 05: Assign an audio file to the Audio Clip property.


3. Adjust any settings for the audio clip for the GameObject.
Adjust the Audio Source parameters to change how and when the audio is played. The Play On
Awake option is on by default, and will play the audio clip as soon as the Scene begins. If the audio
clip needs to play during a specific action, such as footsteps as a character is walking, click the Play
On Awake option. The loop option will play the audio clip over and over until the action stops. This
is helpful with actions like walking, because the footsteps will continue as long as the action
happens.

5.Adding an Audio Listener Component


In real life, sounds are transmitted by an object’s vibrations. Those vibrations are received by a
listener. A listener can tell roughly which direction a sound is coming from and may also get some
sense of its distance based on loudness and quality. A fast-moving sound source (like a falling bomb
or a passing police car) will change in pitch as it moves. Also, surroundings will affect the way
sound is reflected, so a voice inside a cave will have an echo but the same voice in the open air will
not.
To add an Audio Listener Component:
1. Create a GameObject, such as a camera or a character controller, and click Add Component in
the Inspector panel.
2. Select Audio > Audio Listener. This will add an Audio Listener component to the GameObject.
(Figure 06)
Figure 06: Adding a Audio Listener component
The Audio Listener GameObject component has no properties (Figure 07). It’s included on the
Main Camera by default, and included with any new cameras. The Audio Listener can also be
attached to a GameObject that represents the player so the audio will play based on the position of
the player, rather than the camera. However, a Scene can have only one Audio Listener component
attached to an object.

Figure 07: The Audio Listener component has no other properties.


6.Conclusion
With a few basic steps, you can add audio clips to a project, set up sources to transmit sound in a
Scene, and select objects, character controllers, or cameras as listeners to receive the sound and play
it back. Using audio components adds realism and provides interactive feedback for the player.

Working with Audio Components - 2019.3


General Tutorial Discussion
0
0
1. Working with Audio Components
0
1
2. What are Audio Clips?
0
0
3. Preparing and Importing Audio Files
0
1
4. Adding an Audio Source Component
0
0
5. Adding an Audio Listener Component
0
0
6. Conclusion
0
0
Copyright © 2020 Unity Technologies
Legal
Privacy Policy
Cookies
Language:

English
简体中文
한국어
日本語
Русский
Español
Français
Deutsch
Português

You might also like