BGE slideshow presentation sound effects

UPDATE! SOLVED!

I got the help that I was looking for :slight_smile:

The updated .blend file can be found here:
http://files.manujarvinen.com/blender_game_engine_slideshow_template_v0.3.blend

Original post:

Hi!

I’m making this Blender Game Engine Slideshow Presentation and I was wondering if you could know how to add sound files to be played on the timeline. Sequencer doesn’t seem to work.

I added an ukulele-sound to sequencer and packed it into the .blend for you to try out.

The .blend file can be found here:
http://files.manujarvinen.com/blender_game_engine_slideshow_template_v0.3.blend




You have to use the sound actuator to play sounds.

But how to activate them to happen on certain frames of the animation?

Just to let you know, I can hear the ukulele sound on my computer (with Windows, Realtek Audio) in the sequencer. What you could try doing in the sequencer is going to Strip->Reload Strips (alt-R). You could also try Strip->Unmute strips (alt-H) to see if that works. Hope that helps.

Ah, yes. The music can be heard if you play the timeline - but not if you start the game engine by pressing ‘P’, which is how I like the thing to work, as it is a slideshow presentation.

Ah, sorry I misunderstood.

Try adding:

import aud
sound = aud.Factory.file("the_sound_you_want.ogg")
device = aud.device()

at the beginning of your file and then inserting:

if round(own['frame']) == 52:
    if not own['music']:
        device.play(sound)
        own['music'] = True

after you list your step frames in code.

Also, try adding a property called ‘music’ as a boolean set to False.

Basically, what this does is utilize the aud library, and then plays the desired sound around frame 52 (with some margin of error). The code also prevents the sound from being played twice because of a simple flip switch called ‘music.’

Hope that helps.

Thanks, Mirror|rorriM

Even though, I can’t get it to work :confused:

Could you do that in the provided .blend, perhaps?

You’re welcome!

Here’s the file, I hope it works for you:
http://www.filedropper.com/blendergameengineslideshowtemplatev03

Unfortunately for me, I was unable to upload anything else due to a maximum upload restriction, and my uploads haven’t been deleted within an hour despite me not using them. I’ve tried deleting the uploads (by clicking the x’s on the top right hand corner) but to no avail. I was wondering if someone could help me with this. I’d appreciate that.

Thanks! The file works fine. I appreciate your helpfulness.

Even though still, I can’t hear anything, even after switching your airtone_-_H2O_instrumental.mp3 to something else I have. Where should the sound file be located, next to the .blend file? At frame 52 I don’t hear anything when I press P and navigate :frowning:

Hi again maxon,

For your specific case, the sound file should be located in the same directory as your blender file.

For other cases (and yours as well), the path to the sound file can be specified within the directory and subdirectories of the blender file using aud.Factory.file(…) like this:

sound = aud.Factory.file(bge.logic.expandPath(//...)

or

sound = aud.Factory.file(GameLogic.expandPath(//...)

for GameLogic.

Here’s an additional resource: https://blenderartists.org/forum/archive/index.php/t-218811.html

Please ask again if it still doesn’t work.

for GameLogic.

do not use gamelogic its very outdated and has been replaced with logic: bge.logic

Thanks for helping me out Mirror|rorriM and Cotaks, this is the best :slight_smile:

So, if I have this directory structure

/slideshow.blend
/audio/sound_effect.mp3

Should I then mark it like so?:
sound = aud.Factory.file(bge.logic.expandPath(//audio//sound_effect.mp3)

Anyways, I had the sound file in the same directory as my .blend and I didn’t get it to work still, I hear nothing :frowning: What can I do?

sound = aud.Factory.file(bge.logic.expandPath(//audio//sound_effect.mp3)

almost.

sound = aud.Factory.file(bge.logic.expandPath(//audio/sound_effect.mp3)

the first // is there for the logic, it knows that // means that it needs to open the directory where the .blend is run from.
the second / is the marker for folder structure.

Does your animation start as soon as you start the game? If so, you can use a delay sensor to wait 52 frames, and then play your sound via the sound actuator.

YES! No we’re getting somewhere :slight_smile: And the Logic Bricks are so easy to use for multiple sound files. But I still have the issue that this Delay Sensor is activated immediatelly when I press ‘P’. It should activate only after I press left, right or spacebar. And I wonder how this works when I add another sound file for ie. slide number 3.

Could any of you by chance know how to activate the Delay sensor only after I’ve pressed left, right or spacebar?


With your color scheme its hard to tell what options are selected. What options are selected for the delay?

You wouldn’t want the duration to be that long. The duration affects how long the signal is sent. This would cause the audio file to start and stop for 155 ticks. You should have it set to 1, and the tap option selected. This would cause the audio file to play 55 ticks after “p” is pressed.

Now you want the delay to only star after you begin walking? That’d be a bit more tricky. I’d not use delay for this, but instead use the timer property. Try setting up a system that sets the timer to zero when space-bar is pressed, and then when the timer equals 3, then the audio file is played. The only problem is that the timer works in seconds, not ticks. 55 Ticks is nearly a second on a 60 fps simulation, so you’d want a 1 second delay.

To be more specific, add the space bar sensor that sets the timer to zero. Then below that add a sensor that detects the timer being between 1 and 2 seconds. Connect this sensor to your audio actuator, and it should delay properly. The 1-2 second interval seems to work more reliably than just 1 second.

Thanks for the good answer!

Sadly, I’m such a newbie this will be difficult for me to do. I’ll try my best, though

Would it be such a coward move to ask if you could do this in the provided .blend and send it back to me? It’s all simple once it’s done, but until then, I’m soooo lost :stuck_out_tongue:

Well, I try my best. Thanks for the input!

It’s no problem to use seconds, I can watch the correct position from Sequencer.

You’re welcome!

When you put your sound in the same directory as the .blend file, did you, in the code, put quotes around the path name?
i.e.) sound = aud.Factory.file(“your_sound_file.[EXTENSION]”)

It needs quotes.

By the way, Cotaks has the right idea for using the “expandPath” method.


Try this. You can also add more conditions to the controller for the sound. Such as one that ensures it only plays on slide 4, or otherwise.

YES! Now this works well for me!

However, how can you do that, to actually have it play only on slide 4, for example? Now every time I press Spacebar the sound is played.