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 TV Product API.

Since : 2.3

Product : TV

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 (unsigned long format, unsigned long sampleRate);
boolean disableDevice ();
boolean stop (optional unsigned long ? state);
boolean play (optional boolean ? lockState);
unsigned long getVolumeLevel();
boolean setVolumeLevel (unsigned long volume);
unsigned long getSupportedEffect ();
unsigned long getEnabledEffect ();
boolean setEffect (unsigned long 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 (unsigned long eventType);

1. Interfaces

1.1. MicrophoneManagerObject

Defines a WebApi object instance of the Tizen Samsung TV Product API.


[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: 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 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]: 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: 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);    

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

onsuccess

Callback method for microphone connection notifications.

void onevent(MicrophoneConnectEvent event);    

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 {
      readonly attribute DOMString uid;
      readonly attribute DOMString name;
      readonly attribute unsigned long eventType;
    };    

Attributes

  • readonly DOMString uid
    Microphone UID
  • readonly DOMString name
    Microphone name
  • readonly unsigned short 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_FILTER = 0x10;
    };    

Constants

  • MICROPHONE_EFFECT_NONE

    No 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 {
          readonly attribute DOMString uid;
          readonly attribute DOMString name;
          readonly attribute long deviceId;
          readonly attribute long deviceType;
    
          DOMString getUniqueId();
          unsigned long getDeviceId();
          DOMString getName();
          boolean enableDevice(unsigned long format, unsigned long sampleRate);
          boolean disableDevice();
          boolean stop(optional unsigned long ? state);
          boolean play(optional boolean ? lockState);
          unsigned long getVolumeLevel();
          boolean setVolumeLevel(unsigned long volume);
          unsigned long getSupportedEffect();
          unsigned long getEnabledEffect();
          boolean setEffect(unsigned long 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

  • readonly DOMString uid
    Device UID
  • readonly DOMString name
    Device name
  • readonly long deviceId
    Microphone Device ID
  • readonly 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: 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: 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: 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 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.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 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]: Microphone state

Return value: 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);    

Since : 2.3 Privilege level: public

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

Parameters:

  • lockState [optional]: Ignore if Tizen

Return value: 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: 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

Return value: 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: Microphone effect

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_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: Microphone effect

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_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\]: If filter is enabled, microphone tempo
* pitch \[optional\]: If filter is enabled, microphone pitch
* rate \[optional\]: If filter is enabled, microphone rate
* threshold \[optional\]: Threshold below which to ignore sounds
* noduration \[optional\]: Silence duration before playing the filtered voice

Return value: 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 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: 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: 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(unsigned long eventType);
};    

Since : 2.3

Methods

onevent

Callback method for microphone event notifications.

void onevent(MicrophoneConnectEventType eventType);    

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 {
    readonly attribute DOMString uid;
    readonly attribute DOMString name;
    readonly 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_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 {
    readonly attribute DOMString uid;
    readonly attribute DOMString name;
    readonly attribute long deviceId;
    readonly 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);
  };
};