Error in enhanceSpeech for audio enhancement

I am using enhanceSpeech (https://www.mathworks.com/help/audio/ref/enhancespeech.html) to proceed an audio file and encountered the following problem.
Index in position 1 exceeds array bounds. Index must not exceed 256384.
Error in audio.ai.metricgan.postprocess (line 39)
audioOut = audioOut(1:size(audioIn,1),1);
Error in enhanceSpeech (line 58)
audioOut = audio.ai.metricgan.postprocess(audioIn,fs,reconstructionPhase,netOutput,win);
I looked at the signal. It has certain noise in the very beginning.
I think this is the major reason because if I run:
enhancedSpeech = enhanceSpeech(noisySpeech(3000:end),fs);
there is no error. But if I run:
enhancedSpeech = enhanceSpeech(noisySpeech(2900:end),fs);
there will errors as shown above.

2 Comments

I checked the source code according to the error message. The length of audioOut in my example is shorter than the length of audioIn.
Therefore, I made a remedial action to replace the line 39
audioOut = audioOut(1:size(audioIn,1),1);
with
if length(audioOut) >= length(audioIn)
audioOut = audioOut(1:size(audioIn,1),1);
else
audioOut = [audioOut;audioIn(length(audioOut)+1:end)];
end
Then I can run the function successfully.
Hope MathWorks can fix this bug soonly.
Thank you for bringing this to our attention. This is indeed a bug and will be fixed shortly.
The underlying model operates on an STFT of 16 kHz audio data. This means we are resampling under-the-hood and padding to multiples of the hop length of the STFT. I believe the issue you encountered is due to a bug in the calculation of the padding happening before resampling. Another option to get around this issue without touching the source code is to resample to 16 kHz outside of the function.
[noisySpeech,fs] = audioread('yourfile');
a = audioresample(noisySpeech,InputRate=fs,OutputRate=16e3)
b = enhanceSpeech(a,16e3)
c = audioresample(b,InputRate=16e3,OutputRate=fs)

Sign in to comment.

Answers (0)

Products

Release

R2024a

Asked:

on 27 Aug 2024

Community Treasure Hunt

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

Start Hunting!