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
var file = "/sdcard/demofile.wav";
function OnStart()
{
rec = app.CreateAudioRecorder();
rec.SetFile( file );
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 );
}
from native import app
file = "/sdcard/demofile.wav"
def OnStart():
global rec
rec = app.CreateAudioRecorder()
rec.SetFile( file )
rec.Start()
app.ShowPopup( "Please speak" )
setTimeout( StopRecording, 5000 )
def StopRecording():
rec.Stop()
app.ShowPopup( "Finished recording. Now playing" )
ply = app.CreateMediaPlayer()
ply.SetFile( file )
ply.SetOnReady( ply.Play )
Properties
The following properties are available on the AudioRecorder object:
Methods
The following methods are available on the AudioRecorder object:
GetType() →
String: “AudioRecorder”
all types
String
Number: integer
Number: integer: 8000 or 11025 or 22050 or 44100 or 48000
String: path to file ( “/absolute/...” or “relative/...” )
String: “Default” or “Camcorder” or “Mic” or “Unprocessed” or “Voicecommunication” or “Voiceperformance” or “Voicerecognition”
Object: {
command:
args }
rec.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
rec.data
An object for saving individual extra properties.
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.SetSource
Define the file where the recorder should record to.
rec.Start
Start recording to the specified file.
rec.Stop
Stop the audio recording.