radio button to play song

조회 수: 1 (최근 30일)
roget dubose
roget dubose 2014년 3월 14일
댓글: roget dubose 2014년 3월 15일
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. !

채택된 답변

Benjamin Avants
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
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
roget dubose 2014년 3월 14일
and what if its an mp3 not wav file?
  댓글 수: 2
Benjamin Avants
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.
roget dubose
roget dubose 2014년 3월 15일

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

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by