Hello!
Today I will continue to talk about the visual novel engine 【light.vn】.
Today's topic is playing audio in light.vn!
If you've used Ren'py before, you might be familiar with this concept.
In light.vn just like Ren'py, we also have three pre-defined channels for audio:
- music: for background music
- sound effects: for sound effects
- voice: for voice-over
Although Light.VN has similar channel presets, they don't work exactly the same
What's the difference?
- You don't need to add "play" before the command in light.vn
- You have this wonderful left sidebar. With a simple click on the button there, you can add commands directly to the script open on the right side.
Like this:
- Ren'py supports the following audio file format:
- Opus
- Ogg Vorbis
- MP3
- MP2
- FLAC
- WAV
- And I did not find which / how many audio files format light.vn supports, but I've tested some common audio format files and as the result at least: mp3, wav, ogg are supported
What's similar?
- If you play two music tracks at the same time, only the second one will be played.
Example:
- As well as with sound tracks, if you write multiple sound commands, only the last one will be played
- Just like Ren'py: voice, music, and sound are played on separate channels so they will not interrupting each other
- You can preload audio files in both engines for a smoother gameplay experience
How to play audio file in Light.vn?
Play Music
- We use command 「bgm」 to play music in light.vn
bgm [filename] (repeat)
- Repeat is optional, You can write 「repeat」 at the end of the line to loop the audio file
- You can also add "0" to the "bgm" -> 「bgm0」 so that the audio file will starts play at volume 0
Play Sound
- Here we use the command 「soundEffect」 to do it
soundEffect [name] [filename] (repeat)
- Repeat is here again optional, You can write 「repeat」 at the end of the line to loop the audio file
- Unlike「bgm」name (id / tag for the file) is needed here so you must give the sound effect a name
- It can be anything like ID2 or like banana if you want to use it
- You can add "0" to the "sound effect" again here -> 「soundEffect0」 so that the audio file will starts play at volume 0
Play Voice
Its a little bit more complex here but the code will look similar to this:
voice [name] [filename] (volume variable name) (on/off variable) (noBacklogAddition)
- 「name」 and [filename] are obligated here
- Other things are all optional to add
- With 「volume variable name」 you can set an individual variable name for the voice/character.
- This variable can then be added in the config -> "config-voice" to control the volume of this character.
- With 「on/off variable」 you can set whether the player can mute this voice in the config.
- 「noBacklogAddition」: Light.vn tracks recently played voice clips and allows you to replay them easily using a voice playback button in the Backlog.
- However, there might be times when example voice clips you play in config(settings) also end up showing on this playback button. To prevent unwanted voice examples from appearing, you can use this command 「noBacklogAddition」. This setting basically tells light.vn not to add those example voice clips to the history (backlog) screen
Replay voice
Open Backlog to replay voice is not the only way to replay voice.
You can also use the quick menu shown in the right bottom of the textbox - there you will find a button called "Replay", which also allow player to reply the audio file played before.
Lip Sync
It's also very easy to do Lip Sync in Light.vn
We use a command called 「sound_cg 」 here
sound_cg [name] [filepath] [x] [y] [layer] [name] [filename / animation name] [x] [y] [layer] move per second
- First as usually we need to set a name for it
- Then we add file path (which image you want to use)
- Then we need to set x position and y position, if you used Ren'py before i guess it would be easy for you to understand what does that mean ->> set xpos and ypos for the image
- Next we got layer, 0 would be behind everything and a bigger number will bring the image to front. The layer function in light.vn I'd say its much easier to do than ren'py. If you want the image appear in front of everything (incl. quick menu, textbox, etc.) then you can set it to 999
- We need then another variable name (volume variable name) for it and this variable name should match the audio file name that you want to use later
- (Volume Variable: The "Volume Variable" is a unique identifier for the audio source's volume level. It is used to link the volume measurements to the correct image display logic)
- Then we got another x and y but this time it's not for the position anymore
- X = Measurement Interval: setting determines how frequently the volume is measured. The example provided below shows measurement at 100ms interval.
- Y = Volume Thresholds: Each measurement interval is associated with one or more volume thresholds. Each threshold has a corresponding image file to be displayed when the volume falls within that range
- Y = Minimum Volume Threshold: If the measured volume is below the minimum threshold (including silence), a default image is displayed instead
Example:
~sound_cg inu scg/kojiken/kouji_01.png 480 100 30 inu_voice 100 3 scg/kojiken/kouji_02.png 20 scg/kojiken/kouji_03.png 30 scg/kojiken/kouji_04.png
- Command: sound_cg
- Name/ Tag: inu (means dog)
- File Path: scg/kojiken/kouji_01.png
- xpos (x position) of the image: 480
- ypos (y position) of the image: 100
- Layer of the image: 30
- Volume Variable Name: inu_voice
- Measurement Interval: 100ms
- Volume Thresholds:
- 0-3: Display "kouji_02.png"
- 4-19: Display "kouji_03.png"
- 20-30: Display "kouji_04.png"
In this example, the system will measure the volume of the audio source represented by the "inu_voice" variable every 100ms. If the volume is between 0 and 3, the image "kouji_02.png" will be displayed. If the volume is between 4 and 19, the image "kouji_03.png" will be displayed, and so on. If the volume drops below 0 (silence) or exceeds 128, a default image (kouji_01.png) will be displayed.
Full Example
So here's a mix example of play audio file in light.vn:
~sound_cg chara01 new_chara/002.png 180 -350 30 new_chara_voice 50 20 new_chara/003.png
soundEffect se01 maou_game_jingle01.mp3
wait 2000
voice new_chara_voice shozyo1-katimasita.mp3
wait obj_destroy new_chara_voice
~【???】
"勝ちました!"
~movex chara01 -150 500
sound_cg chara02 new_chara/03.png 150 -100 30 new_chara02_voice 50 5 new_chara/03.png 15 new_chara/04.png 30 new_chara/04.png
movex chara02 500 500
wait 100
voice new_chara02_voice shozyo1-arigatou.mp3
wait obj_destroy new_chara02_voice
~【???】
"まだじゃ、まだいける…
~wait 300
fadeout chara02, chara01
- In this example, I first used the command「sound_cg」 to set a character who will start showing a talking animation when she speaks.
- Then, I played a sound effect (e.g., a victory sound) that is slightly louder than the voice.
- After that, as you can see, I used the command 「voice」 to play the file "shozyo1-katimasita.mp3".
- Since the tag name for the voice command matches the one used with 「sound_cg」 beforehand, the character sprite will start changing frames, making it appear as if she's speaking!
- Finally, I called another 「sound_cg」 command and repeated the process.
Also, because the sound effect is noticeably louder than the voice, players might have difficulty understanding the dialogue. In this case, they can click the "Backlog" button to replay the voice!
Check the video:
The file used in this example:
Stop Audio File
- In Ren'Py, we use this code:
stop music (fadeout xx)
- In Light.vn, it's similar. You just need to type:
fadeout bgm xx
Pause Audio File
- In Ren'Py, we use
$ renpy.music.set_volume(0.00, delay=0, channel='music')
in the script to pause the audio. - And in Light.vn, we use 「pause」 to pause and 「play」 to resume playback.
Final: Ren'py Command ➡️ Light.vn Command
Action | Ren'py | Light.VN |
---|---|---|
play background music | play music | bgm |
play sound effect | play sound | soundEffect |
play voice file | play voice | voice |
auto-voice | A little bit complex, you can check it here - Character Animated Features - Can Lip Flap Be Synched (Sync / Synced) With Voice | Check it here: - Lip Sync |
stop audio file | stop music stop sound stop ("channel") | fadeout bgm fadeout soundEffect fadeout (tag name) |
pause audio file | $ renpy.music.set_volume(0.00, delay=0, channel='music') | pause |
Also, if you don't know where to find audio assets, you can check this post we wrote a few months ago:
This however does not have english version but you can use google translation or something like that to translate it easily!
[…] Renpy To Light.vn Tutorial 【Basic #003】 - Play Audio […]
[…] Ren'py To Light.vn Tutorial 【Basic #003】 - Play Audio […]
[…] Renpy To Light.vn Tutorial 【Basic #003】 - Play Audio […]
[…] Renpy To Light.vn Tutorial 【Basic #003】 - Play Audio - YoruBox […]