如何使用Matlab以特定间隔播放音频文件?

0xF*_*FFF 3 matlab audio-player matlab-figure

像平常一样:

player=audioplayer(snd1,FS1);
play(player);

%let as suppose that sound duration is 10 seconds
% and I wanted to play the sound from second 5 or 7... 
%   .. depending on the input of user(and using audioplayer libraries)
Run Code Online (Sandbox Code Playgroud)

Jea*_*aul 6

您可以指定startstop使用播放(playerObj,[start,stop])功能:

load handel;
playerObj = audioplayer(y,Fs);
start = 1;
stop = playerObj.SampleRate * 3;

play(playerObj,[start,stop]);
Run Code Online (Sandbox Code Playgroud)

或者,您可以计算总数据的子样本并将其提供给audioplayer:

load handel;
% y = data
% Fs = frequency = number of datapoints per second
% so calculate begin and end time using the sampling frequency:
totalTime = size(y,1)/Fs;  % all data divided by sampling frequency
beginTime = round(5*Fs);   % 5 seconds
endTime = round(7*Fs);     % 7 seconds

% playing full audio:
% player = audioplayer(y, Fs);
% play(player);

% playing only part of audio:
player = audioplayer(y(beginTime:endTime,:), Fs);
play(player);
Run Code Online (Sandbox Code Playgroud)