此示例显示如何从文件读取音频并将音频写入扬声器。
要将整个音频文件读入工作区,然后将整个音频信号写入扬声器,请使用Audioread.
和Soundsc.
职能。称呼Audioread.
使用文件名来读取整个音频文件和音频的采样率。称呼Soundsc.
使用音频数据和采样率播放音频到默认扬声器。
[auidiodata,fs] = audioread(“speemdft-16-8-mono-5secs.wav”);Soundsc(Audiodata,FS)
要将音频帧框架读入工作区,然后将音频框架写入扬声器,请使用dsp.audiofilereader.
和audiodevicewriter.
职能。
创建一个dsp.audiofilereader.
对象从文件帧帧读取音频。音频文件读取器将音频文件的采样率保存到采样率
财产。
filereader = dsp.audiofilereader(“文件名”那“speemdft-16-8-mono-5secs.wav”)
filereader = dsp.audiofilereader具有属性:filename:'/mathworks/devel/bat/bdoc21a/build/matlab/toolbox/audio/samples/speechdft-16-8-mono-5secs.wav'playcount:1 samplesperframe:1024 outputdatatype:'双人'Samplate:8000 ReadRange:[1款]
创建一个audiodevicewriter.
对象将音频写入扬声器。设置样品率audiodevicewriter.
对象到音频文件的采样率。
devicewriter = audiodevicewriter(“采样率”,filereader.samplerate)
DeviceWriter = audioViceWriter具有属性:设备:'默认'Samplerge:8000显示所有属性
在循环中,从文件读取并写入设备。循环运行时,播放默认音频设备的音频。
尽管〜Isdone(Filereader)%从文件中读取一帧音频数据。audiodata = filereader();%将一个音频数据写入扬声器。devicewriter(audiodata);结尾
作为最佳实践,完成后释放文件和音频设备。
释放(Filereader)释放(DeviceWriter)
要了解如何实现其他音频I / O配置,例如从麦克风读取或写入扬声器,请参阅Matlab中的实时音频。
AcioSettings.
|audiodevicereader.
|audiodevicewriter.
|audioltayerrecorder.
|dsp.audiofilereader.
|dsp.audiofileWriter.
|GetAudioDevices.