Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting sounds as WAV files

I never worked too much with sounds in Mma.

I have

t = Sound[List["Violin",SoundNote[-6]]]

How could I Export t as a .WAV file?

When I try the obvious

Export["c:\\test.wav",t]

I get

enter image description here

In this old thread Szabolcs said that it can't be done. Perhaps things have improved since 2007!

like image 280
Dr. belisarius Avatar asked Sep 29 '11 04:09

Dr. belisarius


1 Answers

I think that it still can't be done. Mathematica supports creating and modifying MIDI objects, but leaves the sound generation from the midi to the underlying operating system. For now, you'll have to export to midi then use the midi interface on your system or an online service to convert to a sampled sound format.

For example (from the documentation)

t = Sound[SoundNote[DeleteCases[3 Range[31] Reverse[#], 0] - 48, .1] & /@ 
   Transpose[CellularAutomaton[90, {{1}, 0}, 30]]]
Export["test.mid", t]

Uploaded to http://free-midi-converter.com/Midi/Create gives the link.

It can also be converted with TiMidity which is available on all major operating systems with the command (assuming you've run the above)

Run["timidity test.mid -Ow -o test.wav"]

which can be imported back into Mathematica using Import["test.wav"].

This conversion can be automated if need be...


Apparently VLC can also convert midi to wav, which might be an easier option for some propriety operating systems! See also the options given here.

like image 110
Simon Avatar answered Sep 29 '22 04:09

Simon