1
$\begingroup$

I want Mathematica (Version 11.0.1.0) to automatically play a specific sound file after importing from the hard drive without any user intervention other than opening the notebook. Here is what I have tried:

SetDirectory["D:\\MyTestDirectory"];
mysound = Import["Two_musical_notes_overlap-for-test.wav"];
EmitSound[mysound]

After that cell is evaluated I get a dialog box with a play button that the user has has to click on to get the "wav" file to play. I do not want the user to have to do anything other than evaluate the cell which will cause the sound to be played. It would be nice if I could even suppress the sound dialog box from even appearing but I'll be happy with just getting this to play automatically.

enter image description here

$\endgroup$
4
  • $\begingroup$ The observed behavior is due to that fact that in the current version, your sound file is automatically imported as an Audio[] object instead of as a Sound[] object. (It does sound confusing...) $\endgroup$ Commented Dec 31, 2016 at 9:20
  • $\begingroup$ Out of curiosity: what $Version are you using? 'Cause I have no problems with s = Import[ "ExampleData/rule30.wav"]; EmitSound[s] on 10.4.1 for Linux x86 (64-bit). $\endgroup$
    – corey979
    Commented Dec 31, 2016 at 14:56
  • 1
    $\begingroup$ @J.M. it sounds confusing made my day. $\endgroup$ Commented Dec 31, 2016 at 15:26
  • $\begingroup$ @corey979 - I am using Mathematica 11.0.1.0. The latest version. I have modified my question to include that information. $\endgroup$ Commented Dec 31, 2016 at 20:49

1 Answer 1

0
$\begingroup$

Try this:

f = Import["ExampleData/rule30.wav", "Sound"];
EmitSound[f]

This plays right away, when cell is evaluated. To make it play when notebook is opened, you might want to put it in initialization cell also.

$\endgroup$
2
  • $\begingroup$ Thank You @Nasser that worked perfectly. I guess "Audio" object is different than a "Sound" object. $\endgroup$ Commented Dec 31, 2016 at 20:53
  • $\begingroup$ Sound`AudioToSound? $\endgroup$
    – yode
    Commented Mar 30, 2017 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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