Play Voice
Play a voice audio file

# Description

1
'play voice <voice_id> [with [properties]]'
Copied!
The play voice action let's you, as it name says, play voice files so that you can make your characters speak. You can play as many voices as you want simultaneously.
To stop a voice, check out the Stop Voice documentation.
Action ID: Voice
Reversible: Yes
Requires User Interaction: No

# Parameters

Name
Type
Description
voice_id
string
The name of the voice file you want to play. These assets must be declared beforehand.
properties
string
Optional. A list of comma separated properties with their respective value.

## Properties

The following is a comprehensive list of the properties available for you to modify certain behaviors of this action.
Property Name
Type
Description
string
The fade property let's you add a fade in effect to the voice, it accepts a time in seconds, representing how much time you want it to take until the voice reaches it's maximum volume.
volume
number
The volume property let's you define how high the voice will be played.
loop
none
Make the voice loop. This property does not require any value.

# Assets Declarations

To play a voice, you must first add the file to your assets/voice/ directory and then declare it. To do so, Monogatari has an has a function that will let you declare all kinds of assets for your game.
1
monogatari.assets ('voice', {
2
'<voice_id>': 'voiceFileName'
3
});
Copied!

## Supported Formats

Each browser has it's own format compatibility. MP3 however is the format supported by every browser.
If you wish to use other formats, you can check a compatibility table to discover what browsers will be able to play it.

# Examples

## Play Voice

The following will play the sound, and once the sound ends, it will simply stop.
Script
Voice Assets
1
monogatari.script ({
2
'Start': [
3
'play voice dialog_001',
4
'This is the dialog that the voice file is narrating',
5
'end'
6
]
7
});
Copied!
1
monogatari.assets ('voice', {
2
'dialog_001': 'dialog_file_1.mp3'
3
});
Copied!

## Loop Voice

The following will play the voice file, and once it ends, it will start over on an infinite loop until it is stopped using the Stop Voice Action.
Script
Sound Assets
1
monogatari.script ({
2
'Start': [
3
'play voice dialog_001 with loop',
4
'This is the dialog that the voice file is narrating',
5
'end'
6
]
7
});
Copied!
1
monogatari.assets ('voice', {
2
'dialog_001': 'dialog_file_1.mp3'
3
});
Copied!

The following will play the voice file, and will use a fade in effect.
Script
Sound Assets
1
monogatari.script ({
2
'Start': [
3
'play voice dialog_001 with fade 3',
4
'This is the dialog that the voice file is narrating',
5
'end'
6
]
7
});
Copied!
1
monogatari.assets ('voice', {
2
'dialog_001': 'dialog_file_1.mp3'
3
});
Copied!

## Custom Volume

The following will set the volume of this voice to 73%.
Script
Sound Assets
1
monogatari.script ({
2
'Start': [
3
'play voice dialog_001 with volume 73',
4
'This is the dialog that the voice file is narrating',
5
'end'
6
]
7
});
Copied!
1
monogatari.assets ('voice', {
2
'dialog_001': 'dialog_file_1.mp3'
3
});
Copied!
Please note however, that the user's preferences regarding volumes are always respected, which means that this percentage is taken from the current player preferences, meaning that if the player has set the volume to 50%, the actual volume value for the voice will be the result of:
$50 * 0.73 = 36.5%$

## All Together

Of course, you can combine all of this properties, and remember the order doesn't really matter, you can write the properties on the order that feels more natural to you.
Script
Sound Assets
1
monogatari.script ({
2
'Start': [
3
'play voice dialog_001 with volume 100 loop fade 20',
4
'This is the dialog that the voice file is narrating',
5
'end'
6
]
7
});
Copied!
1
monogatari.assets ('voice', {
2
'dialog_001': 'dialog_file_1.mp3'
3
});
Copied!