Audio

The Audio Presenter, on the Visual Novel Kit prefab’s Dialogue Runner, plays four kinds of audio:

KindHow it plays
MusicOn a loop. A new track fades in over the old one.
AmbienceOn a loop, under the music, for sounds like rain or waves.
Sound effectsOnce each. Several can play at the same time.
VoiceA voice line for each line of dialogue, with no Commands.
The kinds of audio VNKit plays.

Music, ambience and sound effects

CommandWhat it does
<<music track seconds>>Plays a music track on a loop. If music is already playing, the new track fades in while the old one fades out. If it’s the same track, nothing changes.
<<stop_music seconds>>Fades the music out.
<<music_volume volume seconds>>Changes the music’s volume, from 0 to 1.
<<ambience track seconds>>Plays an ambience track on a loop.
<<stop_ambience seconds>>Fades the ambience out.
<<ambience_volume volume seconds>>Changes the ambience’s volume, from 0 to 1.
<<sound effect seconds>>Plays a sound effect once.
<<stop_sound seconds>>Fades out every sound effect that’s playing.
The audio Commands.

The duration is how long the fade takes. Like every VNKit Command, the story waits for the fade to finish, unless you add nowait:

<<ambience waves 2 nowait>>
<<music beach 3 nowait>>
<<sound thud>>
Starting the waves and the music without waiting, then a thud.

<<sound thud>> has no duration, so it starts at full volume, and the story carries on straight away.

Where audio files go

VNKit finds audio files in a Resources folder, the same way it finds images. Each kind looks in its own folder first:

CommandLooks in first
musicResources/music
ambienceResources/ambience
soundResources/sounds
The folders VNKit looks in for audio.

So <<music beach>> plays Resources/music/beach. If the file isn’t there, VNKit looks through the rest of your Resources folders, trying the names described in Naming your images. If it can’t find the file, it warns you in the Console.

Voice lines

Voice lines use Yarn Spinner’s own voice over setup. Each line in your Yarn script has a line ID, and the audio file with the same name plays with that line.

  1. Give every line a line ID, with a #line: hashtag:

    c: Lovely day for selling yarn. #line:bab4f433
    A line with the line ID bab4f433.
  2. Put the voice lines in a folder next to your Yarn Project, named after their line IDs, without the line:. For this line, the file is bab4f433.wav.

  3. Open your .yarnproject file in a text editor, and point the base language’s localisation at the folder:

    "localisation": {
      "en": {
        "assets": "Voice/en"
      }
    }
    Pointing the English localisation at Voice/en.

Lines without an audio file are shown without a voice. The VNKit Template is set up this way, with its voice lines in Assets/Dialogue/Voice/en.

See Localisation and Assets in the Yarn Spinner for Unity docs for more about line IDs and localised assets.

Keeping voice and text together

A line’s voice starts when its text starts appearing in the text box. When a different character speaks, the text box fades out and back in first, and the voice waits for the fade.

  • Pressing to finish typing a line leaves its voice playing.
  • Moving on to the next line fades the voice out.
  • If Auto Advance Dialogue is on, on the Main Presenter, the box waits for the voice to finish, then for its Auto Advance Hold Duration, before moving on.

Voiced Lines, in the Dialogue Visuals group of your Configuration asset, sets how lines with a voice are typed out:

Voiced LinesWhat it does
NormalTypes the line out with the Typewriter, like a line without a voice.
MatchVoiceTypes the line out over the length of the voice line, so the text and the voice finish together.
InstantShows the whole line as the voice starts.
The choices for Voiced Lines.

Volume settings

The Audio Presenter has a slot for an Audio Mixer Group for each kind of audio: Voice Group, Music Group, Ambience Group and Sound Group. Route each kind through its own group, and you can give each one its own volume control.

The Audio Presenter also has these settings:

SettingWhat it doesStarts as
Voice Fade Out On AdvanceHow long a voice line takes to fade out when the player moves on, in seconds.0.05
Fade Out On Dialogue CompleteHow long the music and ambience take to fade out when the dialogue ends, in seconds.0.5
The Audio Presenter’s other settings.

Saving

When the game saves, VNKit saves the music and ambience that are playing, and their volumes. Loading a save starts them again.

Next step Standalone Mode The main menu, controls, and saving.