Playing Sound and Music at the Same Time 2018

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Posts: 1
Joined: Fri Feb 23, 2018 5:49 pm
Tumblr: casdwelis
Deviantart: casdwelis

Playing Sound and Music at the Same Time 2018

#1 Post by veerashurra » Fri Feb 23, 2018 5:51 pm

Hello everyone!

I am a noob at Ren'Py and ran into an interesting issue while coding today. I want to play a sound effect and music at the same time, but for the life of me I cannot get it to work. I've tried using the audio channel, and I've tried registering a new channel, but I'm pretty sure I'm doing it wrong. No matter what I do, I cannot get the secondary sound effect to play over the music.

Any help would be much appreciated, or if someone could point me in the direction of an updated tutorial for this, I'd be very grateful. I can't find any new information past Feb. of 2017.


User avatar
Miko-Class Veteran
Posts: 919
Joined: Sun Jun 27, 2010 12:54 pm
Completed: AIdol, When Our Journey Ends
Projects: Connection Pending
Tumblr: MysteryCorgi
Deviantart: MysteryCorgi
Soundcloud: MysteryCorgi
itch: MysteryCorgi
Location: USA

Re: Playing Sound and Music at the Same Time 2018

#2 Post by Morhighan » Fri Feb 23, 2018 7:06 pm

Hey, welcome!

I struggled with this at first, too! I ended up figuring it out, so I'll show you how I do it. :D

The first issue I ran into with audio files was the format. I was using MP3s, which are compatible with Ren'Py. But the files were large enough to make the game kind of clunky when it tried to play them. Also the MP3 format is not open source, so I don't use it so I can avoid any fees or copyright issues.

The good news is that MP3 is not the only audio file format that is supported! OPUS, OGG Vorbis, and WAV files are also compatible. Personally, I use the OGG Vorbis format. .ogg files are pretty lightweight, size-wise, but don't sacrifice much in the way of quality!

Ren'Py allows for the use of multiple audio channels. The three default channels are music, sound, and voice, but you can add others.

The music channel plays background music. The sound channel allows for sound effects to be played. This channel is ideal for short sound effects, like a gunshot or shattering glass. Sound effects generally do not loop (so you don't deal with the gunshots on repeat.) The voice channel allows for voice acted files to be synchronized with the text of the story. Additional channels are defined into three categories: music, sfx, and voice. This allows the volume mixers to be adjusted in the settings menu.

These usually work pretty well, but I also have made use of "longer" sound effects that play over the music, like the sound of cicadas or waves or the wind blowing. Most of these are sounds that would be found in nature, so that's what I call the new channel.

To add the nature, add the following into options.rpy:

Code: Select all"nature", "sfx", True)
Where "nature" is the label, "sfx"is the volume mixer assignment, and "True" determines that the sound loops.

To play a nature sound in your script:

Code: Select all

play nature "nature.ogg"
To play a short sound effect in the script:

Code: Select all

play sound "gunshot.ogg"
To play a song in the bgm:

Code: Select all

play music "mozart.ogg"
To play a voice file with the written script:

Code: Select all

voice "line_0001.ogg"
"Hello World."
Hope this helps!

Post Reply

Who is online

Users browsing this forum: Nikois