Microphone API

To use Samsung Product API,

<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>

Should be loaded in index.html

This module defines the microphone functionalities provided by the Tizen Samsung Product API.

Since : 2.3

Product : TV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Summary of Interfaces and Methods

Interface Method
MicrophoneManagerObject

MicrophoneManager

DOMString getVersion();
boolean isConnected(DOMString uid);
void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);
void removeMicrophoneConnectListener(unsigned long listenerId);

MicrophoneDeviceArraySuccessCallback

void onsuccess(MicrophoneDevice[] devices);

MicrophoneConnectCallback

void onevent(MicrophoneConnectEvent event);

MicrophoneConnectEvent

MicrophoneConnectEventType

MicrophoneSampleRateValue

MicrophoneDeviceAudioFormat

MicrophoneEffectValue

MicrophoneStateValue

MicrophoneAudioinputEvent

MicrophoneDevice

DOMString getUniqueId();
unsigned long getDeviceId();
DOMString getName();
boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate);
boolean disableDevice();
boolean stop(optional MicrophoneStateValue? state);
boolean play(optional boolean? lockState);
unsigned long getVolumeLevel();
boolean setVolumeLevel(unsigned long volume);
MicrophoneEffectValue getSupportedEffect();
MicrophoneEffectValue getEnabledEffect();
boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long? tempo, optional unsigned long? pitch, optional unsigned long? rate, optional unsigned long? threshold, optional unsigned long? noduration);
unsigned long getFilterVolume();
unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);
void removeMicrophoneEventListener(unsigned long listenerId);

MicrophoneEventCallback

void onevent(MicrophoneConnectEventType eventType);

1. Interfaces

1.1 MicrophoneManagerObject

Defines a WebApi object instance of the Tizen Samsung Product API.
The webapis.microphone object enables access to Microphone API functionality.

[NoInterfaceObject] interface MicrophoneManagerObject {
  readonly attribute MicrophoneManager microphone;
};
WebApi implements MicrophoneManagerObject;

Attributes

1.2 MicrophoneManager

Provides methods for microphone functionalities.

[NoInterfaceObject] interface MicrophoneManager {
  DOMString getVersion();
  boolean isConnected(DOMString uid);
  void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
  unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);
  void removeMicrophoneConnectListener(unsigned long listenerId);
};

Methods

getVersion

Retrieves the plugin version number.

DOMString getVersion();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • DOMString : Plugin version

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

try {
  var value = webapis.microphone.getVersion();
  console.log(" version value = " + value);
} catch (error) {
  console.log(" error code = " + error.code);
}

isConnected

Checks whether a microphone is connected.

boolean isConnected(DOMString uid);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • uid : Microphone unique ID

Return Value :

  • boolean : Boolean value:
    true: Connected
    false: Disconnected

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

try {
  var flag = webapis.microphone.isConnected(uid);
  console.log(" microphone connected = " + flag);
} catch (error) {
  console.log(" error code = " + error.code);
}

getMicrophones

Retrieves a list of all connected microphones.

void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback? onerror);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • onsuccess : Callback method to invoke when a connected microphone is found
  • onerror [optional][nullable] : Callback method to invoke if an error occurs

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

function onsuccess(mics)  {
  if(mics && mics.length > 0){
    for(var i = 0; i < mics.length; i++){
      if(mics[i]!=null){
        console.log( i + " " + mics[i]);
      }
    }
  }else{
    console.log("No microphone found. Check that a microphone is connected, and try again in a few seconds.");
  }
}


try {
  webapis.microphone.getMicrophones(onsuccess);
} catch (error) {
  console.log(" error code = " + error.code);
}

addMicrophoneConnectListener

Registers a microphone connection listener.

unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • listener : MicrophoneConnectListener callback

Return Value :

  • unsigned long : MicrophoneConnectCallback ID

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

var callback =  function(deviceInfo) {
  console.log("device name is " + deviceInfo.name);
  console.log("device uid is " + deviceInfo.uid);
  console.log("device eventType is " + deviceInfo.eventType);
}
try {
  var listenerId = webapis.microphone.addMicrophoneConnectListener(callback);
  console.log("listener id = " + listenerId);
} catch (error) {
  console.log(" error code = " + error.code);
}

removeMicrophoneConnectListener

Unregisters a microphone connection listener registered by addMicrophoneConnectListener.

void removeMicrophoneConnectListener(unsigned long listenerId);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • listenerId : MicrophoneConnectCallback ID returned by addMicrophoneConnectListener

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Code Example :

try {        webapis.microphone.removeMicrophoneConnectListener(listenerId);
  console.log("listener id = " + value);
} catch (error) {
  console.log(" error code = " + error.code);
}

1.3 MicrophoneDeviceArraySuccessCallback

Defines the device list callback.

[Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneDeviceArraySuccessCallback {
  void onsuccess(MicrophoneDevice[] devices);
};

Methods

onsuccess

Callback method returning the device list.

void onsuccess(MicrophoneDevice[] devices);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • devices : MicrophoneDevice

Code Example :

function onsuccess(devices)  {
  for (var i in devices)
  {
    console.log("SystemConfig devices = " + devices[i]);
  }
}

1.4 MicrophoneConnectCallback

Defines the microphone connection listener.

[Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneConnectCallback {
  void onevent(MicrophoneConnectEvent event);
};

Methods

onevent

Callback method for microphone connection notifications.

void onevent(MicrophoneConnectEvent event);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • event : MicrophoneConnectEvent

Code Example :

var onevent = function (event){
  console.log("changing event is = " + event);
}

1.5 MicrophoneConnectEvent

Defines microphone connection event structure.

[NoInterfaceObject] interface MicrophoneConnectEvent {
  attribute DOMString uid;
  attribute DOMString name;
  attribute unsigned long eventType;
};

Attributes

  • DOMString uid
    Microphone UID
  • DOMString name
    Microphone name
  • unsigned long eventType
    Microphone event type

1.6 MicrophoneConnectEventType

Defines microphone connection event type.

[NoInterfaceObject] interface MicrophoneConnectEventType {
  const unsigned long EVENT_DEVICE_CONNECT = 11;
  const unsigned long EVENT_DEVICE_DISCONNECT = 12;
};

Constants

  • EVENT_DEVICE_CONNECT
    Device connection
  • EVENT_DEVICE_DISCONNECT
    Device disconnection

1.7 MicrophoneSampleRateValue

Defines constants for sample rates.

[NoInterfaceObject] interface MicrophoneSampleRateValue {
  const unsigned long MICROPHONE_SAMPLE_RATE_48000 = 48000;
  const unsigned long MICROPHONE_SAMPLE_RATE_44100 = 44100;
  const unsigned long MICROPHONE_SAMPLE_RATE_32000 = 32000;
  const unsigned long MICROPHONE_SAMPLE_RATE_16000 = 16000;
  const unsigned long MICROPHONE_SAMPLE_RATE_8000 = 8000;
};

Constants

  • MICROPHONE_SAMPLE_RATE_48000
    48 kHz, CD quality. Default format for audio input device.
  • MICROPHONE_SAMPLE_RATE_44100
    44.1 kHz
  • MICROPHONE_SAMPLE_RATE_32000
    32 kHz
  • MICROPHONE_SAMPLE_RATE_16000
    16 kHz
  • MICROPHONE_SAMPLE_RATE_8000
    8 kHz

1.8 MicrophoneDeviceAudioFormat

Defines constants for microphone device formats.

[NoInterfaceObject] interface MicrophoneDeviceAudioFormat {
  const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN = 0;
  const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT = 1;
};

Constants

  • MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN
    Little endian format
  • MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT
    Big endian format

1.9 MicrophoneEffectValue

Defines constants for microphone effects.

[NoInterfaceObject] interface MicrophoneEffectValue {
  const unsigned long MICROPHONE_EFFECT_NONE = 0x00;
  const unsigned long MICROPHONE_EFFECT_REVERB = 0x01;
  const unsigned long MICROPHONE_EFFECT_FILTER = 0x10;
};

Constants

  • MICROPHONE_EFFECT_NONE
    No effect
  • MICROPHONE_EFFECT_REVERB
    Reverb effect
  • MICROPHONE_EFFECT_FILTER
    Filter effect

1.10 MicrophoneStateValue

Defines constants for microphone states.

[NoInterfaceObject] interface MicrophoneStateValue {
  const unsigned long MICROPHONE_STATUS_STOP = 0x00000000;
  const unsigned long MICROPHONE_STATUS_PLAY = 0x00000001;
  const unsigned long MICROPHONE_STATUS_RECORD = 0x00000010;
  const unsigned long MICROPHONE_STATUS_FILTER = 0x00000100;
};

Constants

  • MICROPHONE_STATUS_STOP
    Stop state
  • MICROPHONE_STATUS_PLAY
    Play state
  • MICROPHONE_STATUS_RECORD
    Record state
  • MICROPHONE_STATUS_FILTER
    Filter state

1.11 MicrophoneAudioinputEvent

Defines constants for microphone input events.

[NoInterfaceObject] interface MicrophoneAudioinputEvent {
  const unsigned long MICROPHONE_AUDIOINPUT_PLAY_FAIL = 400;
  const unsigned long MICROPHONE_AUDIOINPUT_DATA = 401;
  const unsigned long MICROPHONE_AUDIOINPUT_RECORD_FAIL = 402;
  const unsigned long MICROPHONE_AUDIOINPUT_RECORD_STOP = 403;
  const unsigned long MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED = 404;
  const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_START = 405;
  const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP = 406;
  const unsigned long MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED = 407;
  const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME = 450;
};

Constants

  • MICROPHONE_AUDIOINPUT_PLAY_FAIL
    Failed to play
  • MICROPHONE_AUDIOINPUT_DATA
    Read
  • MICROPHONE_AUDIOINPUT_RECORD_FAIL
    Failed to record
  • MICROPHONE_AUDIOINPUT_RECORD_STOP
    Recording stopped due to the effect setting
  • MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED
    Voice detected
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_START
    Filtered playback started
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP
    Filtered playback stopped
  • MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED
    Silence detected
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME
    Filtered playback volume changed

1.12 MicrophoneDevice

Provides methods for microphone device functionalities.

[NoInterfaceObject] interface MicrophoneDevice {
  attribute DOMString uid;
  attribute DOMString name;
  attribute long deviceId;
  attribute long deviceType;

  DOMString getUniqueId();
  unsigned long getDeviceId();
  DOMString getName();
  boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate);
  boolean disableDevice();
  boolean stop(optional MicrophoneStateValue? state);
  boolean play(optional boolean? lockState);
  unsigned long getVolumeLevel();
  boolean setVolumeLevel(unsigned long volume);
  MicrophoneEffectValue getSupportedEffect();
  MicrophoneEffectValue getEnabledEffect();
  boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long? tempo, optional unsigned long? pitch, optional unsigned long? rate, optional unsigned long? threshold, optional unsigned long? noduration);
  unsigned long getFilterVolume();
  unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);
  void removeMicrophoneEventListener(unsigned long listenerId);
};

Attributes

  • DOMString uid
    Device UID
  • DOMString name
    Device name
  • long deviceId
    Microphone Device ID
  • long deviceType
    Microphone device type

Methods

getUniqueId

Retrieves the unique ID.

DOMString getUniqueId();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • DOMString : Device UID

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.getUniqueId();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

getDeviceId

Retrieves the device ID.

unsigned long getDeviceId();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • unsigned long : Device ID

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.getDeviceId();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

getName

Retrieves the device name.

DOMString getName();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • DOMString : Device name

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.getName();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

enableDevice

Enables the microphone device.

boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • format : Microphone format
  • sampleRate : Microphone sample rate

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type InvalidValuesError, if any input parameter contains an invalid value.

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.enableDevice(webapis.microphone.MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN,webapis.microphone.MICROPHONE_SAMPLE_RATE_48000);
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

disableDevice

Disables a microphone device.

boolean disableDevice();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.disableDevice();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

stop

Stops the microphone.

boolean stop(optional MicrophoneStateValue? state);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • state [optional][nullable] : Microphone state

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.stop(webapis.microphone.MICROPHONE_STATUS_PLAY | webapis.microphone.MICROPHONE_STATUS_RECORD);
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

play

Plays the microphone.

boolean play(optional boolean? lockState);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • lockState [optional][nullable] : Ignore if Tizen.

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.play();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

getVolumeLevel

Retrieves the volume level.

unsigned long getVolumeLevel();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • unsigned long : volume level

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.getVolumeLevel();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

setVolumeLevel

Sets the volume level.

boolean setVolumeLevel(unsigned long volume);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • volume : Volume level, the value is between 0 and 100, will return false if value is invalid.

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var volume = 50;
      var value = device.setVolumeLevel(volume);
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

getSupportedEffect

Retrieves the supported effects.

MicrophoneEffectValue getSupportedEffect();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var effects = device.getSupportedEffect();
      if(effects == webapis.microphone.MICROPHONE_EFFECT_NONE) {
        console.log("No effects supported");
      }
      else {
        if(effects & webapis.microphone.MICROPHONE_EFFECT_REVERB) {
          console.log("REVERB effect supported");
        }
        if(effects & webapis.microphone.MICROPHONE_EFFECT_FILTER) {
          console.log("FILTER effect supported");
        }
      }
    } catch (error) {
      console.log("error code = " + error.code);
    }
    
  }
});

getEnabledEffect

Retrieves the enabled effects.

MicrophoneEffectValue getEnabledEffect();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var effects = device.getEnabledEffect();
      if(effects == webapis.microphone.MICROPHONE_EFFECT_NONE) {
        console.log("No effects enabled");
      }
      else {
        if(effects & webapis.microphone.MICROPHONE_EFFECT_REVERB) {
          console.log("REVERB effect enabled");
        }
        if(effects & webapis.microphone.MICROPHONE_EFFECT_FILTER) {
          console.log("FILTER effect enabled");
        }
      }
    } catch (error) {
      console.log("error code = " + error.code);
    }
  }
});

setEffect

Sets a microphone effect.

boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long? tempo, optional unsigned long? pitch, optional unsigned long? rate, optional unsigned long? threshold, optional unsigned long? noduration);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • effect : Microphone effect
  • enable : If true, enable the effect. If false, disable the effect.
  • tempo [optional][nullable] : If filter is enabled, microphone tempo, This value is between -95.0 and 5000.0
  • pitch [optional][nullable] : If filter is enabled, microphone pitch, This value is between -60.0 and 60.0
  • rate [optional][nullable] : If filter is enabled, microphone rate, This value is between -95.0 and 5000.0
  • threshold [optional][nullable] : Threshold below which to ignore sounds
  • noduration [optional][nullable] : Silence duration before playing the filtered voice

Return Value :

  • boolean : Boolean value:
    true: Success
    false: Failure

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type InvalidValuesError, if any input parameter contains an invalid value.

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var flag = device.setEffect(webapis.microphone.MICROPHONE_EFFECT_FILTER, true, Number(tempo), Number(pitch), Number(rate), Number(threshold), Number(noduration));
    } catch (error) {
      console.log(" error code = " + error.code);
    }
  }
});

getFilterVolume

Retrieves the filter volume.

unsigned long getFilterVolume();

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Return Value :

  • unsigned long : Filter volume

Code Example :

webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var value = device.getFilterVolume();
    } catch (error) {
      console.log(" error code = " + error.code);
    }
    
  }
});

addMicrophoneEventListener

Registers a microphone event listener.

unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • listener : MicrophoneEventListener callback

Return Value :

  • unsigned long : MicrophoneEventCallback ID

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.

Code Example :

var onevent =  function(eventType) {
  console.log("eventType is " + eventType);
}
webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var listenerId = device.addMicrophoneEventListener(onevent);
      console.log("listener id = " + listenerId);
    } catch (error) {
      console.log(" error code = " + error.code);
    }
  }
});

removeMicrophoneEventListener

Unregisters a microphone event listener registered by addMicrophoneEventListener.

void removeMicrophoneEventListener(unsigned long listenerId);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • listenerId : MicrophoneEventCallback ID returned by addMicrophoneEventListener.

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.

Code Example :

var onevent =  function(eventType) {
  console.log("eventType is " + eventType);
}
webapis.microphone.getMicrophones(function(mics){
  if (mics && mics.length > 0) {
    var device = mics[0];
    try {
      var listenerId = device.addMicrophoneEventListener(onevent);
      device.removeMicrophoneEventListener(listenerId);
    } catch (error) {
      console.log(" error code = " + error.code);
    }
  }
});

1.13 MicrophoneEventCallback

Defines a listener for device events.

[Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneEventCallback {
  void onevent(MicrophoneConnectEventType eventType);
};

Methods

onevent

Callback method for microphone event notifications.

void onevent(MicrophoneConnectEventType eventType);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/microphone

Parameters :

  • eventType : unsigned long

Code Example :

var onevent = function (eventType){
  console.log(" onevent eventType is = " + eventType);
}

2. Full WebIDL

module Microphone {
  [NoInterfaceObject] interface MicrophoneManagerObject {
    readonly attribute MicrophoneManager microphone;
  };

  WebApi implements MicrophoneManagerObject;

  [NoInterfaceObject] interface MicrophoneManager {
    DOMString getVersion();
    boolean isConnected(DOMString uid);
    void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
    unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);
    void removeMicrophoneConnectListener(unsigned long listenerId);
  };

  [Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneDeviceArraySuccessCallback {
    void onsuccess(MicrophoneDevice[] devices);
  };

  [Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneConnectCallback {
    void onevent(MicrophoneConnectEvent event);
  };

  [NoInterfaceObject] interface MicrophoneConnectEvent {
    attribute DOMString uid;
    attribute DOMString name;
    attribute unsigned long eventType;
  };

  [NoInterfaceObject] interface MicrophoneConnectEventType {
    const unsigned long EVENT_DEVICE_CONNECT = 11;
    const unsigned long EVENT_DEVICE_DISCONNECT = 12;
  };

  [NoInterfaceObject] interface MicrophoneSampleRateValue {
    const unsigned long MICROPHONE_SAMPLE_RATE_48000 = 48000;
    const unsigned long MICROPHONE_SAMPLE_RATE_44100 = 44100;
    const unsigned long MICROPHONE_SAMPLE_RATE_32000 = 32000;
    const unsigned long MICROPHONE_SAMPLE_RATE_16000 = 16000;
    const unsigned long MICROPHONE_SAMPLE_RATE_8000 = 8000;
  };

  [NoInterfaceObject] interface MicrophoneDeviceAudioFormat {
    const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN = 0;
    const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT = 1;
  };

  [NoInterfaceObject] interface MicrophoneEffectValue {
    const unsigned long MICROPHONE_EFFECT_NONE = 0x00;
    const unsigned long MICROPHONE_EFFECT_REVERB = 0x01;
    const unsigned long MICROPHONE_EFFECT_FILTER = 0x10;
  };

  [NoInterfaceObject] interface MicrophoneStateValue {
    const unsigned long MICROPHONE_STATUS_STOP = 0x00000000;
    const unsigned long MICROPHONE_STATUS_PLAY = 0x00000001;
    const unsigned long MICROPHONE_STATUS_RECORD = 0x00000010;
    const unsigned long MICROPHONE_STATUS_FILTER = 0x00000100;
  };

  [NoInterfaceObject] interface MicrophoneAudioinputEvent {
    const unsigned long MICROPHONE_AUDIOINPUT_PLAY_FAIL = 400;
    const unsigned long MICROPHONE_AUDIOINPUT_DATA = 401;
    const unsigned long MICROPHONE_AUDIOINPUT_RECORD_FAIL = 402;
    const unsigned long MICROPHONE_AUDIOINPUT_RECORD_STOP = 403;
    const unsigned long MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED = 404;
    const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_START = 405;
    const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP = 406;
    const unsigned long MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED = 407;
    const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME = 450;
  };

  [NoInterfaceObject] interface MicrophoneDevice {
    attribute DOMString uid;
    attribute DOMString name;
    attribute long deviceId;
    attribute long deviceType;
  
    DOMString getUniqueId();
    unsigned long getDeviceId();
    DOMString getName();
    boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate);
    boolean disableDevice();
    boolean stop(optional MicrophoneStateValue? state);
    boolean play(optional boolean? lockState);
    unsigned long getVolumeLevel();
    boolean setVolumeLevel(unsigned long volume);
    MicrophoneEffectValue getSupportedEffect();
    MicrophoneEffectValue getEnabledEffect();
    boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long? tempo, optional unsigned long? pitch, optional unsigned long? rate, optional unsigned long? threshold, optional unsigned long? noduration);
    unsigned long getFilterVolume();
    unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);
    void removeMicrophoneEventListener(unsigned long listenerId);
  };

  [Callback = FunctionOnly, NoInterfaceObject] interface MicrophoneEventCallback {
    void onevent(MicrophoneConnectEventType eventType);
  };

};