OpenersPrimaryExamplesSection(Spacer1)Examples  (31)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

This imports a WAV file:

Import[ "ExampleData/rule30.wav" ]

Use (RefLink[Play, paclet:ref/Play]) to generate sampled sound and export it to WAV:

s=Play[(2+Cos[50 t])*Sin[2000*(1+ Round[2t,0.1])* t] , {t,0,1}]

Export it to WAV:

Export["sound.wav",s]

Export to 24-bit WAV:

Export["sound24.wav",s,"AudioEncoding"->"Integer24"]

OpenersExampleSection1(Spacer1)Scope  (3)

Show all import elements available in this file:

Import["ExampleData/rule30.wav","Elements"]

Import audio properties:

Import["ExampleData/rule30.wav",{{"AudioChannels","SampleRate"}}]

Use (RefLink[ExportString, paclet:ref/ExportString]) and (RefLink[ImportString, paclet:ref/ImportString]) with a WAV:

Play[Sin[300t Sin[20t]],{t,0,1}]

str=ExportString[Play[Sin[300t Sin[20t]],{t,0,1}],"WAV"];

ImportString[str,"Audio"]

OpenersExampleSection2(Spacer1)Import Elements  (16)

OpenersExampleSubsection0(Spacer1)Available Elements  (3)

List of available elements:

Import["ExampleData/rule30.wav","Elements"]

Get audio-related information as a list of rules:

Import["ExampleData/rule30.wav","Rules"]//Short

Import some image options:

Import["ExampleData/rule30.wav","Options"]

The "Options" element does not return all options that are present in the imported audio:

Import["ExampleData/rule30.wav"]//Options

OpenersExampleSubsection1(Spacer1)Data Representation  (5)

OpenersExampleSubsubsection0(Spacer1)"Audio"  (1)

Get an audio signal given as an (RefLink[Audio, paclet:ref/Audio]) object:

Import["ExampleData/rule30.wav","Audio"]

OpenersExampleSubsubsection1(Spacer1)"AudioFile"  (1)

Import the audio file as an out-of-core (RefLink[Audio, paclet:ref/Audio]) object:

Import["ExampleData/rule30.wav","AudioFile"]

OpenersExampleSubsubsection2(Spacer1)"Data"  (1)

Get a raw audio sample, given as a list of real numbers:

data=Import["ExampleData/rule30.wav","Data"]

Create an audio sample from imported data:

Audio[data]

OpenersExampleSubsubsection3(Spacer1)"SampledSoundList"  (1)

Get an audio signal given as a (RefLink[SampledSoundList, paclet:ref/SampledSoundList]) object:

Import["ExampleData/rule30.wav","SampledSoundList"]

OpenersExampleSubsubsection4(Spacer1)"Sound"  (1)

Get an audio signal given as a (RefLink[Sound, paclet:ref/Sound]) object:

Import["ExampleData/rule30.wav","Sound"]

OpenersExampleSubsection2(Spacer1)Metadata  (8)

OpenersExampleSubsubsection5(Spacer1)"AudioChannels"  (1)

Get the number of audio channels:

Import["ExampleData/rule30.wav","AudioChannels"]

OpenersExampleSubsubsection6(Spacer1)"AudioEncoding"  (1)

Get the audio encoding:

Import["ExampleData/rule30.wav","AudioEncoding"]

OpenersExampleSubsubsection7(Spacer1)"Duration"  (1)

Get the duration of the audio given in seconds:

Import["ExampleData/rule30.wav","Duration"]

OpenersExampleSubsubsection8(Spacer1)"Length"  (1)

Get the number of samples:

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

OpenersExampleSubsubsection9(Spacer1)"MetaInformation"  (1)

Get the audio metadata:

Import["ExampleData/rule30.wav","MetaInformation"]

OpenersExampleSubsubsection10(Spacer1)"RawMetaInformation"  (1)

Get the audio metadata in a raw form:

Import["ExampleData/rule30.wav","RawMetaInformation"]

OpenersExampleSubsubsection11(Spacer1)"SampleDepth"  (1)

Get the number of bits used to store every sample:

Import["ExampleData/rule30.wav","SampleDepth"]

OpenersExampleSubsubsection12(Spacer1)"SampleRate"  (1)

Get the number of amplitude samples per second and channel:

Import["ExampleData/rule30.wav","SampleRate"]

OpenersExampleSection4(Spacer1)Import Options  (6)

OpenersExampleSubsection3(Spacer1)"AudioChannels"  (2)

Generate a stereo AIFF file:

Export["stereo.wav", AudioPan[AudioGenerator["Sin"],Sin[2Pi#]&]]

By default, the number of audio channels is set to be (RefLink[Automatic, paclet:ref/Automatic]):

AudioChannels[Import["stereo.wav"]]

Specify all the audio channels to be imported:

AudioChannels[Import["stereo.wav","AudioChannels"->All]]

Import second channel only:

AudioChannels[Import["stereo.wav","AudioChannels"->{2}]]

OpenersExampleSubsection4(Spacer1)IncludeMetaInformation  (3)

By default, all available metadata is imported:

Options[Import["ExampleData/rule30.wav","Audio"],MetaInformation]

Import an audio sample with no metadata:

Options[Import["ExampleData/rule30.wav",IncludeMetaInformation->None],MetaInformation]

Import the audio with only specified classes of metadata:

Options[Import["ExampleData/rule30.wav","Audio",IncludeMetaInformation->{"RawID3v2"}],MetaInformation]

OpenersExampleSubsection5(Spacer1)SampleRate  (1)

By default, the sample rate is extracted from the file:

Options[Import["ExampleData/rule30.wav"], SampleRate]

Specify the sample rate of the imported sound:

Options[Import["ExampleData/rule30.wav",SampleRate->22050], SampleRate]

OpenersExampleSection5(Spacer1)Export Options  (4)

OpenersExampleSubsection6(Spacer1)"AudioChannels"  (1)

By default, the audio is exported using the default number of channels:

i= ;

Export["test.wav",i]

Import[%, "AudioChannels"]

Specify the number of channels of exported audio:

Export["test.wav",i , "AudioChannels"-> {1}]

Import[%, "AudioChannels"]

OpenersExampleSubsection7(Spacer1)"AudioEncoding"  (1)

By default, the audio is exported using the "Integer16" encoding:

i=;

Export["test.wav",i]

Import[%, "AudioEncoding"]

Specify the encoding of exported audio:

Export["test.wav",i , "AudioEncoding"-> "Integer24"]

Import[%, "AudioEncoding"]

OpenersExampleSubsection8(Spacer1)IncludeMetaInformation  (1)

By default, the audio is exported using the metadata:

i=;

Options[i, MetaInformation]

Export["test.wav",i]

Options[Import[%], MetaInformation]

Specify the metadata of exported audio:

Export["test.wav",i , IncludeMetaInformation-> None]

Options[Import[%], MetaInformation]

OpenersExampleSubsection9(Spacer1)SampleRate  (1)

By default, the audio is exported using the default sample rate:

i=;

Options[i, SampleRate]

Export["test.wav",i]

Options[Import[%], SampleRate]

Specify the sample rate of exported audio:

Export["test.wav",i , SampleRate-> 35200]

Options[Import[%], SampleRate]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {Related Formats:  (RefLink[AIFF, paclet:ref/format/AIFF])  ▪  (RefLink[AU, paclet:ref/format/AU])  ▪  (RefLink[FLAC, paclet:ref/format/FLAC])  ▪  (RefLink[SND, paclet:ref/format/SND])  ▪  (RefLink[Wave64, paclet:ref/format/Wave64])  ▪  (RefLink[MP3, paclet:ref/format/MP3])  ▪  (RefLink[M4A, paclet:ref/format/M4A])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Audio Formats, paclet:guide/AudioFormats])}, {▪(RefLinkPlain[Creating Web Pages, paclet:guide/CreatingWebPages])}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[Listing of All Formats, paclet:guide/ListingOfAllFormats])}, {▪(RefLinkPlain[Numerical Data, paclet:guide/NumericalData])}, {▪(RefLinkPlain[Signal Processing, paclet:guide/SignalProcessing])}, {▪(RefLinkPlain[Sound and Sonification, paclet:guide/SoundAndSonification])}, {▪(RefLinkPlain[Web Formats, paclet:guide/WebFormats])}})}})