Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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) – acl Aug 4 '12 at 14:38
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. – programming_historian Aug 4 '12 at 17:01

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:


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.

share|improve this answer
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. – Alexander Aug 5 '12 at 6:50
@Alexander I changed the beginning of my answer to reflect on your last comment. – Vitaliy Kaurov Aug 6 '12 at 18:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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