NAOqi Audio - Overview | API
Namespace : AL
#include <alproxies/alaudiodeviceproxy.h>
As any module, this module inherits methods from ALModule API. It also has the following specific methods:
Deprecated Parameter
Deprecated Methods
Experimental methods
Disables the computation of the energy on each input channel.
Enables the computation of the energy on each input channel (this computation is off by default). The result of this computation can be collected by calling:
This methods clears all the samples that may remain to be sent to the loudspeaker.
Returns the signal energy on the front microphone averaged on a 170ms buffer. The computation of the energy must first be enabled with ALAudioDeviceProxy::enableEnergyComputation().
Returns: | energy [0,32768] |
---|
Returns the signal energy on the left microphone averaged on a 170ms buffer. The computation of the energy must first be enabled with ALAudioDeviceProxy::enableEnergyComputation().
Returns: | energy [0,32768] |
---|
Gets the overall output volume of the system. This volume can be set with ALAudioDeviceProxy::setOutputVolume().
Returns: | volume [0,100] |
---|
Deprecated since version 1.22: parameter ‘inputBufferSize’ has no effect now.
This method returns the internal parameter (‘outputSampleRate’). The value -1 is returned if the specified parameter is not valid.
Parameters: |
|
---|---|
Returns: | value |
Returns the signal energy on the rear microphone averaged on a 170ms buffer. The computation of the energy must first be enabled with ALAudioDeviceProxy::enableEnergyComputation().
Returns: | energy [0,32768] |
---|
Returns the signal energy on the right microphone averaged on a 170ms buffer. The computation of the energy must first be enabled with ALAudioDeviceProxy::enableEnergyComputation().
Returns: | energy [0,32768] |
---|
Tells if the audio output device has been muted by a call to ALAudioDeviceProxy::muteAudioOut().
Returns: | True if the output device has been muted, False otherwise. |
---|
Mutes the output device.
Parameters: |
|
---|
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Opens the audio device used for capture by ALAudioDevice. This device is open by default. This method is however useful if you used ALAudioDeviceProxy::closeAudioInputs() before.
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Opens the audio device used for playback by ALAudioDevice. This device is open by default. This method is however useful if you used ALAudioDeviceProxy::closeAudioOutputs() before.
Play a sine wave which the specified characteristics.
Parameters: |
|
---|
By using this method a local module (a module running on the robot) can send a signal to the robot’s loudspeakers. This signal should be formated as a 16 bits stereo interleaved buffer. The size of this buffer should also not exceed 16384.
Parameters: |
|
---|---|
Returns: | True if the operation is successful - False otherwise |
Warning
This interface can crash the robot if not use correctly! Be very careful with the second parameter.
// Example: Play a 1kHz sine wav on the robot's loudspeakers during 2s
int sineTableSize = 1024;
int outputBufferSize = 16384;
float sine[sineTableSize];
int left_phase = 0;
int right_phase = 0;
int nbOfOutputChannels=2;
int sampleRate = 48000;
int freq =1000;
float duration = 2.0;
boost::shared_ptr<ALProxy> audiodeviceProxy = getParentBroker()->getProxy("ALAudioDevice");
signed short fOutputBuffer[nbOfOutputChannels*outputBufferSize];
for ( int i=0; i<sineTableSize; i++ )
{
sine[i] = float(32767) * sin((double(i)/double(sineTableSize))*M_PI*2.0);
}
float ratio= 1.0 /( 1.0 / float(freq) * float(sampleRate) / float(sineTableSize));
double inc= std::ceil(ratio);
int nbOfBuffersToSend = std::ceil(duration*sampleRate/outputBufferSize);
for (int d=0;d<nbOfBuffersToSend;d++)
{
for (int i=0;i<nbOfOutputChannels*outputBufferSize;i+=nbOfOutputChannels)
{
// left channel
fOutputBuffer[i] = (signed short)(float(sine[left_phase]));
// right channel
fOutputBuffer[i+1] = (signed short)(float(sine[right_phase]));
left_phase += inc;
if ( left_phase >= sineTableSize ) left_phase -= sineTableSize;
right_phase += inc;
if ( right_phase >= sineTableSize ) right_phase -= sineTableSize;
}
audiodeviceProxy->callVoid("sendLocalBufferToOutput",
outputBufferSize,
(int) &fOutputBuffer);
}
def onInput_onStart(self):
self.isRunning = True
self.ad = ALProxy("ALAudioDevice")
framemanager = ALProxy("ALFrameManager")
self.behaviorPath = framemanager.getBehaviorPath(self.behaviorId)
self.addedPaths = [self.behaviorPath]
for addedPath in self.addedPaths:
sys.path.append(addedPath)
from pydub import AudioSegment
songPath = self.behaviorPath + "/audio_file.wav"
self.song = AudioSegment.from_wav(songPath)
try:
# here is important to note that the second parameter is contigus memory audio data!
self.ad.sendLocalBufferToOutput(int(self.song.frame_count()), id(self.song._data))
except Exception as e:
self.log("error for buffer: " + str(e) + str(id(self.song.data)))
self.onUnload()
pass
By using this method a remote module (a module running outside the robot) can send a signal to the robot’s loudspeakers. This signal should be formated as a 16 bits stereo interleaved buffer. The size of this buffer should also not exceed 16384.
Parameters: |
|
---|---|
Returns: | True if the operation is successful - False otherwise |
By using this method a module can specify the format of the signal that will be sent after subscribing to ALAudioDevice. If no call to this method is made, the default format sent to this module is 4 channels interleaved at 48000Hz. Note that for now, only the following combinations are available:
This call must be made before the call to ALAudioDeviceProxy::subscribe() or startDetection() to be taken into account.
// This shows how setClientPreferences can be used
boost::shared_ptr<ALProxy> proxyAudioDevice = getParentBroker()->getProxy("ALAudioDevice");
proxyAudioDevice->callVoid("setClientPreferences",
getName(), //Name of this module
48000, //48000 Hz requested
(int)ALLCHANNELS, //4 Channels requested
1 //Deinterleaving requested
);
Parameters: |
|
---|
This method notifies ALAudioDevice that audio inputs should be read in the specified file instead. The specified sound file must be a .wav file containing 48000Hz, 16bits, 4 channels interleaved signals.
Parameters: |
|
---|
Sets the overall output volume of the system. This volume can be collected with ALAudioDeviceProxy::getOutputVolume().
Parameters: |
|
---|
Deprecated since version 1.22: parameter ‘inputBufferSize’ has no effect now.
This method sets the internal parameter (‘outputSampleRate’).
Parameters: |
|
---|
This method records the signal collected on the microphones directly into the specified file.
If the extension of the specified file is ‘wav’, data will be recored as a 16 bits, 48000Hz, 4 channels wav file.
If the extension of the specified file is ‘ogg’, data will be recored as a 16 bits, 16000Hz, 1 channels ogg file.
Parameters: |
|
---|
This method stops the recording started by the call to ALAudioDeviceProxy::startMicrophonesRecording().
This function allows a module which inherits from the ALSoundExtractor class to subscribe to the ALAudioDevice module. Once the module is subscribed, the function ‘process’ of the module (the module needs to contain one) will be automatically and regularly called with raw data from microphones as inputs. The call to this method can be replaced by a call to startDetection() within a NAOqi module that inherits from ALSoundExtractor.
The callback function must be declared as follows:
process(const int & nbOfChannels, const int & nbrOfSamplesByChannel, const AL_SOUND_FORMAT * buffer, const ALValue & timeStamp)
Parameters: |
|
---|
This function allows a module which inherits from the ALSoundExtractor class to unsubscribe from the ALAudioDevice module. This stops the regular calls to the module callback “process”. The call to this method can be replaced by a call to stopDetection() within a NAOqi module that inherits from ALSoundExtractor.
Parameters: |
|
---|
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Closes the audio device used for capture by ALAudioDevice. This method is useful to allow an external program (e.g. arecord) to access the input device of the robot. Note however that a call to this method will prevent every functionality that uses microphones to work correctly (e.g. ALSpeechRecognition, ALAudioSourceLocalization, etc...).
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Closes the audio device used for playback by ALAudioDevice. This method is useful to allow an external program (e.g. aplay) to access the output device of the robot. Note however that a call to this method will prevent every functionality that uses microphones to work correctly (e.g. ALTextToSpeech).
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Tells if the audio input device has been closed by a call to ALAudioDeviceProxy::closeAudioInputs().
Returns: | True if the input device has been closed, False otherwise. |
---|
Deprecated since version 1.22: due to technical improvements, closing the audio is not necessary anymore.
Tells if the audio output device has been closed by a call to ALAudioDeviceProxy::closeAudioOutputs().
Returns: | True if the output device has been closed, False otherwise. |
---|