Audio capture API allows you to capture audio from the device’s built in microphone or input source.
In order to use this API you must include the following extension in your build.yml
extensions: ["audiocapture"]
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript.
Be sure to review the Ruby API Usage guide for important information about using this API in Ruby.
Cancel audio recording. During recording if ‘cancel’ method is called, the status of recording will be ‘cancel’ in the callback returning parameter of ‘start’ method. No file is saved. In android, it will delete the file if it exists.
Synchronous Return:
Method Access:
myObject.cancel()
Rho.AudioCapture.cancel()
Rho::AudioCapture.cancel()
This method will return all of object/value pairs for the propertyNames of the API class.
Parameters
Async Callback Returning Parameters: HASH
Synchronous Return:
Map of all available properties
: this method also supports async callbacks - check the Callback tab for callback return parameters.
Method Access:
myObject.getAllProperties(CallBackHandler callback)
Rho.AudioCapture.getAllProperties(CallBackHandler callback)
Rho::AudioCapture.getAllProperties(CallBackHandler callback)
This method will return an object that represents the default instance of the API Class. For example Camera.getDefault will return a Camera object that represents the default camera.
Synchronous Return:
Default object of Module.
Method Access:
Rho.AudioCapture.getDefault()
Rho::AudioCapture.getDefault()
This method will return a set of object/value pairs for the list of the propertyName that is passed in. The propertyNames must be a valid property of the API class.
Parameters
List of properties I want to know about
Async Callback Returning Parameters: HASH
Synchronous Return:
Map of properties I want to know about
: this method also supports async callbacks - check the Callback tab for callback return parameters.
Method Access:
myObject.getProperties(ARRAY arrayofNames, CallBackHandler callback)
Rho.AudioCapture.getProperties(ARRAY arrayofNames, CallBackHandler callback)
Rho::AudioCapture.getProperties(ARRAY arrayofNames, CallBackHandler callback)
This method will return the value of the propertyName that is passed in. The propertyName must be a valid property of the API class.
Parameters
The property to return info about.
Async Callback Returning Parameters: STRING
Synchronous Return:
The property to return info about.
: this method also supports async callbacks - check the Callback tab for callback return parameters.Method Access:
myObject.getProperty(STRING propertyName, CallBackHandler callback)
Rho.AudioCapture.getProperty(STRING propertyName, CallBackHandler callback)
Rho::AudioCapture.getProperty(STRING propertyName, CallBackHandler callback)
This method allows you to set the attributes of the default object instance by passing in an object of the same class.
Parameters
An instance object that is of the same class.
Synchronous Return:
Method Access:
Rho.AudioCapture.setDefault(SELF_INSTANCE: Rho::AudioCapture defaultInstance)
Rho::AudioCapture.setDefault(SELF_INSTANCE: Rho::AudioCapture defaultInstance)
This method will set the values of a list of properties for the API class. The propertyName must be a valid property for the class and must also not be read only.
Parameters
Map of properties I want to set
Synchronous Return:
Method Access:
myObject.setProperties(HASH propertyMap)
Rho.AudioCapture.setProperties(HASH propertyMap)
Rho::AudioCapture.setProperties(HASH propertyMap)
This method will set the value of a property for the API class. The propertyName must be a valid property for the class and must also not be read only.
Parameters
The one property name that I want to set
The one property value that I want to set
Synchronous Return:
Method Access:
myObject.setProperty(STRING propertyName, STRING propertyValue)
Rho.AudioCapture.setProperty(STRING propertyName, STRING propertyValue)
Rho::AudioCapture.setProperty(STRING propertyName, STRING propertyValue)
Starts capturing audio until either ‘stop’ is received, or ‘maxDuration’ is reached. The successful recording will set ‘ok’ as the status. An unsuccessful recording will set ‘cancel’ or ‘error’ as the status in the callback returning parameters. If ‘cancel’ method is called during recording, ‘cancel’ status will be set in the callback returning parameters. In order to restart the audio capture, if the audio capturing is already in process, it is mandatory to call ‘stop’ or ‘cancel’ method before calling ‘start’ method again.
Parameters
Map of Audio Capture properties to be set. For iOS 22kHz 16bit Mono WAV file will be created. In Android, ruby callbacks are taking 20secs to fire.
Valid `properties` for this parameter are the properties avaliable to this API module. Check the property sectionAsync Callback Returning Parameters: HASH
Whether or not the audio recording was successfully captured, status will be ‘ok’ or ‘cancel’ or ‘error’.
If ‘status’ == ‘error’, then message contains error message. In all other cases, it will remain empty.
If ‘status’ == ‘ok’, then contain full file path with the file name of recorded audiofile. In all other cases, it will remain empty.
Synchronous Return:
Method Access:
myObject.start(HASH props, CallBackHandler callback)
Rho.AudioCapture.start(HASH props, CallBackHandler callback)
Rho::AudioCapture.start(HASH props, CallBackHandler callback)
Stop audio recording. During recording if ‘stop’ method is called, the status of recording will be ‘ok’ in the callback returning parameter of ‘start’ method. The file is saved in user provided location.
Synchronous Return:
Method Access:
myObject.stop()
Rho.AudioCapture.stop()
Rho::AudioCapture.stop()
Encoder to compress recorded audio. In Android devices, the supported encoder type is dependent upon device hardware and vendor.
Possible Values (STRING):
AAC low complexity. This is the default value. If wrong or no value is specified this value will be accounted.
AMR narrow-band.
AMR wide-band.
Property Access:
myObject.encoder
Rho.AudioCapture.encoder
Rho::AudioCapture.encoder
(Required) This parameter is used to specify the file name. The file name should be set at least once before calling ‘start’ method, otherwise the ‘start’ method will update the callback ‘status’ as ‘error’.
Property Access:
myObject.fileName
Rho.AudioCapture.fileName
Rho::AudioCapture.fileName
Specifies the number of milliseconds of audio to capture, defining the size of the capture buffer. This is also the maximum number of milliseconds of audio to capture when the ‘start’ method is called if not interrupted with the ‘stop’ method. The duration cannot be set to less than 1000 milliseconds, if a value of less than 1000 milliseconds is specified, the interval will be defaulted to 20000 milliseconds. The default value is 20,000 milliseconds.
Default: 20000
Property Access:
myObject.maxDuration
Rho.AudioCapture.maxDuration
Rho::AudioCapture.maxDuration
Starting, Stopping and Canceling audio capture is same across all platforms.
// Starting Audio Capture without settings. Callback is mandatory. Setting the file name at least once is also mandatory before invoking 'start' method. Rho.AudioCapture.start({},mycallback); // Starting Audio Capture with settings. Callback is mandatory. // On successful recording the hash property for fileName' in callback will return the complete file path with the filename. // In Windows, for the below settings, it will return "file://\AudioCapture.wav". Rho.AudioCapture.start({'fileName':"AudioCapture",'maxDuration':'15000'},mycallback); // Stopping Audio Capture Rho.AudioCapture.stop(); // Cancelling Audio Capture Rho.AudioCapture.cancel();
#Starting Audio Capture without settings. Callback is mandatory. Setting the file name at least once is also mandatory before invoking 'start' method. Rho::AudioCapture.start({},mycallback); #Starting Audio Capture with settings. Callback is mandatory. #On successful recording the hash property for fileName' in callback will return the complete file path with the filename. #In Windows, for the below settings, it will return "file://\AudioCapture.wav". Rho::AudioCapture.start({'fileName'=>"AudioCapture",'maxDuration'=>'15000'},mycallback); #Stopping Audio Capture Rho::AudioCapture.stop(); #Cancelling Audio Capture Rho::AudioCapture.cancel();
In WM/WinCE, one can set the fileName with or without extensions. On retrieving, the fileName property will return the complete path with the extension name.
// Setting fileName without extension Rho.AudioCapture.fileName = "\\Application\\Audio1"; // The returned value is "\Application\Audio1.wav" alert(Rho.AudioCapture.fileName); // Setting fileName with extension Rho.AudioCapture.fileName = "Audio2.wav"; // The returned value is "\Audio2.wav" alert(Rho.AudioCapture.fileName);
#Setting fileName without extension Rho::AudioCapture.fileName = "\\Application\\Audio1"; #The returned value is "\Application\Audio1.wav" Alert.show_popup(Rho::AudioCapture.fileName); #Setting fileName with extension Rho::AudioCapture.fileName = "Audio2.wav"; #The returned value is "\Audio2.wav" Alert.show_popup(Rho::AudioCapture.fileName);
In Android, one can set the fileName with or without extensions. The extension depends on encoder. The directory should be present.
// Setting fileName without extension Rho.AudioCapture.fileName = "/sdcard/Audio/sample"; // The returned value is "/sdcard/Audio/sample"; alert(Rho.AudioCapture.fileName); // Setting fileName with extension Rho.AudioCapture.fileName = "/sdcard/Audio/sample.mp4"; // The returned value is "/sdcard/Audio/sample.mp4"; alert(Rho.AudioCapture.fileName);
#Setting fileName without extension Rho::AudioCapture.fileName = "/sdcard/Audio/sample"; #The returned value is "/sdcard/Audio/sample" Alert.show_popup(Rho::AudioCapture.fileName); #Setting fileName with extension Rho::AudioCapture.fileName = "/sdcard/Audio/sample.mp4"; #The returned value is "/sdcard/Audio/sample.mp4" Alert.show_popup(Rho::AudioCapture.fileName);
In iOS, one can set the fileName without extensions. The extension depends on encoder and will be automatically added. Currently supported WAV (16kHz, 16 bit, mono) IF you do not specify fullpath filename, then file will be placed to default folder. You can receive result fullpath filename in callback.
#Setting fileName without extension Rho.AudioCapture.fileName = "sample"; // The returned value is "sample"; alert(Rho.AudioCapture.fileName); #Setting fileName with fullpath Rho.AudioCapture.fileName = Rho.Application.userFolder + 'mysound'; // The returned value is (this is example for simulator) "/Users/MOHUS/Library/Application Support/iPhone Simulator/7.1/Applications/376D660D-B6C7-4E6E-8B69-38E7C681DAC5/Documents/apps/mysound"; alert(Rho.AudioCapture.fileName);
#Setting fileName without extension Rho::AudioCapture.fileName = 'sample' // The returned value is "sample" Alert.show_popup(Rho.AudioCapture.fileName) #Setting fileName with fullpath Rho::AudioCapture.fileName = File.join(Rho::Application.userFolder,'mysound') // The returned value is (this is example for simulator) "/Users/MOHUS/Library/Application Support/iPhone Simulator/7.1/Applications/376D660D-B6C7-4E6E-8B69-38E7C681DAC5/Documents/apps/mysound"; Alert.show_popup(Rho.AudioCapture.fileName)
In Windows, to store the file in a particular location, specify the path with the file name. Mentioning the extension name with the file name is optional. Only *.wav files are supported. If the path is not specified with the file name, the captured file is stored in the root directory of the device. In Windows and Android, if the folder is not present, it should be created manually for storing the file in that location. In Android, the file extension depends on encoder value. If it is AAC, the extension should be ‘.mp4’. In all other cases, it is of ‘.3gpp’. If only filename is specified, it will be saved in the root directory of external storage.
In Windows & Android, Audio capture will not be started, if the file name is set to null. File will not be saved for invaild file name. It will return error in the callback returning parameters with the valid reason.
Audio recording will not be restarted, if the audio recording is already in process. In order to restart the audio capture, stop or cancel method need to be invoked before invoking start method.
If the page is to be refreshed, the audio recording should be canceled. In Android and iOS, the state will be persisted.
Upon page navigation, the audio recording should be canceled.In iOS, the state will be persisted.
The default values will be applied for duration if no values are provided by the user. If values are provided then it will apply the user provided values. Later if values are not provided then it will apply the last provided values for the same. The settings for duration and file name will not be applied if the audio capture is already started and in progress. In android, there might be slight omit of recording data initially.
In Windows, ‘getProperty’ or ‘getProperties’ for fileName will return the complete path along with the extension name. For example: If file name was set to ‘\Application\AudioCapture’, then ‘getProperty’ or ‘getProperties’ will return ‘\Application\AudioCapture.wav’. If file name was set to ‘AudioCapture’, then ‘getProperty’ or ‘getProperties’ will return ‘\AudioCapture.wav’. In Android, the fileName will return whatever is set with or without extension.
On Quitting of the Application, Android will save the data in the file and gracefully exit. In Android, during suspend/resume or screen timeout the audio will keep on recording.
Extensions which came from RhoElements (i.e. AudioCapture) that could possibly write files to external storage will require “write SD card” permissions as part of the extension’s AndroidManifest. You cannot remove the ability to write to the SD card as it would cause the extension to malfunction. Therefore, the capability has already been granted on build, and any capability added by you will be ignored. This being the case, the following extensions will always be able to write to the SD card by default.