Speed up the audio clip
23 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
Manan Jain
2023 年 7 月 10 日
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.
0 件のコメント
Mahesh Chilla
2023 年 7 月 10 日
編集済み: Mahesh Chilla
2023 年 7 月 10 日
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.
- https://www.mathworks.com/help/matlab/ref/audiowrite.html
- https://www.mathworks.com/help/matlab/ref/audioread.html
- https://www.mathworks.com/help/matlab/ref/sound.html
Hope this helps,
Thank you!!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!