Help with your scripting

Concatenate Sounds

Concatenate Sounds

Postby Shando » 12 Nov 2017, 02:20

Hi All,

Just wondering if there was an easy way to play Sounds one after the other?

I'm trying to add speech to my game but have come across a few issues with creating the sound files. At the moment I'm creating a different sound for each required phrase, so, for example, the following text:

Code: Select all
sTmp = "You have produced " .. iProduction .. " Commodities this turn! Please press the buttons below to allocate it into Storage and press OK when finished. NOTE: The RESET button will reset your Stored Commodities back to their original values."


would need multiple different versions depending on the value of iProduction:

IG221.ogg (iProduction = 1)
IG222.ogg (iProduction = 2)
IG223.ogg (iProduction = 3)
...
IG2210.ogg (iProduction = 10)

I'm currently limiting them to a maximum of 10, but until I test this part of the game, I'm not 100% sure what the maximum value would be :(

I would like to be able to play 3 different 2D Sounds to generate the above speech, as it would make my life so much easier:

IG22.ogg (First part of text)
NO1.ogg (Number 1 - i.e. iProduction = 1)
IG23.ogg (Second part of text)

then play them in sequence.

Short of writing something in the onUpdate function, I can't see a way around this? Also, I have rather a lot of speech to do, which would make using onUpdate almost unmanageable, so was hoping there would be some other way (maybe something like a Sound buffer that will only play the next item in the buffer if the previous one has finished?).

Any help/thoughts would be gratefully received.

Regards

Shando

[EDIT] I have managed to put together the code below, which seems to work OK, just a minor issue with timing, but not a problem for now:

Code: Select all
tSB = { }
iSB = -1
iCurSB = 0

function onUpdate( td )
   updateSoundBuffer ( )
end

function onKeyDown( key )
   if ( key == "a" ) then
      addToSoundBuffer ( "IG1.ogg" )
      addToSoundBuffer ( "IG2.ogg" )
      addToSoundBuffer ( "IG3.ogg" )
   elseif ( key == "p" ) then
      playSoundBuffer ( )
   end
end

function addToSoundBuffer ( sIn )
   local iLen = tableLength ( tSB )
   iLen = iLen + 1
   tSB[iLen] = sIn
end

function playSoundBuffer ( )
   sound.setSoundFile ( tSB[1] )
   sound.setIsStreamed ( 0 )
   iSB = sound.create2DSound ( )
   sound.play2DSound ( iSB )
   iCurSB = 1
end

function updateSoundBuffer ( )
   if ( iCurSB > 0 ) then
      if ( sound.isPlaying ( iSB ) == 0 ) then
         sound.freeSound ( iSB )
         iCurSB = iCurSB + 1
         
         local iLen = tableLength ( tSB )

         if ( iCurSB <= iLen ) then
            sound.setSoundFile ( tSB[iCurSB] )
            sound.setIsStreamed ( 0 )
            iSB = sound.create2DSound ( )
            sound.play2DSound ( iSB )
         else
            tSB = { }
            iSB = -1
            iCurSB = 0
         end
      end
   end
end

function tableLength ( inT )
   local iC = 0

   for _ in pairs ( inT ) do
      iC = iC + 1
   end

   return iC
end
Last edited by Shando on 12 Nov 2017, 03:04, edited 1 time in total.
Reason: Added Code
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 492
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Concatenate Sounds

Postby Shando » 12 Nov 2017, 08:20

Or the other option would be for the Devs to implement something like this:

http://espeak.sourceforge.net/

eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows.  

eSpeak uses a "formant synthesis" method. This allows many languages to be provided in a small size. The speech is clear, and can be used at high speeds, but is not as natural or smooth as larger synthesizers which are based on human speech recordings.

eSpeak is available as:
A command line program (Linux and Windows) to speak text from a file or from stdin.
A shared library version for use by other programs. (On Windows this is a DLL).
A SAPI5 version for Windows, so it can be used with screen-readers and other programs that support the Windows SAPI5 interface.

Features:
Includes different Voices, whose characteristics can be altered.
Can produce speech output as a WAV file.
SSML (Speech Synthesis Markup Language) is supported (not complete), and also HTML.
Compact size. The program and its data, including many languages, totals about 2 Mbytes.
Can be used as a front-end to MBROLA diphone voices, see mbrola.html. eSpeak converts text to phonemes with pitch and length information.
Can translate text into phoneme codes, so it could be adapted as a front end for another speech synthesis engine.
Potential for other languages. Several are included in varying stages of progress. Help from native speakers for these or other languages is welcome.
Development tools are available for producing and tuning phoneme data.
Written in C.


It's available as a DLL and under the GNU GPL :mrgreen:
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 492
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Concatenate Sounds

Postby SolarPortal » 12 Nov 2017, 10:27

unfortunately "GNU GPL" is not a license we can use because whatever that source is added into would also need to be licensed as GPL which stops any commercial usage. We tend to avoid this at all costs lol :P LGPL is better as we can link as a dynamic library without being subject to changing our source license. MIT is preferred though :)

As for a sound buffer, we have some audio updates planned in because only a maximum of 16-32 sounds can be played at any one time. This is not a skyline issue, but more what the audio cards built into motherboards are capable of. so we will be switching to creating buffers that are then played into the audio queue instead.

As for your issue, at the moment, using the onUpdate would be your best best, or using a timer might be even better to save some CPU cycles.

Also note, if you dont want the sound file to be auto deleted once its finished playing then you need to pass a 0 into createSound function.. :)

Sorry i coulnt be of more help, but thats the best we have at the moment..
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3157
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Concatenate Sounds

Postby Shando » 12 Nov 2017, 11:25

Hi SP,

unfortunately "GNU GPL" is not a license we can use

Yeah, thought that was the case :(

Also note, if you dont want the sound file to be auto deleted once its finished playing then you need to pass a 0 into createSound function..

So, if the sound is auto deleted, then I don't need to call the freeSound?

Code: Select all
         sound.freeSound ( iSB )

using a timer might be even better to save some CPU cycles

As my game is not an FPS, CPU cycles don't really make too much of a difference ;)

Thanks for the info, what I've come up with seems to do the job for now, so I'll go with it :)

Shando
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 492
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Concatenate Sounds

Postby SolarPortal » 12 Nov 2017, 12:00

So, if the sound is auto deleted, then I don't need to call the freeSound?

yes, and this is the default behaviour, but once its deleted you obviously cant playsound with the same id again as it doesnt exist, so you would have to call createsound() again. the argument 1 = self delete, and 0 = no self delete.

Its done this way to stop the system running out of sounds and ensure that audio is cleaned properly :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3157
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron