[Weired] Data not update when placed in a for/while loop
1 view (last 30 days)
Show older comments
I used matlab and python interface to convert my voice to text:
When run the code again and again, it successfully record my speech and show the correct text.
However, when I just surround the code with while loop or for loop, weired thing happend: No matter what I speak from 2nd loop, everytime it shows the text the same as the first run of the loop.
I have checked that voice data : data1 was fresh everyround by showing the mean value and it indeed differs each cycle. So its not the problem of data1.
%while 1
% record voice to a file
recorder = audiorecorder(Fs,Bits,nChannel);
recordblocking(recorder,4);
x = getaudiodata(recorder);
audiowrite(filename,x,Fs);
% read file
fid = fopen(filename,'r+');
data1 = uint8(fread(fid))';
disp(mean(data1(:)));
fclose(fid);
%end
0 Comments
Answers (1)
Image Analyst
on 24 Nov 2018
Try using 'w' instead of 'r+'.
3 Comments
Image Analyst
on 24 Nov 2018
Sorry - my answer was not right - I didn't look at your code closely enough. I don't think your mean computation is right. I think you should use audioread() to read your data instead of fread() since not all data in the file is sound amplitude data, though I'm not familiar with the flac format.
See Also
Categories
Find more on Digital Input and Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!