6
$\begingroup$

I am trying to send a Wolfram demo, which contains a sound wav file.

sound = Import["C:/myfile.wav", "Data"]; snd := sound[[1]]; or snd = sound[[1]];

Is it possible to convert the wav file into the data set,- and in this form to insert in the demonstration? Or is there a problem with my Internet connection when uploading the demo? In what form do you have to prepare audio *.wav files for use in Wolfram demonstrations? What kind of audio compression is needed for this purpose?

$\endgroup$
2
  • 1
    $\begingroup$ Compress returns a string which can be Uncompressed into whatever was originally compressed. You could have something like s=string with the appropriate string, but I don't know if this is allowed in demonstrations (and you'd need to fold the cell closed) $\endgroup$
    – acl
    Commented Aug 4, 2012 at 14:38
  • $\begingroup$ The demonstrations are powered by CDFs, which unfortunately prohibit Import commands. I asked a similar question a few months back, "Deploying Mathematica Content Online." You have to have the data all in the notebook so it can be self contained. $\endgroup$ Commented Aug 4, 2012 at 17:01

1 Answer 1

12
$\begingroup$

Due to security restrictions some functions such as Import, Uncompress, or OS access functions cannot be used as a part of Demonstrations code, including the Initialization. So a generally great idea by @acl comment about compression will not work on Demonstrations site (but it's really ncie to use otherwise). This is what you get if you try to use Uncompress function inside a Demonstration code:

enter image description here

But this is what you can do. When you import a .WAV file into Mathematica notebook it has a very simple structure:

s = Import[ "ExampleData/rule30.wav"]

enter image description here

s // InputForm

enter image description here

Basically it is a simple list of numbers wrapped into functions Sound and SampledSoundList. You can extract these data and store them in a variable:

data = List @@ s[[1]];

ListLinePlot[data[[1]], PlotRange -> All, AspectRatio -> 1/4]

enter image description here

which will also (besides the data list) include the sampling frequency:

data[[2]]
44100

Include this data in Initialization for your demonstration:

enter image description here

Then inside the Manipulate you can restore your sound identically to the original as

Sound[SampledSoundList @@ data]

enter image description here

Browse these Demonstrations to see how other people deal with audio data.

$\endgroup$
2
  • 1
    $\begingroup$ Excuse me, “You cannot use Import function as a part of Demonstrations code”, - in general, or only in the "Manipulation" section. Can I put Import function in the Initialization? «Then inside the Manipulate you can restore your sound identically to the original as…»- Restore from data placed in “Initialization” section. Can I use data from external *.nb document (file). Thanks again for the response to the primitive questions. $\endgroup$
    – Alexander
    Commented Aug 5, 2012 at 6:50
  • $\begingroup$ @Alexander I changed the beginning of my answer to reflect on your last comment. $\endgroup$ Commented Aug 6, 2012 at 18:14

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.