MP3 (.mp3)
Background & Context
-
- MIME types: audio/mpeg, audio/mpeg3, audio/x-mpeg-3MP3 digital audio format, known as MPEG Audio Layer 3.
- A lossy compression scheme commonly used for consumer audio streaming, storage, transfer, and playback, which can also be used on the web.
- Binary file format.
- Follows the ISO/IEC 11172-3 and ISO/IEC 13818-3 standard.
- Supports a few sampling frequencies from 8kHz to 48kHz.
- Supports up to two audio channels.
Import & Export
- Import["file.mp3"] imports an MP3 file, returning an audio object.
- Import["file.mp3",elem] imports the specified element from an MP3 file.
- The import format can be specified with Import["file","MP3"] or Import["file",{"MP3",elem,…}].
- Export["file.mp3",expr] exports an audio or sound object to an MP3 file.
- Sound objects including notes are rasterized to sampled audio.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Data representation elements:
-
"Audio" audio signal given as an Audio object "AudioFile" audio signal given as an out-of-core Audio object "Data" raw audio samples, given as a list of real numbers, each sublist representing an individual audio channel "SampledSoundList" audio signal given as a SampledSoundList object "Sound" audio signal given as a Sound object - Import by default uses the "Audio" element for short MP3 files and the "AudioFile" element otherwise.
- Advanced Import element:
-
"AudioChannels" number of audio channels "Duration" duration of the audio given in seconds "Length" number of samples "SampleRate" number of amplitude samples per second and channel - Metadata elements:
-
"MetaInformation" interpreted metadata as quantities, dates, locations, etc. "RawMetaInformation" uninterpreted metadata including strings and numbers only - Available metadata tags include ID3v1, ID3v2 and APE.
- Multiple channels are represented as an array of audio samples.
Options
- Import and Export options:
-
"AudioChannels" Automatic number of audio channels IncludeMetaInformation All metadata types to import and export SampleRate Automatic samples per second for each channel - Export option:
-
CompressionLevel 0.5 compression level, given as a number between 0 and 1 - Possible SampleRate settings in Hz are 8000, 11025, 16000, 22050, 24000, 32000, 44100, and 48000.
- Supported IncludeMetaInformation settings are: "APE", "ID3v1", "ID3v2", "RawAPE", "RawID3v1", "RawID3v2", All and None.
Examples
open all close allBasic Examples (2)
Scope (4)
Show all import elements available in this file:
Import["ExampleData/car.mp3", "Elements"]Import["ExampleData/car.mp3", {{"AudioChannels", "SampleRate"}}]Generate an audio signal and export to MP3:
audio = AudioGenerator["Sin"]Export["sample.mp3", audio, CompressionLevel -> 1]//FileByteCountExport["sample.mp3", audio, CompressionLevel -> .5]//FileByteCountCompare to a size of a WAV file:
Export["sample.wav", audio]//FileByteCountUse ExportString and ImportString with an MP3:
Play[Sin[300t Sin[20t]], {t, 0, 1}]str = ExportString[Play[Sin[300t Sin[20t]], {t, 0, 1}], "MP3"];ImportString[str, "Audio"]Import Elements (14)
Available Elements (3)
Import["ExampleData/car.mp3", "Elements"]Get audio-related information as a list of rules:
Import["ExampleData/car.mp3", "Rules"]//ShortImport["ExampleData/car.mp3", "Options"]The "Options" element does not return all options that are present in the imported audio object:
Import["ExampleData/car.mp3"]//OptionsData Representation (5)
"Audio" (1)
Get an audio signal given as an Audio object:
Import["ExampleData/car.mp3", "Audio"]"AudioFile" (1)
Get an audio signal given as an out-of-core Audio object:
Import["ExampleData/car.mp3", "AudioFile"]"Data" (1)
"SampledSoundList" (1)
Get an audio signal given as a SampledSoundList object:
Import["ExampleData/car.mp3", "SampledSoundList"]"Sound" (1)
Get an audio signal given as an Sound object:
Import["ExampleData/car.mp3", "Sound"]Metadata (6)
"AudioChannels" (1)
"Duration" (1)
"Length" (1)
"MetaInformation" (1)
"RawMetaInformation" (1)
Import Options (6)
"AudioChannels" (2)
Export["stereo.mp3", AudioPan[AudioGenerator["Sin"], Sin[2Pi#]&]]By default, the number of audio channels is set to be Automatic:
AudioChannels[Import["stereo.mp3"]]Specify all the audio channels to be imported:
AudioChannels[Import["stereo.mp3", "AudioChannels" -> All]]Import the second channel only:
AudioChannels[Import["stereo.mp3", "AudioChannels" -> {2}]]IncludeMetaInformation (3)
By default, all available metadata is imported:
Options[Import["ExampleData/car.mp3", "Audio"], MetaInformation]Import an audio file with no metadata:
Options[Import["ExampleData/car.mp3", "Audio", IncludeMetaInformation -> None], MetaInformation]Import the audio with only specified classes of metadata:
Options[Import["ExampleData/car.mp3", "Audio", IncludeMetaInformation -> {"RawID3v2"}], MetaInformation]Export Options (5)
"AudioChannels" (1)
By default, the audio is exported using the default number of channels:
i = \!\(\*AudioBox[""]\);Export["test.mp3", i]Import[%, "AudioChannels"]Specify the number of channels of exported audio:
Export["test.mp3", i, "AudioChannels" -> {1}]Import[%, "AudioChannels"]CompressionLevel (1)
By default, the audio is exported using the 0.5 compression level:
i = \!\(\*AudioBox[""]\);ByteCount[i]Export["test.mp3", i]FileByteCount[%]Specify the encoding of exported audio:
Export["test.mp3", i, CompressionLevel -> 1]FileByteCount[%]IncludeMetaInformation (2)
By default, all existing metainformation is exported:
i = \!\(\*AudioBox[""]\);Options[i, MetaInformation]Export["test.mp3", i]Options[Import[%], MetaInformation]Specify the metadata to include:
Export["test.mp3", \!\(\*AudioBox[""]\), IncludeMetaInformation -> None]Options[Import[%], MetaInformation]SampleRate (1)
By default, the audio is exported using the default sample rate:
i = \!\(\*AudioBox[""]\);Options[i, SampleRate]Export["test.mp3", i]Import[%, "SampleRate"]Specify the sample rate of exported audio:
Export["test.mp3", i, SampleRate -> 44100]Import[%, "SampleRate"]Related Guides
History
Introduced in 2014 (10.0) | Updated in 2018 (11.3)