Can "audioread" read mp3 file correctly?
3 次查看(过去 30 天)
显示 更早的评论
I use the code
[y,Fs]=audioread('**.mp3','double');
to read a mp3 file. and size(y) is [12762480 2] (two channels).
But foobar tells me that the sample is 12 759 666. They are different, which one is correct?
1 个评论
David Mellinger
2025-7-14
编辑:David Mellinger
2025-7-14
Not sure what 'foobar' you're referring to there, but in general audioread does NOT read mp3 files correctly. As mentioned by MathWorks, this is due to limitations in the underlying operating system (Windows or Linux) that means audioread sometimes returns fewer samples than requested. Another limitation is that if you specify what sample indexes you want (via the 'samples' argument to audioread), and the sample range does not start at 1, you'll get different sample values at a given index than if the range starts at sample 1. Probably because of the way mp3 files are encoded, audioread doesn't (or can't) get the correct sample offset into the mp3 file.
I sometimes work with large (multi-gigabyte) sound files, so I have to process them in chunks. Being unable to read data starting at the correct sample offset into an mp3 file is a real headache. It turns out to be easiest just to convert mp3's to .wav files and work from there, even though the .wav files are much larger.
To answer your question, I'd use size(y) because that's what samples you can get.
回答(1 个)
Kaashyap Pappu
2020-1-21
The variation could be due to the limitation highlighted here. There are instances when the software and hardware specifications also play a role in how many samples would be output when ‘audioread’ is called. This can be mainly attributed to MP3 compression not having a fixed bits per sample ratio. However, this does not mean that the samples are incorrect. The sound function can be used to verify if the original audio is still intact.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!