radio button to play song
3 次查看(过去 30 天)
显示 更早的评论
im trying to come up with the code for selecting a radio button and making it play a song... i have asked my instructor with no luck, my book says nothing... if someone can point me in a direction... that would be great. !
0 个评论
采纳的回答
Benjamin Avants
2014-3-14
I have had success with the following.
In the opening function:
% Audio Players
[y,Fs,NBITS]=wavread('punch.wav');
handles.Punch = audioplayer(y,Fs,NBITS);
[y,Fs,NBITS]=wavread('electric buzz.wav');
handles.Buzz = audioplayer(y,Fs,NBITS);
[y,Fs,NBITS]=wavread('I_can_see.wav');
handles.See = audioplayer(y,Fs,NBITS);
and in the callback:
play(handles.Buzz); % or whichever sound is appropriate for the selected button/control
This preloads the audio and player object when the GUI is opened and then it can be controlled from the callbacks in the GUI without a delay.
1 个评论
Benjamin Avants
2014-3-14
If you're not using a GUI created in GUIDE, initialize the audio players in whatever function creates your GUI window. Save them as UserData in the button group or button that will use them and then you'll have access to them in the callback by using
get(hObject,'UserData')
更多回答(1 个)
roget dubose
2014-3-14
2 个评论
Benjamin Avants
2014-3-15
You can read pretty much any audio file with
[y,Fs] = audioread('filename') ;
instead and the audio player will be initialized as
audioplayer(y,Fs);
If the audio data is in floating point format (shouldn't be with mp3) then you'll need to specify NBITS, the bits per sample.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!