How to record voice in uint8 format without telling the number of seconds in advance?

2 vues (au cours des 30 derniers jours)
Muhammad Asad
Muhammad Asad le 23 Juin 2011
Hi,
I want to record voice and then have to do some processing on the recorded voice. The output samples of the recorded voice should be in uint8 format.
I have used wavrecord function as given below. It gives me uint8 samples but I have to tell the seconds of recording in advance.
y = wavrecord(recording_duration*Fs,Fs,'uint8');
I have also found another function called audiorecorder as given below. It helps me start a recording and stop a recording and I don't need to give the recording duration in advance but the output samples are not in uint8 format.
recorder = audiorecorder(Fs,nBits,nChannels)
Now, what I want is that:
1. I don't have to give recording duration in advance. 2. I should get the samples in uint8 format.
How can I achieve this?
Thank you.

Réponses (2)

Daniel Shub
Daniel Shub le 23 Juin 2011
doc getaudiodata
Will tell you
y = getaudiodata(recorder, dataType) converts the signal data to the specified data type: 'double', 'single', 'int16', 'int8', or 'uint8'
  4 commentaires
Daniel Shub
Daniel Shub le 24 Juin 2011
@walter, I believe wavwrite automatically writes with the file with the same type as the input (if not, you can definitely specify the type to be written).
@Muhammad, you use getaudiodata with the audiorecoder object.
Matlab Help Seeker
Matlab Help Seeker le 24 Juin 2011
@Daniel: Could you please tell me how to create an audiorecorder object. Can you please provide me a code that fulfills my two requirements?
Thank you.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 24 Juin 2011
Working from Daniel's answer:
recorder = audiorecorder(Fs,8,nChannels);
Then when ready,
record(recorder);
and when done,
stop(recorder);
Then to get the data as uint8,
samples = getaudiodata(recorder,'uint8');
clear recorder
  1 commentaire
Daniel Shub
Daniel Shub le 27 Juin 2011
It is not obvious to me what the audiorecorder function does with the nbits argument. While at first glance it makes sense to only record with 8 bit resolution if you want the result as an int8, but if audiorecorder or the soundcard does anything funky, you might be better off using
recorder = audiorecorder(Fs,16,nChannels);

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by