How do I save adw modified audio to a wav file

1 回表示 (過去 30 日間)
mark palmer
mark palmer 2024 年 11 月 6 日
コメント済み: mark palmer 2024 年 11 月 6 日
How do I savef this modified adw audio to a wav file without having to play it? Audiowrite here doesn't work here to save.
filename = 'speech_dft.mp3';
SpeedFactor = 4/1;
WindowLen = 1024;
OverlapLength = 896;
% Define audio source
reader = dsp.AudioFileReader(filename, ...
'SamplesPerFrame',(WindowLen - OverlapLength));
adw = audioDeviceWriter('SampleRate',reader.SampleRate);
% Define time scale modification object
ats = audioTimeScaler('Window',sqrt(hann(WindowLen,'periodic')), ...
'OverlapLength',OverlapLength, ...
'SpeedupFactor', SpeedFactor);
while ~isDone(reader) % THIS PLAYS THE MODIFIED RESULTS
x = reader();
y = ats(x); % AUDIO TIME SCALER
adw(y); % AUDIO DEVICE WRITER
end
% THIS SAVES THE MODIFIED RESULTS
audiowrite('output_file.wav', y, 44100, 'BitsPerSample', 16);
% THIS SAVES the object to a file
% save('adw.mat', 'adw');
release(reader);
release(adw);

回答 (2 件)

Walter Roberson
Walter Roberson 2024 年 11 月 6 日
Use dsp.AudioFileWriter
Note: in your current code, the y that you audiowrite() would represent only the last buffer-full of data, and not the entire transformed data.

Sameer
Sameer 2024 年 11 月 6 日
To save the modified audio to a WAV file without playing it, you can use a buffer to collect the processed audio data and then write it to a file using "audiowrite".
Here's how you can modify your code:
filename = 'speech_dft.mp3';
SpeedFactor = 4/1;
WindowLen = 1024;
OverlapLength = 896;
% Define audio source
reader = dsp.AudioFileReader(filename, ...
'SamplesPerFrame', (WindowLen - OverlapLength));
% Define time scale modification object
ats = audioTimeScaler('Window', sqrt(hann(WindowLen, 'periodic')), ...
'OverlapLength', OverlapLength, ...
'SpeedupFactor', SpeedFactor);
% Initialize a buffer to store the modified audio
buffer = [];
while ~isDone(reader)
x = reader();
y = ats(x); % AUDIO TIME SCALER
buffer = [buffer; y]; % Append the processed audio to the buffer
end
% Save the entire buffer as a WAV file
audiowrite('output_file.wav', buffer, reader.SampleRate, 'BitsPerSample', 16);
release(reader);
Hope this helps!
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 11 月 6 日
mark palmer
mark palmer 2024 年 11 月 6 日
Thanks, it works! Not sure about the buffering problem, but will look into it.

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

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by