ALAudioPlayer API

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.

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

Starts the playback of the specified task.

Parameters:
  • taskId – Id of the task handling the playing of the file
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 stero 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)
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)

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

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)

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)

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 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 caracteristics.

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