Audio recording code example

I am trying to figure out how to use the audiorecorder class in order to make some recording from within octave code, but I can’t get any success. Can anyone share some code snippet, please?

I have found the available audio devices in my system with audiodevinfo to figure out the ID of the device I want to use.

>> DEVINFO = audiodevinfo ();
>> DEVINFO.input(2)
ans =

  scalar structure containing the fields:

    Name = WEB CAM: USB Audio (hw:1,0) (ALSA)
    DriverVersion = ALSA
    ID = 6

>>

then I am making an audio recorder object and attempting to record with the following code

>> rec = audiorecorder (16000, 8, 1, 6);
>> audiosample = record (rec, 5);
error: record: function called with too many outputs
error: called from
    record
>>

Obviously I am missing something here.

Any help or a working example would be very helpful to get me started.
Thanks

See the doc string for the record method of audiorecorder objects:

octave:1> help @audiorecorder/record
'@audiorecorder/record' is a function from the file /opt/share/octave/7.1.0/m/audio/@audiorecorder/record.m

 -- record (RECORDER)
 -- record (RECORDER, LENGTH)
...

There is no output arg., hence the error message. Here is a working code:

ar = audiorecorder (16000, 8, 1); # using the default input here and thus omitting the ID arg
recordblocking (ar, 5);  # recordblocking only returns when recording is actually done
audio_data = getaudiodata (ar);

We should probably add an example like this to show how to retrieve the data.

Thank you very much. I understood the basic syntax and got it working! :partying_face:

I am building an app for recording short voice clips for my research, so once I have something functional I will post it here.