A Sound object can be programmatically played using EmitSound. Example:

snd = ExampleData[{"Sound", "AltoFlute"}];

Button["Play!", EmitSound[snd]]

What about an Audio object?

  • 1
    $\begingroup$ As a version 10 user I don't get it: why is there both Audio and Sound in v11? Is this a case of oops, we didn't plan well with Sound so let's try again with Audio or is there a completely different application that requires a different container? $\endgroup$
    – Mr.Wizard
    Oct 7 '16 at 14:26
  • $\begingroup$ Audio[] can do out-of-core stuff, e.g. Audio["http://exampledata.wolfram.com/bach.mp3"], Why Sound[] was not modified to have that ability as well, I dunno... $\endgroup$
    – J. M.'s torpor
    Oct 7 '16 at 14:28
  • 3
    $\begingroup$ @MrW Audio is supposed to be more like Image. It is highly optimized and atomic. Sound can't really be made atomic as it is meant to hold either wave or midi data and it is meant to be dissected by users. More importantly, Audio supports out-of-core processing. We can have Audio[File[...]] which won't load all the data into memory. Applying a filter to it produces another file-backed object. $\endgroup$
    – Szabolcs
    Oct 7 '16 at 14:29
  • 1
    $\begingroup$ @MrW However, in my tests Audio filters are much slower than the equivalent filter in the open source Audacity, so I think it has a long way to go. $\endgroup$
    – Szabolcs
    Oct 7 '16 at 14:31
  • 1
    $\begingroup$ @Szabolcs I have a same confusion with @Mr.Wizard ,Why the W.R. make a new Audio but not refine the old Sound?And it's seem the Mathematica process the Audio file which have a same size with Image is lower efficiency. $\endgroup$
    – yode
    Oct 9 '16 at 18:51

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

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

  Audio`AudioInformation[au, "AudioID"]],

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.

  • $\begingroup$ You mean Audio`Play work? $\endgroup$
    – yode
    Oct 7 '16 at 15:57
  • $\begingroup$ @yode No it won't work because insetad of Audio`AudioInformation[au, "AudioID"] it does "AudioID" /. Options[au], which fails. $\endgroup$
    – Szabolcs
    Oct 7 '16 at 18:29
  • $\begingroup$ @Szabolcs If I start it playing this way is there a way to get the current time index dynamically as it plays? I tried using Audio`Internals`Execute[ Audio`Internals`GetAudioManager[id], "GetDataPosition"] but no luck. $\endgroup$
    – M.R.
    Oct 12 '16 at 20:53
  • $\begingroup$ @M.R. I don't know. $\endgroup$
    – Szabolcs
    Oct 12 '16 at 21:07

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.