Search Unity

Get Audio Spectrum Data from Timeline

Discussion in 'Timeline' started by daville, Jan 14, 2018.

  1. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    I have a Script that syncs to the current Audio being listened by the Audio Listener.

    I want to export an image sequence of that from the Timeline using the Unity Recorder.

    If I export a Movie, it works fine, since the Video Recording is in Realtime.

    But If I export a Image Sequence the Audio plays at normal speed (and so is my script reacting to it) but the recording takes longer, so the Audio stops at around 60% of the animation, because the recorder haven't finished yet.

    So I think I could solve this if I can get access to the waveform data in the current frame, how can I get access to that binding information?

    upload_2018-1-13_23-27-43.png
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Not sure if this is exactly what you are looking for, but there is an API for timeline that lets you dig down and get the clips on a track, and in the case of audio, get the AudioClips associated with the clips.

    Specifically GetOutputTracks, which gets all the non-grouping tracks, TrackAsset.GetClips() which get the timeline clips (for timing information). TimelineClip.asset, cast as an AudioPlayableAsset, contains the AudioClip asset being played.
     
  3. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Yes I was looking for that information, I found out about GetOutputTracks but didn't knew how to actually access the AudioClip... I'll try later what you just said.

    A related question, what happens if I have multiple Audio Tracks? how can I know which one to get?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You can name the tracks (using the inspector). That should help distinguish them. GetOutputTracks returns them in the order that they appear in timeline as well.