Syncing audio and program actions. What's the best approach?

0 favourites
  • 9 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • WHAT I'M TRYING TO DO:

    I want to record my voice, and while I'm recording, press number keys on my keyboard at specific times.

    Then I want to play back the audio recording, and have code trigger at the specified times.

    For example, I might record a story that includes me saying: "Then Sally turned the corner and she saw a large bear! It raised up!" At the appropriate time I would press "1" on the keyboard. (This uses Date.now to tell me that "1" was pressed at 6.364 seconds.)

    When someone PLAYS my "story" I will play/stream my audio file and start checking the timestamps. At 6.364 seconds that first timestamp would trigger, and the "1" would tell me to play an animation where the bear raises up.

    CONCERNS

    Some of my stories could last 15 or more minutes and I'm concerned that there could be lag or other issues that make the audio get out of sync with the timestamps.

    Is there a better approach that I should be using?

  • One thing that I have considered is adding high pitched sounds at certain points in my audio recording. Maybe sounds that are too high for human hearing?

    Would I be able to detect those high pitched "pings" using the audio analyzer?

  • I don't think lag would cause the audio to desync. How exactly are you checking the timestamps? Because the audio object offers you Audio.CurrentTime or Audio.PlaybackTime(Tag) which you can compare against your timestamps. Even if the audio lags these should be consistent with timings.

    I wouldn't go with the high pitched pings, that sounds terribly hacky.

  • Thanks, WackyToaster! I don't often get replies to my questions here so I appreciate the response. :-)

    I'm saving the timestamps in a dictionary object and then comparing them against the current time every tick. (That's the idea anyway, haven't tried it yet.)

    I hadn't found the Audio.CurrentTime or Audio.PlaybackTime(Tag) properties yet, but those sound like they should work much better. Thanks!!

  • Haha. No, I'm not making a story book app. :-) I just came up with that as an example since it seemed easier to explain.

    I'm actually trying to control a TENS machine using Bluetooth, and I want to sync signals from the machine with a long audio file that is playing.

    Thanks for the reply anyway! I appreciate it!

  • Because the audio object offers you Audio.CurrentTime or Audio.PlaybackTime(Tag) which you can compare against your timestamps.

    I'm not sure if it's a bug, but apparently "Audio.PlaybackTime(Tag)" doesn't work when you load a sound externally. (Using "Add remote URL".)

    Maybe I can simply use timers.

  • > Because the audio object offers you Audio.CurrentTime or Audio.PlaybackTime(Tag) which you can compare against your timestamps.

    I'm not sure if it's a bug, but apparently "Audio.PlaybackTime(Tag)" doesn't work when you load a sound externally. (Using "Add remote URL".)

    Maybe I can simply use timers.

    The project I'm working on uses external audio url, and I use "audio.playbacktime" very often for syncing objects to the music, which works well! I haven't had the same bug that you have described. Hmm..

  • The project I'm working on uses external audio url, and I use "audio.playbacktime" very often for syncing objects to the music, which works well! I haven't had the same bug that you have described. Hmm..

    That would be awesome if it worked!! Thanks for the reply! Hmm. I must have been doing something wrong. Here's what I did:

    FIRST TEST

    1. I played a .webm file, stored on my website. I could hear the file playing.

    2. Every tick: Set text file to "Audio.PlaybackTime(tag)". (The text field just stays blank.)

    SECOND TEST

    1. I saved the .webm file to my project and ran it like a normal sound effect.

    2. Every tick: Set text file to "Audio.PlaybackTime(tag)". (As soon as I start the sound I see numbers climbing in the text field.)

    Let me try it again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, fixed my problem.

    I was using a tag when I downloaded the sound, but not when I *played* the sound. Once I set and used that second tag it worked great!

    Thanks, Jase00!

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