How to programmatically play an Audio object?

The following resulted from a lot of spelunking and reading the code of Audio`Play.

au = ExampleData[{"Audio", "Bird"}];

Audio`Internals`Execute[
 Audio`Internals`GetAudioManager[
  Audio`AudioInformation[au, "AudioID"]],
 "Play"
 ]

Audio`Play does the same thing except it gets the "AudioID" in a different way which appears to fail.

There are many other commands that can be executed, e.g. "Stop", "Pause", etc. See the definition of Audio`Internals`Execute.

If the audio object is being displayed in the notebook, the seekbar will start moving on playback.

Warning: This is undocumented functionality. I was doing spelunking in M11.0.1 and Audio was introduced in 11.0.0. I expect that the Audio stuff is still under heavy development. I won't be surprised at all if the above stops working in the next version of Mathematica.


You can also use Sound`AudioToSound[] to convert the Audio[] object to a Sound[] object that can then be passed to EmitSound[]:

ExampleData[{"Audio", "Bird"}] // Sound`AudioToSound // EmitSound

Of course, this is only recommended for modestly-sized Audio[] objects.

Tags:

Sound