d = audio_name.recordInteractive(ʃmessageʅ);
The
Audio.recordInteractive function launches an interactive audio recorder that stores a recording to an
Audio object. When the function is called, the audio recorder screen is displayed. It contains record, save, and clear buttons that control the audio recording. If the optional string argument
message is specified, the message will be displayed at the top of the recorder screen. The
Audio.recordInteractive function does not return until the user has finished recording and taps the save button. This is useful for synchronous recording, for example to have the interviewer record the response to a single question. To record the audio in the background while the user continues to interact with the survey, use the function
Audio.record.
The recorded audio is stored in the
Audio object and can be played back using
Audio.play or saved to a file using
Audio.save. If the
Audio object already contains an audio recording, the recorded audio will be appended to the existing recording. To replace the existing recording rather than adding to it, call the
Audio.clear function before calling
Audio.recordInteractive.
Recorded audio is stored in m4a format (AAC encoded in an MPEG-4 container). Files should be saved with the extension .m4a so that they will be recognized by media players.
Audio recording is only supported on Android. This function will do nothing on Windows.
The function returns the length of the recorded audio in seconds (and fractional seconds) or
default if there was an error during recording.
PROC AUDIO_QUESTION
onfocus
// Variable to store the recording
Audio recording;
// Save recording to a file that includes case id-items to differentiate it from
// audio saved in other cases
string nameOfAudioFile = maketext("%v%v%vAUDIO_QUESTION.m4a", PROVINCE, DISTRICT, EA);
// If no audio is recorded for this question then the only option is to record,
// otherwise allow user to re-record, play or clear recording before continuing
ValueSet vs;
if fileexist(nameOfAudioFile) and recording.load(nameOfAudioFile) then
vs.add("Re-record", 1);
vs.add("Play recording", 2);
vs.add("Clear recording", 3);
vs.add("Next question", 4);
else
vs.add("Record", 1);
endif;
setvalueset($, vs);
postproc
if $ = 1 then
// Record/re-record
recording.clear();
string message = "Record the respondent's answer to this question";
numeric seconds = recording.recordInteractive(message);
if seconds > 0 then
recording.save(nameOfAudioFile);
else
errmsg("No audio recorded. Please try again");
endif;
reenter;
elseif $ = 2 then
// Play back recording
recording.play();
reenter;
elseif $ = 3 then
// Clear the recording
filedelete(nameOfAudioFile);
reenter;
elseif $ = 4 then
// Continue to next question
endif;