Message Boards Message Boards


What functions are available for Importing Sound files into M? *.WAV ?

Posted 9 years ago
3 Replies
2 Total Likes

Q1) I have been trying to import a sound.WAV file into M8 without success. I need to decipher the WAV header for # samples, sample rate, bits/sample, stereo y/n, ... I would greatly appreciate a code snipet that would accomplish this.

Q2) I can use Import["C:\dir1\dir2\sound.WAV","wave"] to load a complete file plus header.If the size of the file exceeds about 6MBytes, M8 "fails". Is there a real limit to the size of wave file that M8 can handle OR is this another mistake on my part?

POSTED BY: Gerald Kamin
3 Replies

This can be automated

fileName = "one.wav";
ele = Import[fileName, "Elements"]

Which gives, for this file

  {"AudioChannels", "AudioEncoding", "Data", "SampledSoundList", "SampleRate", "Sound"}

and now

 all = Import[fileName, #] & /@ ele;
POSTED BY: Nasser M. Abbasi

I was specifying that limited set of elements because the others are raw data from the audio of the file itself. If one wanted to fetch all available elements for a file, one could use

Import[fileName, #]&/@Import[fileName, "Elements"]

I'm pretty sure the set of available elements is the same for all wav files though.

POSTED BY: Jesse Friedman

This gets you all of the metadata directly available to Mathematica:

Import["ExampleData/rule30.wav", #] & /@ {"AudioChannels", 
  "AudioEncoding", "SampleRate"}

And this gets you the number of samples:

Length[Import["ExampleData/rule30.wav", "Data"][[1]]]

Bits per sample is a bit more complex, but I think this should be what you're looking for:

N[(Length[Import["ExampleData/rule30.wav", "Bit"]])/(Length[
    Import["ExampleData/rule30.wav", "Data"][[1]]])]

I don't know if there are any import limits or restrictions in M8, but M10 loads an 18mb file without a hitch. It's probably either the older version or some kind of memory problem on your computer. Could you post the message Mathematica fails with?

POSTED BY: Jesse Friedman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract