Convert audio file to a byte array in matlab

前端 未结 1 1149
傲寒
傲寒 2021-01-29 12:50

I want to convert an audio file (.wav/.mp3) to a byte array like in C#. Here\'s my code,

string imageName = Guid.NewGuid().ToString() + \".mp3\";
byte[] file =          


        
相关标签:
1条回答
  • 2021-01-29 13:23

    If you want to read the raw audio data, use audioread. You call it like so:

    [y,Fs] = audioread(filename);
    

    filename would be the file name of your file (.mp3/.wav) and what is returned is a matrix of values stored in y and the sampling frequency of the file in Fs. y would be a matrix such that the number of rows tells you the number of samples that your audio consists of, and the number of columns tells you how many channels the audio has. For example, mono audio would be a single column vector while stereo audio would be a two-column matrix: the first column being the left channel and the second column being the right channel.

    For more information, check out the MathWorks doc I linked you to above.

    0 讨论(0)
提交回复
热议问题