How to Play a audio File without delay
5 次查看(过去 30 天)
显示 更早的评论
Hi Everyone
I am working on a project in which I am creating an audio file and playing through MATLAB
The audio file is of 10 sec length.While playing first audio file I am doing the processing for next 10 sec data which take around 3 sec to create next audio file.
I just want to do that the second audio file should played without any delay(means when first audio file ends it automatically play the next file) and secondly the processing for the second audio file should start when first audio file played for 7sec.
This work is same as ECG machine where there is no delay between the audio means it read values and create audio and play.
0 个评论
采纳的回答
Walter Roberson
2019-2-9
For the greatest control you should look at https://www.mathworks.com/help/dsp/ref/dsp.audiofilereader-system-object.html and https://www.mathworks.com/help/audio/ref/audiodevicewriter-system-object.html and you should consider streaming data from the source instead of using 10 second files.
Otherwise, read the file with audioread() . Create an audioplayer() object https://www.mathworks.com/help/matlab/ref/audioplayer.html . Configure a TimerFcn callback with a TimerPeriod of 7 seconds and configure a StopFcn callback. play() the first object. When the timerFcn callback fires at 7 seconds, audioread() the second file and create a second audioplayer object for it and set up TimerFcn and TimerPeriod and StopFcn for it, and then return from the timer callback. When the first object hits the StopFcn callback, that callback should play() the second audioplayer() object.
This setup does not promise no delay: there will be the delay of firing the StopFcn callback to invoke the play() of the next file each time. If that delay turns out to be too much then you will need to switch to the audiodevicewriter system objects that I linked to before.
更多回答(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!