The AudioRecorder object can be used to listen for sound and record it to a file.
rec = app.CreateAudioRecorder() → app object: AudioRecorder
After creation you have to define the recording file with the SetFile Method:
rec.SetFile( "/sdcard/demofile.wav" );
After that you can Start the recording: rec.Start();
The recorded audio will then be written to the specified file.
Finally you can also Stop the recording: rec.Stop();
Example - Example
function OnStart()
{
rec = app.CreateAudioRecorder();
rec.SetFile( "/sdcard/demofile.wav" );
rec.Start();
app.ShowPopup( "Please speak" );
setTimeout( StopRecording, 5000 );
}
function StopRecording()
{
rec.Stop();
app.ShowPopup( "Finished recording. Now playing" );
ply = app.CreateMediaPlayer();
ply.SetFile( file );
ply.SetOnReady( ply.Play );
}
Methods
The following methods are available on the AudioRecorder object:
GetType() →
string: “AudioRecorder”
number: integer
number: integer: 8000 or 11025 or 22050 or 44100 or 48000
string: path to file or folder ( “/absolute/...” or “relative/...” )
rec.GetData
Returns a list of frequency values. The amount is dependent on the set frequency.
rec.GetPeak
Returns the PMPO value (Peak music power output).
rec.GetRMS
Returns the RMS value (Root Mean Square)
rec.GetType
Returns the control class name.
rec.Pause
Pauses the recording temporally.
rec.SetFile
Define the file where the recorder should record to.
rec.SetFrequency
Set the Recording frequency to one of the possible values.
rec.Start
Start recording to the specified file.
rec.Stop
Stop the audio recording.