How to add sound effects to Ren'Py menus and buttons
Pack for this guide: Crisp Cozy (free sampler on itch.io). Also fits: Crisp Cute VN.
Short answer: Give the button styles two style properties: hover_sound plays when a button gets focus and activate_sound when it is clicked. Setting them on style button in a new .rpy file covers most of the stock GUI; the choice and quick menu buttons have their own parent styles in screens.rpy, so set those too. Use config.main_menu_music for title music and config.enter_sound and config.exit_sound for the game menu. Interface sounds play on config.play_channel, which is on the sound mixer by default, so the stock Sound Volume slider already controls them; register a ui channel with its own mixer for a separate slider.
1. Put the sounds in game/audio
Ren'Py plays OGG Vorbis, Opus, MP3, WAV and FLAC. OGG files are small and loop cleanly, so they are the usual choice. Copy the interface sounds to game/audio/ui/; in code you write the path from the game folder with forward slashes, such as "audio/ui/hover_soft_01.ogg".
Keep interface sounds short, with no silence at the start, and make the hover sound quieter than the click: it plays every time the mouse crosses a button. The file names below are the ones in the free Crisp Cozy sampler, so you can drop its OGG files into that folder and use the code as it is.
2. Give every button a hover and a click sound
game/ui_sounds.rpy (a new file)
## Sounds for every button. "style button" reaches the main and game menu
## buttons, save slots, preferences and the yes / no prompt. The choice and
## quick menu buttons have their own parents in screens.rpy, so name them too.
style button:
hover_sound "audio/ui/hover_soft_01.ogg"
activate_sound "audio/ui/click_button_01.ogg"
style choice_button:
hover_sound "audio/ui/hover_soft_01.ogg"
activate_sound "audio/ui/pop_bubble_01.ogg"
style quick_button:
activate_sound "audio/ui/tap_wood_01.ogg"
## Check buttons (Unseen Text, After Choices, Mute All): one sound for on and
## one for off. A button that is already selected uses the selected_ property.
style check_button:
activate_sound "audio/ui/toggle_on.ogg"
selected_activate_sound "audio/ui/toggle_off.ogg"
- Ren'Py adds these lines to the styles already in
screens.rpyinstead of replacing them, so the stock backgrounds and text styles stay as they are. hover_soundplays when a button gets focus from the mouse, the keyboard or a gamepad. It does not play for the button that is focused by default when a screen opens, and buttons that cannot be clicked (insensitive) make no sound.- Most stock buttons (the main and game menu navigation, save slots, preference buttons and the yes / no prompt) inherit from
button. The stockscreens.rpydeclaresstyle choice_button is defaultandstyle quick_button is default, so those two need their own lines. - Style properties take prefixes.
selected_activate_soundis used when the button is already selected, so a check button playstoggle_onwhen it turns on andtoggle_offwhen it turns off.
3. Change the sound of one button
script.rpy (or any .rpy file)
default coins = 20
init python:
def buy(item, price):
store.coins -= price
renpy.notify("Bought " + item)
screen seed_shop():
vbox:
align (0.5, 0.5)
spacing 20
text "Coins: [coins]"
textbutton _("Buy strawberry seeds (5)"):
id "buy_seeds"
action Function(buy, "strawberry seeds", 5)
sensitive coins >= 5
activate_sound "audio/ui/coin_01.ogg"
textbutton _("Close"):
id "close"
action [Play("sound", "audio/ui/cancel_01.ogg"), Hide("seed_shop")]
activate_sound None
label harvest:
play sound "audio/ui/level_up.ogg"
"The garden grew a whole basket of strawberries!"
return
Any style property can be written on the button itself. The Buy button replaces the normal click with a coin sound, and while the player has fewer than 5 coins it is insensitive and silent. The Close button plays its sound with the Play action instead, and activate_sound None stops the normal click playing on top of it.
For story moments, use play sound in the script, as in label harvest. The sound channel plays one sound at a time; play audio lets several sounds overlap.
5. Give interface sounds their own channel
hover_sound, activate_sound and the enter and exit sounds all play on config.play_channel. By default that is the audio channel, on the same sound mixer as play sound, so one Sound Volume slider controls both. To let players turn interface sounds down without losing the story's sound effects, give them their own channel:
game/ui_sounds.rpy (add at the end)
## Optional: give interface sounds their own channel and mixer, so the player
## gets a separate Interface Volume slider. hover_sound, activate_sound,
## config.enter_sound and config.exit_sound all play on config.play_channel.
init python:
renpy.music.register_channel("ui", mixer="ui", loop=False)
define config.play_channel = "ui"
The new channel plays one sound at a time, so a new hover cuts the previous one short instead of piling up when the mouse sweeps across a menu. loop=False makes every sound on it play once.
6. Add an Interface Volume slider
screens.rpy, in screen preferences(), under the Sound Volume block
label _("Interface Volume")
hbox:
bar value Preference("mixer ui volume")
textbutton _("Test") action Play("ui", "audio/ui/confirm_01.ogg")
Preference("mixer ui volume")works for any mixer name; the stockmusic volume,sound volumeandvoice volumeare the same thing for the built-in mixers.- The stock Mute All button mutes every mixer, the new one included.
- To start a new player at a lower sound volume, add
define config.default_sfx_volume = 0.7(andconfig.default_music_volumefor music). Ren'Py applies these once, the first time the game runs; after that the player's own settings are kept.
How this was tested
These files were added to the stock project that ships with the Ren'Py 8.5.3 SDK, with the Crisp Cozy Free sounds and a stand-in file as the title music. Lint reports no errors. A headless run left the real main menu with the title music still playing, and checked that the navigation, save slot, yes / no, choice, quick menu and check buttons all got their sounds, that a focused button played its hover sound on the ui channel, that a check button switched from the on sound to the off sound once selected, and that the Interface Volume bar set the ui mixer.
Free assets to try
Crisp Cozy Free: 20 soft sounds as WAV and OGG: 5 button sounds, 2 toggles, 3 feedback sounds (confirm, cancel, error), a notification, 3 menu sounds (open, close, page turn), a level-up, 2 pickups, an 'animal talk' syllable and 2 cozy actions. Every file name in this guide is from it. Download Crisp Cozy Free. Listen to them first in the UI sound board.
Crisp Cute VN Free: 17 pastel GUI images for Ren'Py 8 (textbox, heart name tag, choice buttons, quick menu tray and more) at 1920 x 1080 scale. Download Crisp Cute VN Free, and see how to restyle the Ren'Py GUI to put it in.
The full Crisp Cozy ($5.99) has 1,363 cozy sounds, including more button, toggle and menu families and 25 seamless stereo ambience loops for a calm title screen. Crisp Cute VN ($6.99) is a complete Ren'Py 8 project with every screen restyled in 6 switchable pastel themes. About Crisp Cute VN: Claude (an AI assistant) designed everything in this pack: every image is drawn by code it wrote. All 19 Crisp packs are also in the Crisp Everything Bundle for $17.99.