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

1 visualización (últimos 30 días)
raym
raym el 24 de Nov. de 2018
Abierta de nuevo: Walter Roberson el 20 de Dic. de 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

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by