Ren'Py Sound in a series of images?

Xenorav

Newbie
Game Developer
Sep 30, 2020
24
2,483
I want to put sounds between each image in a series of images, is this possible?
I mean something like this:
image movie:
"image1"
0.009
"image2"
0.009
play sound "sound.ogg"
"image3"
0.009
"image4"
0.009
play sound "sound2.ogg"
"image5"
0.009
repeat
Obviously this did not work, I just want to know if there is a way to do something like this without having to convert my images into a video file.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Your base image movie: is part of the . Unfortunately for you, ATL only controls images, not sounds.

As I see it, your problem is the repeat. Without that, you could do something like this:

Python:
image movie1:
    "image1"
    0.009
    "image2"
    0.009

image movie2:
    "image3"
    0.009
    "image4"
    0.009

image movie2:
    "image5"
    0.009

# blah, blah, code.

    scene movie1
    play sound "sound.ogg"
    scene movie2
    play sound "sound2.ogg"
    scene movie3
You might be able to build the whole thing as a and have some sort of timer that played the sounds. But I suspect that would get out of sync very quickly. My thinking is that by using a screen:, where the sound and image are both looping, the screen code still allows for the game to recognize when the player uses the mouse in order to click to advance.

Alternatively, you could merge the sound1.ogg and sound2.ogg together with very specific length silences into a single sound file that is played on repeat at the same time the image movie is shown on screen. Though again, there is no guarantee they would remain in sync.

Python:
# blah, blah, code.

    scene movie
    play sound "sound.ogg" loop

    "Some dialogue"
    "Some more dialogue"

    stop sound
    scene black

While I'm not sure it's the right answer, my 2nd solution is probably what I would test before resorting to creating a simple movie file. Honestly, I'd probably be moving straight to the video solution, rather than spending time testing something I didn't have much faith in.

This is not an area I'm particularly strong in. So perhaps someone else will come up with a better answer. Good luck.
 

drKlauz

Newbie
Jul 5, 2018
40
24
Actually you can inject sounds into ATL with some tricks.
Code:
init python:
  class atl_play_sound(object):
    def __init__(self,sound):
      super(atl_play_sound,self).__init__()
      self.sound=sound
    def __call__(self,*args,**kwargs):
      if not renpy.predicting():
        renpy.play(self.sound)

image test:
  "test/f001.png"
  0.1
  "test/f002.png"
  0.1
  "test/f003.png"
  0.1
  function atl_play_sound("audio/test.ogg")
  "test/f004.png"
  0.1
  "test/f005.png"
  0.1
  repeat

label start:
  show test
  "testing"
  return
 

Xenorav

Newbie
Game Developer
Sep 30, 2020
24
2,483
Actually you can inject sounds into ATL with some tricks.
Code:
init python:
  class atl_play_sound(object):
    def __init__(self,sound):
      super(atl_play_sound,self).__init__()
      self.sound=sound
    def __call__(self,*args,**kwargs):
      if not renpy.predicting():
        renpy.play(self.sound)

image test:
  "test/f001.png"
  0.1
  "test/f002.png"
  0.1
  "test/f003.png"
  0.1
  function atl_play_sound("audio/test.ogg")
  "test/f004.png"
  0.1
  "test/f005.png"
  0.1
  repeat

label start:
  show test
  "testing"
  return
It works perfect! I've looking for hours about this and just now I saw your answer, thank you very much!
 
  • Like
Reactions: ouzkee and drKlauz