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

# ALAudioPlayer API

NAOqi Audio - Overview | API

Namespace : AL

    #include <alproxies/alaudioplayerproxy.h>

## Method list

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

class `ALAudioPlayerProxy`

- `ALAudioPlayerProxy::getCurrentPosition`
- `ALAudioPlayerProxy::getFileLength`
- `ALAudioPlayerProxy::getInstalledSoundSetsList`
- `ALAudioPlayerProxy::getLoadedFilesIds`
- `ALAudioPlayerProxy::getLoadedFilesNames`
- `ALAudioPlayerProxy::getLoadedSoundSetsList`
- `ALAudioPlayerProxy::getMasterVolume`
- `ALAudioPlayerProxy::getSoundSetFileNames`
- `ALAudioPlayerProxy::getVolume`
- `ALAudioPlayerProxy::goTo`
- `ALAudioPlayerProxy::isSoundSetFileInstalled`
- `ALAudioPlayerProxy::isSoundSetInstalled`
- `ALAudioPlayerProxy::isSoundSetLoaded`
- `ALAudioPlayerProxy::loadFile`
- `ALAudioPlayerProxy::loadSoundSet`
- `ALAudioPlayerProxy::pause`
- `ALAudioPlayerProxy::play`
- `ALAudioPlayerProxy::playFile`
- `ALAudioPlayerProxy::playFileFromPosition`
- `ALAudioPlayerProxy::playFileInLoop`
- `ALAudioPlayerProxy::playInLoop`
- `ALAudioPlayerProxy::playSine`
- `ALAudioPlayerProxy::playSoundSetFile`
- `ALAudioPlayerProxy::playWebStream`
- `ALAudioPlayerProxy::setMasterVolume`
- `ALAudioPlayerProxy::setPanorama`
- `ALAudioPlayerProxy::setVolume`
- `ALAudioPlayerProxy::stopAll`
- `ALAudioPlayerProxy::unloadAllFiles`
- `ALAudioPlayerProxy::unloadFile`
- `ALAudioPlayerProxy::unloadSoundSet`

## Methods

float `ALAudioPlayerProxy::``getCurrentPosition`(const int& taskId)

  Returns the position in seconds in the file currently played. The Id of the playing task will be returned when calling a play method (eg. `ALAudioPlayerProxy::play`) in a non-blocking manner. See below for an example in Python.

  `alaudioplayer_getcurrentposition.py`

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

      """Example: Use getCurrentPosition Method"""

      import qi
      import argparse
      import sys
      import time

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

          audio_player_service = session.service("ALAudioPlayer")

          #plays a file and get the current position 5 seconds later
          fileId = audio_player_service.loadFile("/usr/share/naoqi/wav/random.wav")
          audio_player_service.play(fileId, _async=True)

          time.sleep(3)

          #currentPos should be near 3 secs
          currentPos = audio_player_service.getCurrentPosition(fileId)
          print "The current position in file is: ", currentPos

      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)

  Parameters: | taskId – Id of the task handling the currently playing of the file
  Returns: | Current position in seconds

float `ALAudioPlayerProxy::``getFileLength`(const int& taskId)

  Returns the length in second of the file that is currently played.

  Parameters: | taskId – Id of the task handling the playing of the file
  Returns: | Length of the file in seconds

std::vector<std::string> `ALAudioPlayerProxy::``getInstalledSoundSetsList`()

  Returns the list of the installed soundsets.

std::vector<std::string> `ALAudioPlayerProxy::``getLoadedFilesIds`()

  Returns an array containing the task Ids corresponding to the currently loaded files. File can be loaded using `ALAudioPlayerProxy::loadFile`.

  Returns: | Array of task Ids

std::vector<std::string> `ALAudioPlayerProxy::``getLoadedFilesNames`()

  Returns an array containing the filenames (absolute paths) of the currently loaded files. File can be loaded using `ALAudioPlayerProxy::loadFile`.

  Returns: | Array of filenames

std::vector<std::string> `ALAudioPlayerProxy::``getLoadedSoundSetsList`()

  Returns an array containing the currently loaded soundsets.

  Returns: | Array of loaded soundsets

std::vector<std::string> `ALAudioPlayerProxy::``getSoundSetFileNames`(const std::string setName)

  Returns an array containing the filenames of the corresponding soundset.

  Parameters: | setName – name of the soundset to examine
  Returns: | Array of filenames

- `ALAudioPlayerProxy::getSoundSetFileNames`

float `ALAudioPlayerProxy::``getMasterVolume`()

  Returns the master volume used by ALAudioPlayer for playback. This volume can be set by using `ALAudioPlayerProxy::setMasterVolume`. This volume is independent of the system volume that can be set through ALAudioDevice.

  Returns: | Volume [0.0 - 1.0]

float `ALAudioPlayerProxy::``getVolume`(const int& taskId)

  Returns the volume level at which the specified task should be played. This volume is independent of the master volume set with `ALAudioPlayerProxy::setMasterVolume`. This task dependent volume can be set by using `ALAudioPlayerProxy::setVolume`.

  Parameters: | taskId – Id of the task handling the playing of the file
  Returns: | Volume - [0.0 - 1.0]

void `ALAudioPlayerProxy::``goTo`(const int& taskId, const float& position)

  Jumps to a given position in second in the specified file.

  Parameters: | taskId – Id of the task handling the playing of the file position – Position in the file (in second)

  `alaudioplayer_goto.py`

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

      """Example: Use goTo Method"""

      import qi
      import argparse
      import sys
      import time

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

          audio_player_service = session.service("ALAudioPlayer")

          fileId = audio_player_service.loadFile("/usr/share/naoqi/wav/random.wav")
          audio_player_service.play(fileId, _async=True)
          time.sleep(0.5)
          audio_player_service.goTo(fileId,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)

bool `ALAudioPlayerProxy::``isSoundSetFileInstalled`(const std::string& soundSet, const std::string& soundSetFile)

  Tells if a sound is present in a given soundset.

bool `ALAudioPlayerProxy::``isSoundSetInstalled`(const std::string& soundSet)

  Tells if a soundset is installed.

bool `ALAudioPlayerProxy::``isSoundSetLoaded`(const std::string& soundSet)

  Tells if a given soundset is already loaded.

int `ALAudioPlayerProxy::``loadFile`(const std::string& fileName)

  Preloads a file but does not play it yet. Preloading a file is a way to reduce the time necessary to actually start the playback when a “play” function is called. The playback of a loaded file can be started by calling `ALAudioPlayerProxy::play`.

  Parameters: | fileName – Absolute path of the file to load
  Returns: | Id of the task handling the playing of the file

void `ALAudioPlayerProxy::``loadSoundSet`(const std::string& setName)

  Loads a soundset.

  Parameters: | setName – Name of the soundset.

void `ALAudioPlayerProxy::``pause`(const int& taskId)

  Pause the playback of the specified task. The pause can be resume by calling `ALAudioPlayerProxy::play`.

  Parameters: | taskId – Id of the task handling the playing of the file

void `ALAudioPlayerProxy::``play`(const int& taskId)

  There are two overloads of this function:

  - ALAudioPlayerProxy::play
  - ALAudioPlayerProxy::play with volume and pan parameters

  Starts the playback of the specified task.

  Parameters: | taskId – Id of the task handling the playing of the file

  `alaudioplayer_play.py`

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

      """Example: Use play Method"""

      import qi
      import argparse
      import sys

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

          audio_player_service = session.service("ALAudioPlayer")

          #Loads a file and launchs the playing 5 seconds later
          fileId = audio_player_service.loadFile("/usr/share/naoqi/wav/random.wav")
          audio_player_service.play(fileId)

      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 `ALAudioPlayerProxy::``play`(const int& taskId, const float& volume, const float& pan)

  Starts the playback of the specified task, with a specific volume and stereo panorama. This task has for example been created using `ALAudioPlayerProxy::loadFile`.

  Parameters: | taskId – Id of the task handling the playing of the file volume – Volume of the sound file [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right)

  `alaudioplayer_play.py`

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

      """Example: Use play Method"""

      import qi
      import argparse
      import sys

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

          audio_player_service = session.service("ALAudioPlayer")

          #Loads a file and launchs the playing 5 seconds later
          fileId = audio_player_service.loadFile("/usr/share/naoqi/wav/random.wav")
          audio_player_service.play(fileId)

      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 `ALAudioPlayerProxy::``playFile`(const std::string& fileName)

  There are two overloads of this function:

  - ALAudioPlayerProxy::playFile
  - ALAudioPlayerProxy::playFile with volume and pan parameters

  Starts the playback of the specified file. This call is equivalent to calling successively `ALAudioPlayerProxy::loadFile` and `ALAudioPlayerProxy::play`.

  Parameters: | fileName – Absolute path of the file

  `alaudioplayer_playfile.py`

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

      """Example: Use playFile Method"""

      import qi
      import argparse
      import sys
      import time

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

          audio_player_service = session.service("ALAudioPlayer")

          #Launchs the playing of a file
          audio_player_service.playFile("/usr/share/naoqi/wav/random.wav")

          time.sleep(1.0)

          #Launchs the playing of a file on the left speaker to a volume of 50%
          audio_player_service.playFile("/usr/share/naoqi/wav/random.wav",0.5,-1.0)

      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 `ALAudioPlayerProxy::``playFile`(const std::string& fileName, const float& volume, const float& pan)

  Starts the playback of the specified file. This call is equivalent to calling successively `ALAudioPlayerProxy::loadFile` and `ALAudioPlayerProxy::play` with specific volume and pan.

  Parameters: | fileName – Absolute path of the file volume – Volume of the sound file [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

  `alaudioplayer_playfile.py`

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

      """Example: Use playFile Method"""

      import qi
      import argparse
      import sys
      import time

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

          audio_player_service = session.service("ALAudioPlayer")

          #Launchs the playing of a file
          audio_player_service.playFile("/usr/share/naoqi/wav/random.wav")

          time.sleep(1.0)

          #Launchs the playing of a file on the left speaker to a volume of 50%
          audio_player_service.playFile("/usr/share/naoqi/wav/random.wav",0.5,-1.0)

      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 `ALAudioPlayerProxy::``playFileFromPosition`(const std::string& fileName, const float& position)

  There are two overloads of this function:

  - ALAudioPlayerProxy::playFileFromPosition
  - ALAudioPlayerProxy::playFileFromPosition with volume and pan parameters

  Starts the playback of the specified file from a given position in second.

  Parameters: | fileName – Absolute path of the file position – Position in second where the playing should begin

void `ALAudioPlayerProxy::``playFileFromPosition`(const std::string& fileName, const float& position, const float& volume, const float& pan)

  Starts the playback of the specified file from a given position in second with a given volume and pan.

  Parameters: | fileName – Absolute path of the file position – Position in second where the playing should begin volume – Volume requested [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

void `ALAudioPlayerProxy::``playFileInLoop`(const std::string& fileName)

  There are two overloads of this function:

  - ALAudioPlayerProxy::playFileInLoop
  - ALAudioPlayerProxy::playFileInLoop with volume and pan parameters

  Starts the playback of the specified file and loop. The playback can then be stopped by calling stop(const int & taskId).

  Parameters: | fileName – Absolute path of the file

void `ALAudioPlayerProxy::``playFileInLoop`(const std::string& fileName, const float& volume, const float& pan)

  Starts the playback of the specified file and loop, with specific volume and pan. The playback can then be stopped by calling stop(const int & taskId).

  Parameters: | fileName – Absolute path of the file volume – Volume requested [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

void `ALAudioPlayerProxy::``playInLoop`(const int& taskId)

  There are two overloads of this function:

  - ALAudioPlayerProxy::playInLoop
  - ALAudioPlayerProxy::playInLoop with volume and pan parameters

  Starts the playback of the specified task and loop.

  Parameters: | taskId – Id of the task handling the playing of the file

void `ALAudioPlayerProxy::``playInLoop`(const int& taskId, const float& volume, const float& pan)

  Plays a wav, ogg or mp3 file in loop, with specific volume and audio balance

  Parameters: | taskId – Id of the task handling the playing of the file volume – Volume requested [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

void `ALAudioPlayerProxy::``playSine`(const int& frequence, const int& gain, const int& pan, const float& duration)

  Play a sine wave which the specified characteristics.

  Parameters: | frequence – Frequence in Hertz gain – Volume between [0 - 100] pan – Stereo Pan set to either {-1,0,+1} duration – Duration of the sine wave in seconds

void `ALAudioPlayerProxy::``playSoundSetFile`(const std::string& fileName)

  There are 3 overloads of this function:

  - ALAudioPlayerProxy::playSoundSetFile in one of the loaded soundsets.
  - ALAudioPlayerProxy::playSoundSetFile in the specified soundset.
  - ALAudioPlayerProxy::playSoundSetFile in the specified soundset and with specified parameters.

  Plays a sound contained in one of the loaded soundsets.

  If the same sound is present in different soundsets, it takes the sound of the first soundset loaded which contains this sound.

  Parameters: | fileName – Name of the sound file.

void `ALAudioPlayerProxy::``playSoundSetFile`(const std::string& soundSetName, const std::string& fileName)

  Plays a sound contained in a in a specified soundset with the default parameters.

  Parameters: | soundSetName – Name of the soundset. fileName – Name of the sound file.

void `ALAudioPlayerProxy::``playSoundSetFile`(const std::string& soundSetName, const std::string& fileName, const float& position, const float& volume, const float& pan, const bool& loop)

  Plays a sound contained in a specified soundset and with specified parameters.

  Parameters: | soundSetName – Name of the soundset. fileName – Name of the sound file. position – position in second in the specified file. volume – Volume. pan – Stereo panorama requested (-1.0 : left / 1.0 : right). loop – play in loop yes/no.

void `ALAudioPlayerProxy::``playWebStream`(const std::string& streamName, const float& volume, const float& pan)

  Starts the playback of a web audio stream.

  Parameters: | streamName – Path of the web audio stream volume – Volume requested [0.0 - 1.0] pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

void `ALAudioPlayerProxy::``setMasterVolume`(const float& volume)

  Sets the master volume used by ALAudioPlayer for playback. This volume is independent of the system volume that can be set through ALAudioDevice.

  Parameters: | volume – Volume [0.0 - 1.0]

void `ALAudioPlayerProxy::``setPanorama`(const float& pan)

  Sets the stereo panorama for all the playback tasks handled by ALAudioPlayer.

  Parameters: | pan – Stereo panorama requested (-1.0 : left / 1.0 : right / 0.0 : center)

void `ALAudioPlayerProxy::``setVolume`(const int& taskId, const float& volume)

  Sets the volume level at which the specified task should be played. This volume is independent of the master volume set with `ALAudioPlayerProxy::setMasterVolume`.

  Parameters: | taskId – Id of the task handling the playing of the file volume – Volume - [0.0 - 1.0]

void `ALAudioPlayerProxy::``stopAll`()

  Stops all the files that are currently being played.

void `ALAudioPlayerProxy::``unloadAllFiles`()

  Unloads all the files already loaded.

void `ALAudioPlayerProxy::``unloadFile`(const int& taskId)

  Unloads a file previously loaded with `ALAudioPlayerProxy::loadFile`.

  Parameters: | taskId – Id of the task handling the playing of the file

void `ALAudioPlayerProxy::``unloadSoundSet`(const std::string& setName)

  Unloads a soundset.

  Parameters: | setName – Name of the soundset.

Glossary Site map Index Support Contact Legal Notices