# How to use and input audio wav file into a Wolfram demonstration

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?

-
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:

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"]


s // InputForm


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]


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

data[[2]]

44100


Include this data in Initialization for your demonstration:

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

Sound[SampledSoundList @@ data]


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

-
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