How to play one audio file after another?

0 favourites
  • 12 posts
From the Asset Store
This Student Workbook uses both Construct 3 & 2 encoding. It supplies client-side & php "back-end" encoding.
  • Hi!

    I created a function that plays a sound file (recorded speech) and mutes a little the other sound files (background music).

    Depending on the action, I need to run certain dialogues composed of different speech files.

    So I would like to be able to play individual recordings with speech one by one in any order and with any breaks.

    I have this code, but the second function call with the "swe0" does not work.

    Could someone guide me or suggest something?

  • I added another sound call when file with "textAudio" tag finished playing.

    Function speakText is the same.

    So this is the change in test code:

    It works almost perfect!

    File "swe16" is played, then there is a 1 second pause and "swe0" is played.

    This is great but than...

    ...there is a 1 second pause and "swe0" is playing again!

    Why is this looped?

  • I prepared a test project. Maybe this will help in finding the source of the problem.

    Could someone peek and tell me what's going on with these sounds?

    Is it difficult to set the sound files to play one after the other?

    I changed the file names in the project, now the "three" file is looped.

    drive.google.com/open

  • It's doing what you're telling it to do. You've set up an infinite loop that tells it to play a sound file with the textAudio tag when a sound file with the textAudio tag ends.

    + Audio: On "textAudio" ended 
    -> Functions: Call speakText (fileName: "trzy") 
     
    * On function 'speakText' 
    -> Audio: Play fileName not looping from Sounds at 0 dB (tag "textAudio") 
    

    You call that function the first time here:

    + System: Trigger once 
    -> Functions: Call speakText (fileName: "tututu") 
     
    + System: Else 
    -> Functions: Call speakText (fileName: "raz") 
    

    Once you call the function, it plays the file with the tag textAudio.

    The next tick it checks to see if textAudio has ended, if it has, it plays trzy with the tag textAudio.

    The next tick it checks to see if textAudio has ended, if it has, it plays trzy with the tag textAudio.

    The next tick it checks to see if textAudio has ended, if it has, it plays trzy with the tag textAudio.

    The next tick it checks to see if textAudio has ended, if it has, it plays trzy with the tag textAudio.

    etc....

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think this is what you want:

    twistedvoid.com/c3examples/testSpeaking2.c3p

    I added a new parameter to the speakText function called thisTag and updated where you called the function to pass a tag textAudio or textAudio2.

    If it's not what you want, it's a start to solving your problem.

    You'll have to move or change this function though.

    + Audio: On "textAudio" ended

    -> Audio: Fade "music1" volume to 0 dB over 0.1 seconds, then keep playing

    -> Audio: Fade "music2" volume to 0 dB over 0.1 seconds, then keep playing

  • Thanks a lot Fengist!

    Yes, it looks like a silly approach, but I was looking for a way to call this function once and I didn't find anything.

    That's why I left it as it looks and asked the question in the forum because I got stuck.

    Your solution works (thanks for the code), but it has a limit on ducking function.

    I would have to create a new tag for the sound each time and then check if it stopped playing to start the next sound with the next tag.

    This is the way to go. The tag would have a file name, so I wouldn't be wrong when arranging files and tags.

    But the problem is with the volume down function.

    Here I would have to add a lot of tags (several hundred).

    Maybe there is a way to:

    - detect if a file from the Sounds directory is playing?

    because there are speech files and music files are in the Music directory

    or:

    - can the tag checking be extended?

    for example"

    "TextAudio" + anyNumber

    But I handled this problem in such a way that I added another function:

    "unMute" - which throws the music to the output level.

    I call this function in the next condition:

    Audio -> on "my-tag" ended

    This is probably not the prettiest solution, but it works :-)

  • Yes, it looks like a silly approach, but I was looking for a way to call this function once and I didn't find anything.

    Yep, I realized what you were trying to do and why you were trying to do it. And it was a valiant attempt. Here's the thoughts just off the top of my head. Have an array of all of your voice files with say 2 fields, the file name and a boolean (as a string). Pass the file name to the 'speakText' function as a parameter. When the speakText is run, have it check the array and see where that file name is in the array and then, set the boolean to true. When the On "textAudio" ended is run, you can again, look at the array and see which one is set to true and that tells you the last audio file played. That way, you can get away with using 1 tag and still know which voice file was played last.

    This is probably not the prettiest solution, but it works :-)

    Elegance is for physicists.

  • Thanks! It exceeds me a bit what you wrote. And it scares a bit too ;-)

    I'm just getting to know this world of blocks so that the game can come alive.

    I know JavaScript a bit and wrote a small demo, it only confirmed me that the project makes sense.

    But I wanted to be able to compile my adventure game faster and visually. It is also important to be able to export it to several platforms.

    Sometimes I think I understand that and it's quite easy. Unfortunately, shortly after such moments I stand in front of the big big wall and I don't know how to get around it :-D

    Right now I am standing in front of such a wall.

    My game is based mainly on sounds, I do not need an extensive visual layer.

    I wanted to do some conditions, something like the FSM.

    I check the conditions and run the appropriate combinations of sounds and allow the player to make a decision. For example:

    - I was here

    -- I came from the north

    --- I have the key with me

    --- I don't have a key

    -- I came from the south

    --- I have the key with me

    --- I don't have a key

    - I haven't been here

    -- I came from the north

    -- I came from the south

    - etc.

    So I check if I was here or not. Then I check which side I came from. Then I check if I have specific items or if I have already done some important task.

    Here's what I did:

    drive.google.com/open

    I added the condition "if I was here" and moved the actions there.

    The effect is that the first speech file is looped ("trzy").

    Something else is missing me with Construct logic.

    I am asking for tips on where I made a mistake.

  • When you get stuck, leave the problem for a while and go back to it with a fresh mind. I slept well and today I looked at the code, I analyzed the program for a while and found an error!

    Check if I was here works every tick. Then start the sound in this block should be set: Trigger once.

    Earlier "Trigger once" I had inserted together with: WhereIwas: Contains value "landingPad". I do not know why the program worked so strange before, but the fact that the current setting as in the picture above makes sense and it works fine.

    I leave this picture and description to help someone in the future - if someone struggles with a similar challenge. And thanks again to Fengist for the hints!

  • Most welcome.

    By the way, I don't speak Polish, but I loved the quality and sound of the voices and music you have there.

  • As my kids say: This is a test attempt of the test! :-D

    My first work will be in Polish. And if people like it, then I'll write voices with English native speakers.

    I am very intrigued by the idea of an adventure game where you discover the world only with the help of sounds:

    - music selected for individual scenes and actions

    - additional noises (doors, steps etc.)

    - and of course the narrator and different characters of the story

    Such a game is to calm the mind and stimulate the imagination.

    This is something that warms my heart and I work on it in my free time :)

  • From what I heard, you're off to an excellent start. I'll be interested to see how it all turns out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)