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

답변 (1개)

jibrahim
jibrahim 2022년 9월 6일

0 개 추천

You can use dsp.AudioFileReader with PlayCount set to Inf:
afr = dsp.AudioFileReader('speech_dft.mp3','PlayCount',Inf);
adw = audioDeviceWriter('SampleRate', afr.SampleRate);
while ~isDone(afr)
audio = afr();
adw(audio);
end

댓글 수: 5

Mohamed Turkmani
Mohamed Turkmani 2022년 9월 6일
ok but the sound plays from the beggining, i kinda want the sound to seem non stop, my sound is just a simple 3 secs file, i want it to continue without seeming that its repeated
Mohamed Turkmani
Mohamed Turkmani 2022년 9월 6일
and is there a way to increase the volume of the audio in real time?
Mohamed Turkmani
Mohamed Turkmani 2022년 9월 6일
Error using audioDeviceWriter/setup
A given audio device may only be opened once.
Error in audioDeviceWriter/setupImpl
Error in generate_App/SpinnerValueChanging (line 508)
adw(audio);
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.
Mohamed Turkmani
Mohamed Turkmani 2022년 9월 7일
편집: Mohamed Turkmani 2022년 9월 7일
ok it is working the problem is when i press the button to increas the volume, it doesnt work in real time, it waits until the audio is done and repeats with the increased volume

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

질문:

2022년 9월 6일

편집:

2022년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by