# SoftBank Robotics documentation What's new in NAOqi 2.8?

# ALSoundDetection API

NAOqi Audio - Overview | API

Namespace : AL

    #include <alproxies/alsounddetectionproxy.h>

## Method list

As any module, this module inherits methods from ALModule API. It also has the following specific methods:

class `ALSoundDetectionProxy`

- `ALSoundDetection::setParameter`
- `ALSoundDetection::subscribe`
- `ALSoundDetection::unsubscribe`

## Event list

- `SoundDetected()`

## Methods

void `ALSoundDetection::``setParameter`(const std::string& parameter, const float& value)

  Use it to set the sensitivity of the detection.

  Parameters: | parameter – Name of the parameter value – Value of the parameter

  Available parameters:

  - “Sensibility”: DEPRECATED, use “Sensitivity” instead.
  - “Sensitivity” between 0 and 1 to adjust the detection threshold. At 0, the robot does not detect any sound. At 1, it reacts to the slightest sound.

  So the sensitivity of the detection can be set by calling this function as follows:

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use setParameter Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the setParameter method.
          """
          # Get the service ALSoundDetection.

          sound_detect_service = session.service("ALSoundDetection")

          # Sets the sensitivity of the detection to 0.3 (less sensitive than default).
          # The default value is 0.9.
          sound_detect_service.setParameter("Sensitivity", 0.3)
          print "Sensitivity set to 0.3"

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALSoundDetection::``subscribe`(const std::string& name)

  Subscribes to ALSoundDetection. This causes the module to start writing information to ALMemory in “SoundDetected”. This can be accessed in ALMemory using `ALMemoryProxy::getData`.

  Parameters: | name – Name to identify the subscriber

void `ALSoundDetection::``unsubscribe`(const std::string& name)

  Unsubscribes to ALSoundDetection. This causes the module to stop writing information to ALMemory in “SoundDetected”.

  Parameters: | name – Name to identify the subscriber (as used in `ALSoundDetection::subscribe`).

## Events

Event: `"SoundDetected"`
callback(std::string eventName, AL::ALValue value, std::string subscriberIdentifier)

  Raised when a significant sound has been detected.

  Parameters: | eventName (std::string) – “SoundDetected” value – Detected sound informations. Please refer to ALSoundDetection for details. subscriberIdentifier (std::string) –

Glossary Site map Index Support Contact Legal Notices