top

Microphone API

To use Samsung Product API, 

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

Should be loaded in index.html

The module defines the functionalities of Microphone that are provides as the Samsung TV for Tizen Platform Product API.

Since : 1.0

Table of Contents

  1. 1. Interfaces
    1. 1.1. MicrophoneManagerObject
    2. 1.2. MicrophoneManager
    3. 1.3. MicrophoneDeviceArraySuccessCallback
    4. 1.4. MicrophoneConnectCallback
    5. 1.5. MicrophoneConnectEvent
    6. 1.6. MicrophoneConnectEventType
    7. 1.7. MicrophoneSampleRateValue
    8. 1.8. MicrophoneDeviceAudioFormat
    9. 1.9. MicrophoneEffectValue
    10. 1.10. MicrophoneStateValue
    11. 1.11. MicrophoneAudioinputEvent
    12. 1.12. MicrophoneDevice
    13. 1.13. MicrophoneEventCallback
  2. 2. Full WebIDL

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

The interface defines what is instantiated by the WebApi object of Samsung TV for Tizen Platform Product API.
There will be a webapis.microphone object that allows access to the functionality of the Microphone API

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

  WebApi implements MicrophoneManagerObject;

Since : 1.0

Attributes

1.2. MicrophoneManager

This interface provides methods to use the 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);
  };

Since : 1.0

Methods

getVersion
This method get the plugin's version number.

  DOMString getVersion();

Since : 1.0

Privilege level: public

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

Return value:

DOMString return value of plugin's version

Code example:


  try {    
      var value = webapis.microphone.getVersion();    
      console.log(" version value = " + value); 
  } catch (error) {    
      console.log(" error code = " + error.code);  
  }
isConnected
This method get whether connect the microphone

  boolean isConnected(DOMString uid);

Since : 1.0

Privilege level: public

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

Parameters:

  • uid - unique id of Microphone

Return value:

boolean return value of boolean
  • true is connected
  • false is disconnected

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid DOMString type passed for 'uid' parameter

Code example:


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

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

Since : 1.0

Privilege level: public

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

Parameters:

  • onsuccess - MicrophoneDeviceArraySuccessCallback
  • onerror [optional] - ErrorCallback

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid SuccessCallback type passed for 'onsuccess' parameter

    • with error type TypeMismatchError, if invalid ErrorCallback type passed for 'onerror' parameter

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. If you are sure to hook up a microphone, please try again a few seconds.");   
      }
  }

  try {    
      webapis.microphone.getMicrophones(onsuccess); 
  } catch (error) {    
      console.log(" error code = " + error.code);  
  }
addMicrophoneConnectListener
This method add the listener callback for the microphone change.

  unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);

Since : 1.0

Privilege level: public

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

Parameters:

  • listener - Callback of MicrohoneConnectListener

Return value:

unsigned long Id of MicrophoneConnectCallback

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid fucntion type passed for 'listener' parameter

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 value = webapis.microphone.addMicrophoneConnectListener(callback); 
      console.log("listener id = " + value); 
  } catch (error) {    
      console.log(" error code = " + error.code);  
  }
removeMicrophoneConnectListener
This method remove the listener which was added by addMicrophoneConnectListener

  void removeMicrophoneConnectListener(unsigned long listenerId);

Since : 1.0

Privilege level: public

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

Parameters:

  • listenerId - Id of MicrohoneConnectListener

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'listenerId' parameter

Code example:


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

1.3. MicrophoneDeviceArraySuccessCallback

This callback interface defines listener for get the return devices.

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

Since : 1.0

Methods

onsuccess
This callback interface defines listener for get the return devices.

  void onsuccess(MicrophoneDevice[] devices);

Since : 1.0

Parameters:

  • devices: MicrophoneDevice

1.4. MicrophoneConnectCallback

This callback interface defines listener for notification of changes in the microphonemanager

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

Since : 1.0

Methods

onsuccess
This callback interface defines listener for notification of changes in the microphonemanager

  void onevent(MicrophoneConnectEvent event);

Since : 1.0

Parameters:

  • event: MicrophoneConnectEvent

1.5. MicrophoneConnectEvent

This interface defines error of  event.

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

Since : 1.0

Attributes

  • readonly DOMString uid
    This attribute defines uid of microphone

    Since : 1.0

  • readonly DOMString name
    This attribute defines name of microphone

    Since : 1.0

  • readonly unsigned short eventType
    This attribute defines  event type of microphone

    Since : 1.0

1.6. MicrophoneConnectEventType

This interface defines constants that indicates the value of device event type.

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

 MicrophoneManager implements MicrophoneConnectEventType;

Since : 1.0

Constants

  • EVENT_DEVICE_CONNECT
    device connect

    Since : 1.0


     
  • EVENT_DEVICE_DISCONNECT
    device disconnect

    Since : 1.0


     

1.7. MicrophoneSampleRateValue

This interface defines constants that indicates the value of sample rate value.

  [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;    
    };

  MicrophoneManager implements MicrophoneSampleRateValue;

Since : 1.0

Constants

  • MICROPHONE_SAMPLE_RATE_48000
    sample rate = 48k. CD quality.Default format of Audio Input Device

    Since : 1.0


     
  • MICROPHONE_SAMPLE_RATE_44100
    44100rate

    Since : 1.0


     
  • MICROPHONE_SAMPLE_RATE_32000
    32000rate

    Since : 1.0


     
  • MICROPHONE_SAMPLE_RATE_16000
    16000rate

    Since : 1.0


     
  • MICROPHONE_SAMPLE_RATE_8000
    8000rate

    Since : 1.0


     

1.8. MicrophoneDeviceAudioFormat

This interface defines the format of microphone device.

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

  MicrophoneManager implements MicrophoneDeviceAudioFormat;

Since : 1.0

Constants

  • MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN
    little endian

    Since : 1.0


     
  • MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT
    big endian

    Since : 1.0


     

1.9. MicrophoneEffectValue

This interface defines constants that indicates the value of effect value.

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

  MicrophoneManager implements MicrophoneEffectValue;

Since : 1.0

Constants

  • MICROPHONE_EFFECT_NONE
    no effect

    Since : 1.0


     
  • MICROPHONE_EFFECT_REVERB
    reverb effect

    Since : 1.0


     
  • MICROPHONE_EFFECT_FILTER
    filter effect

    Since : 1.0


     

1.10. MicrophoneStateValue

This interface defines constants that indicates the value of state value.

  [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;
    };

  MicrophoneManager implements MicrophoneStateValue;

Since : 1.0

Constants

  • MICROPHONE_STATUS_STOP
    stop status

    Since : 1.0


     
  • MICROPHONE_STATUS_PLAY
    play status

    Since : 1.0


     
  • MICROPHONE_STATUS_RECORD
    record status

    Since : 1.0


     
  • MICROPHONE_STATUS_FILTER
    filter status

    Since : 1.0


     

1.11. MicrophoneAudioinputEvent

This interface defines constants that indicates the value of state value.

  [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;
    };

  MicrophoneManager implements MicrophoneAudioinputEvent;    

Since : 1.0

Constants

  • MICROPHONE_AUDIOINPUT_PLAY_FAIL
    Event for Play-fail

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_DATA
    Event for Read

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_RECORD_FAIL
    Event for Record-fail

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_RECORD_STOP
    Event for Record stop due to the effect setting

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED
    Event for voice detection

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_START
    Event for filter play started

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP
    Event for filter play stopped

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED
    Event for silence detection

    Since : 1.0


     
  • MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME
    Event for filter play volume

    Since : 1.0


     

1.12. MicrophoneDevice

This interface provides methods to use the 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);
  };

Since : 1.0

Attributes

  • readonly DOMString uid
    This attribute defines uid of device

    Since : 1.0

  • readonly DOMString name
    This attribute defines name of device

    Since : 1.0

  • readonly long deviceId
    This attribute defines  device id of microphone

    Since : 1.0

  • readonly long deviceType
    This attribute defines device type of microphone

    Since : 1.0

Methods

getUniqueId
This method use to get uniqueId

  DOMString getUniqueId();

Since : 1.0

Privilege level: public

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

Return value:

DOMString uid of device

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var value = device.getUniqueId();
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
getDeviceId
This method use to get deviceId

  unsigned long getDeviceId();

Since : 1.0

Privilege level: public

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

Return value:

unsigned long id of device

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var value = device.getDeviceId();
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
getName
This method use to get device Name

  DOMString getName();

Since : 1.0

Privilege level: public

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

Return value:

DOMString name of device

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var value = device.getName();
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
enableDevice
This method use to enable device

  boolean enableDevice(unsigned long format, unsigned long sampleRate);

Since : 1.0

Privilege level: public

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

Parameters:

  • format - format of mirophone
  • sampleRate - sampleRate of microphone

Return value:

boolean return value of boolean
  • true is success
  • false is failure

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'format' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'sampleRate' parameter

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[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
This method use to disable device

  boolean disableDevice();

Since : 1.0

Privilege level: public

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

Return value:

boolean return value of boolean
  • true is success
  • false is failure

Code example:


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

  boolean stop(optional unsigned long ? state);

Since : 1.0

Privilege level: public

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

Parameters:

  • state [optional] - state of microphone

Return value:

boolean return value of boolean
  • true is success
  • false is failure

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'state' parameter

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[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
This method use to play

  boolean play(optional boolean ? lockState);

Since : 1.0

Privilege level: public

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

Parameters:

  • lockState [optional] - ignore it

Return value:

boolean return value of boolean
  • true is success
  • false is failure

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid boolean type passed for 'lockState' parameter

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var value = device.play();
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
getVolumeLevel
This method use to get volume level

  unsigned long getVolumeLevel();

Since : 1.0

Privilege level: public

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

Return value:

unsigned long volume level

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var value = device.getVolumeLevel();
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
setVolumeLevel
This method use to set volume level

  boolean setVolumeLevel(unsigned long volume);

Since : 1.0

Privilege level: public

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

Parameters:

  • volume - volume level

Return value:

boolean return val of boolean
  • true is success
  • false is failure

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'volume' parameter

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
           try {    
                  var volume = 50;
                  var value = device.setVolumeLevel(volume);
            } catch (error) {    
           console.log(" error code = " + error.code);  
           }
      }
  });
getSupportedEffect
This method use to get supported effect

  unsigned long getSupportedEffect();

Since : 1.0

Privilege level: public

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

Return value:

unsigned long effect of microphone
  • const unsigned long MICROPHONE_EFFECT_NONE = 0x00;
  • const unsigned long MICROPHONE_EFFECT_REVERB = 0x01;
  • const unsigned long MICROPHONE_EFFECT_FILTER = 0x10;

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[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
This method use to get enabled effect

  unsigned long getEnabledEffect();

Since : 1.0

Privilege level: public

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

Return value:

unsigned long effect of microphone
  • const unsigned long MICROPHONE_EFFECT_NONE = 0x00;
  • const unsigned long MICROPHONE_EFFECT_REVERB = 0x01;
  • const unsigned long MICROPHONE_EFFECT_FILTER = 0x10;

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[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 enableed");
              }
              if(effects & webapis.microphone.MICROPHONE_EFFECT_FILTER) {
                  console.log("FILTER effect enableed");
              }
          } catch (error) {
              console.log("error code = " + error.code);
          }
      }
  });
setEffect
This method use to set effect

  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);

Since : 1.0

Privilege level: public

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

Parameters:

  • effect - effect of microphone
  • enable - if true, enable the effect. otherwise, disable the effect
  • tempo [optional] - tempo of icrophone, only for filter enabled case.
  • pitch [optional] - pitch of microphone, only for filter enabled case.
  • rate [optional] - rate of microphone, only for filter enabled case.
  • threshold [optional] - if less than this threshold, ignore this sound.
  • noduration [optional] - no sound duration, if the time of user stop speaking exceed the duration, it will play the filted voice.

Return value:

boolean return value of boolean
  • true is success
  • false is failure

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'effect' parameter

    • with error type TypeMismatchError, if invalid boolean type passed for 'enable' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'tempo' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'pitch' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'rate' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'threshold' parameter

    • with error type TypeMismatchError, if invalid long type passed for 'noduration' parameter

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[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
This method use to get filter volume

  unsigned long getFilterVolume();

Since : 1.0

Privilege level: public

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

Return value:

unsigned long return value of filter volume

Code example:


  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
          try {    
              var value = device.getFilterVolume();
          } catch (error) {    
              console.log(" error code = " + error.code);  
          }
      }
  });
addMicrophoneEventListener
This method add the listener callback for the microphone event change.

  unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);

Since : 1.0

Privilege level: public

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

Parameters:

  • listener - Callback of MicrophoneEventListener

Return value:

unsigned long Id of MicrophoneEventCallback

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid function type passed for 'listener' parameter

Code example:


  var onevent =  function(eventType) {    
      console.log("eventType is " + eventType); 
  }
  webapis.microphone.getMicrophones(function(misc){
      if (mics && mics.length > 0) {
          var device = miscs[0];
          try {    
              var listenerId = device.addMicrophoneEventListener(onevent); 
              console.log("listener id = " + listenerId); 
          } catch (error) {    
              console.log(" error code = " + error.code);  
          }
      }
  });
removeMicrophoneEventListener
This method remove the listener which was added by addMicrophoneEventListener

  void removeMicrophoneEventListener(unsigned long listenerId);

Since : 1.0

Privilege level: public

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

Parameters:

  • listenerId - Id of MicrophoneEventCallback

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if invalid long type passed for 'listenerId' parameter

Code example:


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

1.13. MicrophoneEventCallback

This callback interface defines listener for get the event of devices.

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

Since : 1.0

Methods

onevent
This callback interface defines listener for notification of changes in the microphoneevent

  void onevent(unsigned long eventType);

Since : 1.0

Parameters:

  • eventType: unsigned long

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 short eventType;
    };

    [NoInterfaceObject]interface MicrophoneConnectEventType {
        const unsigned short EVENT_DEVICE_CONNECT = 11;
        const unsigned short EVENT_DEVICE_DISCONNECT = 12;
    };
    MicrophoneManager implements MicrophoneConnectEventType;

    [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;    
    };
    MicrophoneManager implements MicrophoneSampleRateValue;

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

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

    [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;
    };
    MicrophoneManager implements MicrophoneStateValue;

    [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;
    };
    MicrophoneManager implements MicrophoneAudioinputEvent;    

    [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);
    };

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