playing a nonstop audio file
3 次查看(过去 30 天)
显示 更早的评论
how can i play an audio file without stopping kinda like a loop in app designer
[y,Fs] = audioread(app.files);
sound(y,Fs)
this will just play it once
0 个评论
回答(1 个)
jibrahim
2022-9-6
afr = dsp.AudioFileReader('speech_dft.mp3','PlayCount',Inf);
adw = audioDeviceWriter('SampleRate', afr.SampleRate);
while ~isDone(afr)
audio = afr();
adw(audio);
end
5 个评论
jibrahim
2022-9-6
You can control the range of the signal you want to play with the ReadRange property:
afr = dsp.AudioFileReader('speech_dft.mp3','PlayCount',Inf,'ReadRange', [start finish]);
Increasing the volume can be done by simply multiplying 'audio' by a constant of your choice.
Regarding the error, in your app, first clear your workspace, then make sure the object afr is only created once (say in setup of your app) and then somply call it in the loop. Do not recreate every time in your loop.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!