[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!