Hello, I have to read a Audio File (.wav) into a vector.
I know how to plot it:
info = audioinfo('sound.wav');
[y, Fs] = audioread('sound.wav');
t = 0:1/Fs:info.Duration;
t = t(1:end-1);
plot(t,y);
xlabel('Time');
ylabel('Audio Signal');
But this Sript does not read the Audio into a Vector.
I also tried to read every single Sample, but this is to complex and I get error after error. Is there a simple way to do this?

댓글 수: 2

Cris LaPierre
Cris LaPierre 2020년 7월 15일
It would be helpful if you could share the error messages as well as your sound.wav file.
dieter alfred
dieter alfred 2020년 7월 15일
Sorry, I cannot upload the file, because the forum doesnt accept the .wav filetype. And I have already deleted the code with the error messages. But next time I will upload everything.

댓글을 달려면 로그인하십시오.

 채택된 답변

Sugar Daddy
Sugar Daddy 2020년 7월 15일
편집: Sugar Daddy 2020년 7월 15일

1 개 추천

[y, Fs] = audioread('sound.wav');
sound_duration = length(y)/Fs;
t = 0:1/Fs:sound_duration;
t = t(1:end-1);
%%
soundsc(y,Fs);
%%
plot(t,y);
xlabel('Time');
ylabel('Audio Signal');

댓글 수: 3

dieter alfred
dieter alfred 2020년 7월 15일
Thank you very much for your answer.
bob bob
bob bob 2024년 12월 21일
Any idea on how to reduce the # of points? I am trying to get the SVG to use in a graphic design setting so I will be altering the shape more in Illustrator but I would like to reduce the point by quite a bit
Walter Roberson
Walter Roberson 2025년 12월 29일
I suggest using resample
If you do not have the Signal Processing Toolbox, then you could instead try using imresize

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2025년 12월 29일

0 개 추천

An audio file would not be read into a vector in the case where the audio file had multiple channels.
%approach #1
[y, Fs] = audioread('sound.wav');
y = y(:,1); %take the left channel only
t = (0:length(y)-1)/Fs;
%approach #2
[y, Fs] = audioread('sound.wav');
y = mean(y,2); %average all channels
t = (0:length(y)-1)/Fs;
Note that the code
t = 0:1/Fs:info.Duration;
t = t(1:end-1);
could result in a time vector that was one element too long or too short because of round-off errors in accumulating the 1/Fs in the colon operation.

카테고리

제품

질문:

2020년 7월 15일

댓글:

2025년 12월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by