[Weired] Data not update when placed in a for/while loop

2 Ansichten (letzte 30 Tage)
raym
raym am 24 Nov. 2018
Erneut geöffnet: Walter Roberson am 20 Dez. 2018
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

Antworten (1)

Image Analyst
Image Analyst am 24 Nov. 2018
Try using 'w' instead of 'r+'.
  3 Kommentare
Image Analyst
Image Analyst am 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.
raym
raym am 26 Nov. 2018
Hi,
the py module argument is the binary data of the file , not the audio data.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by