Here's Matlab Audioread I try:
filename = "test.wav";
[y,fs] = audioread(filename);
%Play the audio.
sound(y,fs);
info = audioinfo("test.wav")
And here is the info from that audio:
CompressionMethod: 'Uncompressed'
NumChannels: 2
SampleRate: 44100
TotalSamples: 487424
Duration: 11.0527
Title: []
Comment: []
Artist: []
BitsPerSample: 16
My question is, How do I play the audio at a sample rate of 8000?

 Respuesta aceptada

Star Strider
Star Strider el 14 de Nov. de 2022

0 votos

I would do something like this, using the Signal Processing Toolbox resample funciton —
filename = "test.wav";
[y,fs] = audioread(filename);
L = size(y,1);
t = linspace(0, L-1, L)/fs; % Time Vector
fs_new = 8000;
[yr,tr] = resample(y, t(:), fs_new); % Resample To New Sampling Frequency
There are several compatible resample syntaxes that will do what you want. I prefer the one I posted here.
Alternatively, the interp1 funciton can be uesd, however resample includes an anti-aliasing filter, so it is best for any sort of signal processing.
.

6 comentarios

Ibnu Darajat
Ibnu Darajat el 14 de Nov. de 2022
when I want to play the audio with this code:
sound(yr,tr)
there is error I got:
Error using sound (line 76)
Operands to the || and && operators must be convertible to logical scalar values.
Error in openaudio>pushbutton1_Callback (line 89)
sound(yr,tr)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in openaudio (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)openaudio('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
Star Strider
Star Strider el 14 de Nov. de 2022
Try this instead:
sound(yr,fs_new)
That should work correctly.
Use ‘tr’ to plot it:
figure
plot(tr, yr)
grid
xlabel('Time (s)')
ylabel('Amplitude')
.
Ibnu Darajat
Ibnu Darajat el 14 de Nov. de 2022
there is 2 color when I plot the signal? What's the different?
Star Strider
Star Strider el 14 de Nov. de 2022
It is not necessary to plot it. I simply wanted to show how to use the ‘tr’ vector correctly. (There should be some differences between the original and resampled vectors because of the interpolation being used.)
To listen to the resampled version, do this —
sound(yr,fs_new)
or use the audioplayer and play functions. (The sound function is easier.)
.
Ibnu Darajat
Ibnu Darajat el 14 de Nov. de 2022
thanks
Star Strider
Star Strider el 14 de Nov. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Measurements and Spatial Audio en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 14 de Nov. de 2022

Comentada:

el 14 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by