Playing snippets of audio from one file

Hi, total noob here,

I’m creating a story book app. Each page has an audio clip of the narrator reading the text. Once the narrator finishes, the reader can click on a word and have it spoken back to him.

So if the narrator says “The quick brown fox jumps over the lazy dog.” Then the reader can click on “fox” and ideally, the same audio clip would play, but just start before the word “fox” and stop right after.

  1. Does Unity allow for playing sections of an audio clip like this?

  2. Do audio files allow you to encode meta data? For instance, I would want to have markers in the file where words stop and start.

Thanks, everyone!

  1. Yes. You can use time or timeSamples in AudioSource to have something play from or jump to that time.

  2. AFAIK, no. You’d have to bring the markers in as a separate file, like XML or a custom Scriptable Object subclass.

1 Like

Awesome, thank you for your reply, this is really helpful!