Playing voice files

Adding voice audio when characters speak can greatly increase your game's immersion. Each line can either have an audio file manually associated with it (or multiple, if your game supports spoken translations), but they can also be associated automatically through naming convention.

For a character to play speech audio, they must have an AudioSource component. This is a simple matter of finding their prefab, clicking Add Component, and selecting Audio Source.

Note: If this is added to a child object, and not the root object, then you must also assign it to the character's Speech AudioSource field.

Next, we want to have AC search the project and identify all speech lines used by the game.

You will need to ensure that all of your game's scenes are added to Unity's Build Settings.

Navigate to the Speech Manager in AC's Game Editor window. There are a few ways to associate a line with an audio clip - here, we're going to do it by naming convention. This set set via the Reference speech files option in the "Speech audio" panel:

For the other methods of associating lines to clips, refer to the Manual's "Speech audio" chapter.

In the "Game text" panel, click Gather text. Adventure Creator will search your game for displayed text, and list it beneath.

The number to the left of each line is it's ID number. To create a file that lists just your speech text, click Create script sheet..., and you will be prompted to save a script file.

The lines will be grouped by the scene in which they appear, and also display the filename the associated audio file must have. Audio files can take any audio format that Unity natively understands, such as mp3 and ogg. For example, the first line shown above can have an audio file of either Player2.mp3 or Player2.ogg.

Once you have created your audio files, you need to place them within a subfolder called Speech, within a folder called Resources. Note that the location of this Resources folder is not important: /Assets/My Game/Resources/Speech is as valid a filepath as /Assets/Resources/Speech. You can select any of the lines in the Speech Manager to reveal its expected filename and folder:

In the next tutorial, we'll cover Unity's Addressables system, which offers a more performant way of playing speech audio.