フィルターのクリア

MATLAB app designer not playing sounds

25 ビュー (過去 30 日間)
Adham Elkhouly
Adham Elkhouly 2021 年 4 月 26 日
コメント済み: Adham Elkhouly 2021 年 4 月 27 日
I am trying to excute the following lines with MATLAB app designer
[x, fs] = audioread('wave.wav');
app.freq = 2 * fs;
player = audioplayer(x, app.freq);
play(player);
but no sound is produced. However, when I copy the above lines along with those lines,
restoredefaultpath
rehash toolboxcache
savepath
it sounds in the command window but not in the app designer.
How can I fix this issue? - TIA

採用された回答

Subhadeep Koley
Subhadeep Koley 2021 年 4 月 27 日
I have attached one demo minimum working example.
Have a look. It might help you fix the issue.
Also, if possible provide the full path of the sound file when reading it with audioread()
  5 件のコメント
Adham Elkhouly
Adham Elkhouly 2021 年 4 月 27 日
audioread doesn't work. This is the entire function
[filename, pathname]=uigetfile({'*.wav'},'File Selector');
fullpathname = fullfile(pathname, filename);
try
[app.x,app.fs] = audioread(fullpathname); %% handling exceptions in case you decide not to attach a folder
catch
return %% function terminates in case of an exception
end
app.wavFolderAvailableLamp.Color = 'g';
app.freq = 2 * app.fs;
player = audioplayer(app.x, app.freq);
play(player);
Am I doing something I shouldn't?
Subhadeep Koley
Subhadeep Koley 2021 年 4 月 27 日
Define a public property player and store the audioplayer object inside app.player.
Then invoke play(app.player)
[filename, pathname]=uigetfile({'*.wav'},'File Selector');
fullpathname = fullfile(pathname, filename);
try
[app.x,app.fs] = audioread(fullpathname);
catch
return
end
app.wavFolderAvailableLamp.Color = 'g';
app.freq = 2 * app.fs;
app.player = audioplayer(app.x, app.freq); % Here app.player is a public property variable
play(app.player);

サインインしてコメントする。

その他の回答 (1 件)

Adham Elkhouly
Adham Elkhouly 2021 年 4 月 27 日
For anyone facing a similar issue, I used
sound(app.x,app.freq);
instead of
player = audioplayer(app.x, app.freq);
play(player);
  2 件のコメント
Subhadeep Koley
Subhadeep Koley 2021 年 4 月 27 日
@Adham Elkhouly I think, if you use sound(app.x, app.freq), then the audio clip will keep on playing even if you close the app window.
Whereas, using the below code, will stop the sound as soon as you close the app window.
app.player = audioplayer(app.x, app.freq);
play(app.player);
Adham Elkhouly
Adham Elkhouly 2021 年 4 月 27 日
Yes, the sound keeps on with
sound()
and what you said works fine after I defined
player
as a public property - thank you very much

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by