6

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?

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
Alexandr
  • 61
  • 2
  • 1
    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 04 '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. – canadian_scholar Aug 04 '12 at 17:01

1 Answers1

12

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.

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
  • 1
    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 05 '12 at 06:50
  • @Alexander I changed the beginning of my answer to reflect on your last comment. – Vitaliy Kaurov Aug 06 '12 at 18:14