Sound callback (text and sound sync) (SOLVED)

nope, only make the table with timing of sounds and use the timer to catch complete event.

:frowning: crap

Is there a way to handle the volume/gain?

Yeah use openal extention for sync text and sound.

This my code:

in on_message receieve message from text source and start sound:

                        local res = resource.load("/Voices/"..self.currentSoundId..".wav")			
			self.soundSource = openal.new_source(res)
			if self.soundSource then
				self.soundSource.x, self.soundSource.y = 0, 0
				self.soundSource.is_looping = false
				self.soundSource:play()
    		end

in on_update wait sound stop state. If sound stop - send callback message to text source.

if self.soundSource then			
			local soundState = self.soundSource.state
			if soundState == "stopped" then
					self.soundSource:stop()			
					msg.post("#","SoundStopPlay",{soundId = self.currentSoundId})											
			end	
		end
1 Like

I make it on start, but now we hve openal extenstion and absent problem.

yep, openal is great! But there is one another problem - build size. If .wav files used instead .ogg for music for example.

For music you can use standart sound object and ogg.

of course, but if you want sequence of music (long level. etc,) you need to known when music file is done :slight_smile:

Solved in 1.2.162

2 Likes