How to read Audio File into Vector?
Mostrar comentarios más antiguos
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 comentarios
Cris LaPierre
el 15 de Jul. de 2020
It would be helpful if you could share the error messages as well as your sound.wav file.
dieter alfred
el 15 de Jul. de 2020
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 29 de Dic. de 2025
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.
Categorías
Más información sobre Audio and Video Data en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!