程序说明书索引 >> 红色说明书索引

>音频系统

引言

ALAudio Player (音频播放器)

ALTextToSpeech (声音合成)

ALSpeechRecognition (语音识别)

ALAudioDevice (音频器件)

ALSoundDetection(声音识别)

ALAudioSourceLocalization(音频源定位)

使用指导:向扬声器发送声音

本指导介绍如何向NAO的扬声器发送声音

注释:

本指导使用C++语音编写。下文介绍的范例都包含在随SDK一起提供的范例源代码里,在"modules/src/examples/mysendingsoundmodule"中。这个范例将一个Wav文件的内容从一个远程桌面发送至NAO的扬声器上。

在模块上创建一个代理

在访问ALAudioDevice模块前,先在上面创建一个代理。

// Create a proxy on the ALAudioDevice module AL::ALPtr<AL::ALProxy> audioDeviceProxy = getParentBroker()->getProxy( "ALAudioDevice" );

向扬声器发送声音

根据是本地还是远程模块,使用“sendLocalBufferToOutput”或“sendRemoteBufferToOutput”函数向扬声器发送声音。

  • 如果是本地模块,就必须向sendLocalBufferToOutput函数传递一个要发送的缓冲区(必须转换为整数)的指针,以及每通道的帧数。 缓冲区必须包含16位立体声交叉存取样本。

    // Example: send a buffer containing 16384 16 bits stereo samples from a local module onto the loudspeakers int NbOfFrames=16384; // maximum buffer size that ALAudioDevice can send int NbOfChannels=2; short *pDataShort = new short [NbOfFrames*NbOfChannels]; // put samples in your buffer here audioDeviceProxy->call <bool> ("sendLocalBufferToOutput",NbOfFrames,(int) pDataShort);

    注释:

    AudioDevice输出点的采样率可通过setParameter函数予以调整。

    如果缓冲区采样在44100Hz,可以如下所示设定采样率:

    audioDeviceProxy->callVoid ( "setParameter",std::string( "outputSampleRate" ),44100 );

    请注意,Aldebaran提供的合成运行在22050Hz。所以,如果您想使用该合成、并发送自己的缓冲区,就必须把发送的缓冲区也采样在22050Hz。
  • 如果是远程模块,就必须向sendRemoteBufferToOutput函数传递缓冲区(在一个转换为二进制的AlValue里),以及每通道的帧数。 缓冲区必须包含16位立体声交叉存取样本。

    // Example: send a buffer containing 16384 16 bits stereo samples from a remote module onto the loudspeakers int NbOfFrames=16384; // maximum buffer size that ALAudioDevice can send int NbOfChannels=2; short *pDataShort = new short [NbOfFrames*NbOfChannels]; // put samples in your buffer here ALValue pDataBin; pDataBin.SetBinary( pDataShort, NbOfFrames*sizeof(short)*NbOfChannels ); audioDeviceProxy->call <bool> ("sendRemoteBufferToOutput",NbOfFrames,pDataBin);





Copyright © 2010 Aldebaran-Robotics - 版权所有