ALAudioPlayer API

NAOqi Audio - Overview | API


Namespace : AL

#include <alproxies/alaudioplayerproxy.h>

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

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_play.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)

#plays a file and get the current position 5 seconds later
fileId = aup.post.playFile("/usr/share/naoqi/wav/random.wav")

time.sleep(5)

#currentPos should be near 5 secs
currentPos = aup.getCurrentPosition(fileId)
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

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

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_goto.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)

#Launchs the playing of a file, waits for 2 seconds, and goes to the 5th second
fileId = aup.post.playFile("/usr/share/naoqi/wav/random.wav")
time.sleep(1)
aup.goTo(fileId,2)
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:

Starts the playback of the specified task.

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

alaudioplayer_play.py

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_play.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)

#Loads a file and launchs the playing 5 seconds later
fileId = aup.loadFile("/usr/share/naoqi/wav/random.wav")
time.sleep(5)
aup.play(fileId)
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

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_play.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)

#Loads a file and launchs the playing 5 seconds later
fileId = aup.loadFile("/usr/share/naoqi/wav/random.wav")
time.sleep(5)
aup.play(fileId)
void ALAudioPlayerProxy::playFile(const std::string& fileName)

There are two overloads of this function:

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

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_playfile.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)
    
#Launchs the playing of a file
aup.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%
aup.playFile("/usr/share/naoqi/wav/random.wav",0.5,-1.0)
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

# -*- encoding: UTF-8 -*-

import sys
import time
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python audioplayer_playfile.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    aup = ALProxy("ALAudioPlayer", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALAudioPlayer"
    print "Error was: ",e
    sys.exit(1)
    
#Launchs the playing of a file
aup.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%
aup.playFile("/usr/share/naoqi/wav/random.wav",0.5,-1.0)
void ALAudioPlayerProxy::playFileFromPosition(const std::string& fileName, const float& position)

There are two overloads of this function:

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:

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:

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:

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.