Effacer les filtres
Effacer les filtres

Speed up the audio clip

21 vues (au cours des 30 derniers jours)
Surendra Reddy Gaddam
Surendra Reddy Gaddam le 10 Juil 2023
Modifié(e) : Mahesh Chilla le 10 Juil 2023
I have a audio clip named "music" . The signal contained in music.au was sampled at 16 kHz, so when played, it sounded much too slow when played back at the default 8 kHz sampling rate. Can you help me write a piece of code which helps to play the audio in its original speed (when played at 8 kHz sampling rate) and save the new audio file?

Réponses (2)

Manan Jain
Manan Jain le 10 Juil 2023
Hi!
There is audioread and audioplayer function in MATLAB which you can use to perform to change the sampling rate.
Here is the code snippet that might help:
% Load the audio clip
filename = 'music.au';
[y, Fs] = audioread(filename);
% Create an audioplayer object
player = audioplayer(y, Fs);
% Set the sample rate to the original value
player.SampleRate = 16000;
% Play the audio
play(player);
There is a similar answer which you can refer for more information:
You can also refer to the audioread and audioplayer functions in the MATLAB.

Mahesh Chilla
Mahesh Chilla le 10 Juil 2023
Modifié(e) : Mahesh Chilla le 10 Juil 2023
Hi Surendra!
Here the desired sampling rate is lower than the sampling rate of the available data. In this case, we must use a process called decimation to reduce the sampling rate of the signal. Sampling rate of the given data is 16000 samples/sec. We require the sampling rate of 8000 samples/sec. To do this, we decimate the original signal by 2 by considering every alternate sample. When we play the obtained signal (signal 1) we see that it plays in the required speed.
The following code will speed up the signal and saves the audio file.
[samples,freq] = audioread('music.au');
%Here we are sampling the slow audio at 8000 samples/sec.
%So actually we are sampling the actual audio signal at 16000 samples/sec.
sig1 = samples(1:2:end);
%We are considering one in every 2 samples.
% we are decimating the discrete-time signal by a factor of 2.
sound(sig1,freq);
%Plays the decimated signal at rate 8000 samples/sec. So
%we get the music in its original speed.
audiowrite('sig1.ogg',sig1,freq);
%Saving the signal 1
To learn more about the functions used in the code, refer the MATLAB's documentation.
Hope this helps,
Thank you!!

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by