MATLAB * .pcm至* .wav转换 [英] MATLAB *.pcm to *.wav converting

查看:995
本文介绍了MATLAB * .pcm至* .wav转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MATLAB代码中将*.pcm音频文件转换为*.wav音频文件? 我只需要插入一个标题,但是它是如何工作的? 非常感谢你!

How can I convert *.pcm audio file to *.wav audio File in MATLAB-Code? I just need to insert a header, but how it is work? Thank you very much!

推荐答案

由于您未指定它,因此我假设您使用的是Matlab 2018b,因此,我将向您介绍有关音频阅读:

Since you didn't specify it, I'm assuming you are using Matlab 2018b, so I will point you to the most recent documentation about audioread:

如您所见, PCM不在受支持的格式列表上.

您应该尝试查看是否可以为AudioRecorder设置参数,以将音频录制为受支持列表中的其他格式:.wav,.ogg,.flac,.au,.aif,.aifc,mp3 、. mp4 ...

You should try to look if you can parameter your AudioRecorder to record your audio to another format within the ones in the supported list: .wav, .ogg, .flac, .au, .aif, .aifc, mp3, .mp4...

不使用audioread的另一种选择是像导入其他任何数据文件一样导入pcm数据,然后将其转换为16位wav.我假设采样率为44100 Hz.

An alternative option, without using audioread, would be to import pcm data like any other data file, then convert it to 16 bit wav. I assume sample rate is 44100 Hz.

fid = fopen('audioFile.pcm');                 % Open raw pcm file
audio = int16(fread(fid, Inf, 'int16'));      % Convert data into 16 bit
fclose(fid);                                  % Close pcm file
audiowrite('audioFile.wav', audio, 44100,'BitsPerSample', 16); % Write wav

这篇关于MATLAB * .pcm至* .wav转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆