How to keep refreshing string of button and audio played in MatLab
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I wanted to know how I can keep refreshing the text strings of two buttons as well as the audio being played in MatLab. So the program below generates the a random sequence, of word pairs and the correct word from the word pair.
%The word pairs
wordsA={'veal','bean','gin','dint','zoo','dune','voal','goat','zed','dense','vast','gaff','vault','daunt','jock','bond','meat','need','mitt','nip','moot','news','moan','note','mend','neck','mad','nab','moss','gnaw','mom','knock','vee','sheet','vill','thick','foo','shoes','those','though','then','fence','than','shad','thong','shaw','von','vox','zee','cheep','jilt','sing','juice','chew','joe','sole','jest','chair','jab','sank','jaws','saw','jot','chop','weed','peak','bid','fin','moon','pool','bowl','fore','met','pent','bank','fad','fought','bong','wad','pot','yield','key','hit','gill','coop','you','ghost','show','keg','yen','gat','shag','yawl','caught','hop','got'};
wordsB={'feel','peen','chin','tint','sue','tune','foal','coat','said','tense','fast','caff','fault','taunt','chock','pond','beat','deed','bit','dip','boot','dues','bone','dote','bend','deck','bad','dab','boss','daw','bomb','dock','bee','cheat','bill','tick','pooh','choose','doze','dough','den','pence','dan','chad','tong','coo','bon','box','thee','keep','gilt','thing','goose','coo','go','thole','guest','care','gab','thank','gauze','thaw','got','cop','reed','teak','did','thin','noon','tool','dole','thor','net','tent','dank','thad','thought','dong','rod','tot','wield','tea','fit','dill','poop','rue','boast','so','peg','wren','bat','sag','wall','taught','fop','dot'};
%access elements like this
wordsA{1}
Num=length(wordsA);
%Create a non-repating sequence of Num indexes
seq=randperm(Num);
%Create a sequence of Num 1s and 0s (which fix whether you replay word A or word B
rep=fix(rand(1,Num)*2);
%Now concatenate to make Num*2 word pairs and replay sequences
actual_seq=[seq,seq];
actual_rep=[rep,not(rep)];
%Loop through the Num items
for n=1:Num*2
indx=actual_seq(n);
AorB=actual_rep(n);
if (AorB==1)
sprintf('Reading word ''%s'' from pair [%s,%s]\n',wordsA{indx},wordsA{indx},wordsB{indx})
%load the file like this
%[s,fs]=audioread([wordsA{5} '.wav']);
else
sprintf('Reading word ''%s'' from pair [%s,%s]\n',wordsB{indx},wordsA{indx},wordsB{indx})
%load the file like this
%[s,fs]=audioread([wordsB{5} '.wav']);
end
%replay the audio file like this
%soundsc(s,fs);
end
Here is a snippet of what the output looks like. It will output 96 word pairs normally.
Reading word 'caff' from pair [gaff,caff]
Now what i want to do is assign the word pair gaff and caff to be set as text strings of a push button and I want the reading word 'caff' in this instance for which I have an audio to be played.
I want to keep doing this 96 times for all the word pairs, so each time the user selects the button from a word pair it moves on to the next pair and plays the reading word.
댓글 수: 1
Geoff Hayes
2016년 7월 5일
Yasir - where are the two buttons that you wish to update with the words? How does the above code fit with that in your GUI? Was your GUI created with GUIDE or programmatically?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!