[Weired] Data not update when placed in a for/while loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Image Analyst
2018 年 11 月 24 日
Try using 'w' instead of 'r+'.
3 件のコメント
Image Analyst
2018 年 11 月 24 日
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.
参考
カテゴリ
Help Center および File Exchange で Digital Input and Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!