MATLAB Answers

Writing an audio file

1 ビュー (過去 30 日間)
Grant Wallis
Grant Wallis 2021 年 3 月 16 日
I have to read an audio file and then change the audio data, after changing the audio data i have to write the new audio. I am having trouble getting the audiowrite function to work.
clc
clear all;
fileName = 'PA6.wav';
audioread('PA6.wav'); %read the file
[y,Fs] = audioread('PA6.wav');
y1 = y / 20; %change the volume
sound(y1,Fs) %play back the new volume, which works
%these are some failed attempts
%audiowrite('PA6.wav', y1,Fs);
%audiowrite(fileName,'YourName_PA6_Problem2');
%then i need to write this new audio into "YourName_PA6_Problem2"

回答 (1 件)

Christopher McCausland
Christopher McCausland 2021 年 3 月 16 日
Hi Grant,
It's been a while from I have used .wav files for ECG recorings. I think you are on the right track with your first attempt however the filename parameter should be the new file name rather than the orignal file name. I'll include a line below. Let me know if this helps, if not please include any error messages to allow for replication.
Christopher
audiowrite('YourName_PA6_Problem2',y1,Fs);
  2 件のコメント
Christopher McCausland
Christopher McCausland 2021 年 3 月 16 日
Hi Grant,
If this was the same issue for the previous file name then I think you are either trying to overwrite files of the same name which MATLAB won't allow to protect data (you must command matlab to deleate the file first) or more likely, the directory which you are trying to generate the file into is not one that you have permission to create the file in. This is a common problem if the directory is the same location as the MATLAB install rather than one of your own directories. The soloution is to change where MATLAB is writing too.
Let me know if that helps,
Christopher

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by