Pepper やNaoで使用されているNaoqi OSのメモです。

このページについて


NAOqi Audio - 概要 | API


Namespace : AL
#include <alproxies/alaudioplayerproxy.h>

メソッドリスト


全てのモジュールはALmoduleAPIのメソッドを継承しています。更に以下のメソッドを持ちます。

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

メソッド


floatALAudioPlayerProxy::getCurrentPosition(const int& taskId)
y
再生中のファイルの再生時間を秒で返します。
再生タスクのIDは再生メソッドを呼び出すときにノンブロッキングで返されます。
以下の例を参照してください。

alaudioplayer_getcurrentposition.py

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

"""getCurrentPositionメソッドの使用例"""

import qi
import argparse
import sys
import time


def main(session):
    """
    この例ではgetCurrentPositionメソッドを使用します。
    """
    # 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(3)

    # 現在位置は3秒前後になるはずです。
    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)


パラメータ: taskId – ファイル再生を実行しているタスクのID
返り値: 秒単位での現在位置

float ALAudioPlayerProxy::getFileLength(const int& taskId)
現在再生中のファイルの長さ(秒)

パラメータ:
taskId – ファイルの再生を実行しているタスクのID
返り値:
ファイルの長さ(秒)

std::vector<std::string> ALAudioPlayerProxy::getInstalledSoundSetsList()
返り値: インストールされたサウンドセットのリスト

std::vector<std::string> ALAudioPlayerProxy::getLoadedFilesIds()
返り値: 読み込まれたファイルに一致するタスクIDを持つ配列。ファイルはALAudioPlayerProxy::loadFileで読み込まれる。

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()
返り値: 読み込まれたサウンドセットを持つ配列

std::vector<std::string> ALAudioPlayerProxy::getSoundSetFileNames(const std::string setName)
返り値: サウンドセットに一致するファイル名を持つ配列

パラメータ:
setName – テストするサウンドセットの名前

・ALAudioPlayerProxy::getSoundSetFileNames

float ALAudioPlayerProxy::getMasterVolume()
返り値: ALAudioPlayerに使われるマスターボリューム。マスターボリュームはALAudioPlayerProxy::setMasterVolumeでセットできます。このボリュームはALAudioDeviceを通してセットされるシステムボリュームとは独立したものです。
ボリュームは[0.0 - 1.0]の範囲で返ります。

float ALAudioPlayerProxy::getVolume(const int& taskId)
返り値: ある再生タスクで使われるボリューム。このボリュームはALAudioPlayerProxy::setMasterVolumeでセットされるマスターボリュームとは独立したものです。また、ALAudioPlayerProxy::setVolumeでセットされたものからも独立しています。
ボリュームは[0.0 - 1.0]の範囲で返ります。

パラメータ:
taskId – ファイルの再生を実行するタスクのID

void ALAudioPlayerProxy::goTo(const int& taskId, const float& position)
再生するファイルにおいて特定のポジションに跳びます。

パラメータ:
taskId – ファイルの再生を実行するタスクのID
position – ファイルにおけるポジション(秒)

alaudioplayer_goto.py

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

"""goToメソッドの使用例"""

import qi
import argparse
import sys
import time


def main(session):
    """
    この例ではgoToメソッドを使用します。
    """
    # 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)
サウンドセットにサウンドが存在しているかどうか

bool ALAudioPlayerProxy::isSoundSetInstalled(const std::string& soundSet)
サウンドセットがインストールされているかどうか

bool ALAudioPlayerProxy::isSoundSetLoaded(const std::string& soundSet)¶
サウンドセットがすでに読み込まれているかどうか

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

ファイルを読み込みますが、再生はしません。再生するときのラグを減らすよう予め読み込んだ状態にします。
再生するにはALAudioPlayerProxy::playを使用します。

パラメータ: fileName – 読み込むファイルの絶対パス
返り値: ファイルの再生を実行するタスクのID

void ALAudioPlayerProxy::loadSoundSet(const std::string& setName)
サウンドセットの読み込み

パラメータ:
setName – サウンドセットの名前

void ALAudioPlayerProxy::pause(const int& taskId)
あるタスクの再生を停止します。ALAudioPlayerProxy::playによって再び再生することができます。

パラメータ:
taskId – 再生を実行するタスクのID

void ALAudioPlayerProxy::play(const int& taskId)

この関数には2つのオーバーロードが存在します。
・ALAudioPlayerProxy::play
・ALAudioPlayerProxy::play with volume and pan parameters
Starts the playback of the specified task.

パラメータ:
taskId – 再生タスクのID
alaudioplayer_play.py

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

"""playメソッドの使用例"""

import qi
import argparse
import sys


def main(session):
    """
    この例ではplayメソッドを使用します。
    """
    # ALAudioPlayerサービスの取得

    audio_player_service = session.service("ALAudioPlayer")

    # ファイルの読み込みと再生をします。
    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)
あるタスクの再生をボリュームとステレオパノラマを指定して実行します。

パラメータ:
taskId – 再生タスクのID
volume – サウンドファイルのボリューム [0.0 - 1.0]
pan – ステレオパノラマ (-1.0 : left / 1.0 : right)
alaudioplayer_play.py

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

"""playメソッドの使用例"""

import qi
import argparse
import sys


def main(session):
    """
    この例はplayメソッドを使用します。
    """
    # ALAudioPlayerサービスの取得

    audio_player_service = session.service("ALAudioPlayer")

    # ファイルの読み込みと再生
    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)
2つのオーバーロードが存在します。

・ALAudioPlayerProxy::playFile
・音量とパンパラメータを持つALAudioPlayerProxy::playFile
指定されたファイルの再生を開始します。 この呼び出しは、ALAudioPlayerProxy :: loadFileとALAudioPlayerProxy :: playを連続して呼び出すのと同じです。

パラメータ:
fileName – ファイルの絶対パス
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)

指定されたファイルの再生を開始します。 この呼び出しは、特定のボリュームとパンでALAudioPlayerProxy :: loadFileとALAudioPlayerProxy :: playを連続して呼び出すのと同じです。

パラメータ:
fileName – ファイルの絶対バス
volume – 音楽ファイルの音量 [0.0 - 1.0]
pan – ステレオパノラマリクエスト (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)
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)
この関数には2つのオーバーロードがあります。:

・ALAudioPlayerProxy::playFileFromPosition
・音量とパンパラメータを持つALAudioPlayerProxy::playFileFromPosition
指定されたファイルの再生を指定された位置から秒単位で開始します。

パラメータ:
fileName – ファイルの絶対パス
position – 秒単位で指定した再生を開始する位置


void
ALAudioPlayerProxy::playFileFromPosition(const std::string& fileName, const float& position, const float& volume, const float& pan)
与えられたボリュームとパンで、指定されたファイルの再生を所定の位置から秒単位で開始します。

Parameters:
fileName – ファイルの絶対パス
position – 秒単位で指定した再生を開始する位置
volume – 要求された音量 [0.0 - 1.0]
pan – ステレオパノラマリクエスト (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)

void
ALAudioPlayerProxy::playFileInLoop(const std::string& fileName)
この関数には2つのオーバーロードがあります。:

・ALAudioPlayerProxy::playFileInLoop
・音量とパンパラメータを持つALAudioPlayerProxy::playFileInLoop
指定したファイルの再生を開始し、ループします。 再生を停止するには、stop(const int & taskId)を呼び出します。

パラメータ:
fileName – ファイルの絶対パス

void ALAudioPlayerProxy::playFileInLoop(const std::string& fileName, const float& volume, const float& pan)
指定したファイルの再生を開始し、ループします。 再生を停止するには、stop(const int & taskId)を呼び出します。

パラメータ:
fileName – ファイルの絶対パス
volume – 要求された音量 [0.0 - 1.0]
pan – ステレオパノラマリクエスト (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)

void ALAudioPlayerProxy::playInLoop(const int& taskId)
この関数には2つのオーバーロードがあります。:

・ALAudioPlayerProxy::playInLoop
・音量とパンパラメータを持つALAudioPlayerProxy::playInLoop
指定したファイルの再生を開始し、ループします。

パラメータ:
taskId – 再生を実行するタスクのID

void ALAudioPlayerProxy::playInLoop(const int& taskId, const float& volume, const float& pan)
拡張子がwav、ogg、mp3のファイルを指定した音量とバランスでループします。

パラメータ:
taskId – 再生を実行するタスクのID
volume – 要求された音量 [0.0 - 1.0]
pan – ステレオパノラマリクエスト (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)

void ALAudioPlayerProxy::playSine(const int& frequence, const int& gain, const int& pan, const float& duration)
指定した特徴のsin波を再生します。

Parameters:
frequence – 周波数の単位はヘルツ
gain – 要求された音量 [0 - 100]
pan – ステレオパノラマを次のいずれかに設定 {-1,0,+1}
duration –秒単位でのsin波の長さ

void ALAudioPlayerProxy::playSoundSetFile(const std::string& fileName)
この関数には3つのオーバーロードがあります。:

・ロードされたサウンドセットのひとつにおけるALAudioPlayerProxy::playSoundSetFile
・指定されたサウンドセットにおけるALAudioPlayerProxy::playSoundSetFile
・指定されたサウンドセット、パラメータにおけるALAudioPlayerProxy::playSoundSetFile
ロードされたサウンドセットの1つに含まれるサウンドを再生します。

同じサウンドが異なるサウンドセットに存在する場合、このサウンドを含む最初にロードされたサウンドセットのサウンドが取り込まれます。

パラメータ:
fileName – サウンドファイルの名前

void ALAudioPlayerProxy::playSoundSetFile(const std::string& soundSetName, const std::string& fileName)
指定されたサウンドセットに含まれているサウンドをデフォルトのパラメータで再生します。

パラメータ:
soundSetName – サウンドセットの名前
fileName – サウンドファイルの名前

void ALAudioPlayerProxy::playSoundSetFile(const std::string& soundSetName, const std::string& fileName, const float& position, const float& volume, const float& pan, const bool& loop)
指定されたサウンドセットおよび指定されたパラメータに含まれるサウンドを再生します。

パラメータ:
soundSetName – サウンドセットの名前
fileName – サウンドファイルの名前
position – 指定したファイルの二番目
volume – 音量
pan – 要求されたステレオパノラマ (-1.0 : 左 / 1.0 : 右)
loop – ループ再生 はい/いいえ.

void ALAudioPlayerProxy::playWebStream(const std::string& streamName, const float& volume, const float& pan)
Webオーディオストリームの再生を開始します。

パラメータ:
streamName – webオーディオストリームのパス
volume – 要求された音量 [0.0 - 1.0]
pan – 要求されたステレオパノラマ (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)

void ALAudioPlayerProxy::setMasterVolume(const float& volume)
再生のためにALAudioPlayerが使用するマスターボリュームを設定します。この音量は、ALAudioDeviceで設定できるシステムボリュームとは独立しています。

Parameters:
volume – 音量 [0.0 - 1.0]

void ALAudioPlayerProxy::setPanorama(const float& pan)
ALAudioPlayerが扱うすべての再生タスクのステレオパノラマを設定します。

パラメータ:
pan – 要求されたステレオパノラマ (-1.0 : 左 / 1.0 : 右 / 0.0 : 中央)
void ALAudioPlayerProxy::setVolume(const int& taskId, const float& volume)
指定したタスクを再生する音量を設定します。 この音量は、ALAudioPlayerProxy :: setMasterVolumeで設定されたマスターボリュームとは独立しています。

パラメータ:
taskId – ファイルの再生を処理するタスクのID
volume – 音量 - [0.0 - 1.0]

void ALAudioPlayerProxy::stopAll()
現在再生されているすべてのファイルを停止します。

void ALAudioPlayerProxy::unloadAllFiles()
既にロードされているすべてのファイルをアンロードします。

void ALAudioPlayerProxy::unloadFile(const int& taskId)
以前にALAudioPlayerProxy :: loadFileでロードされたファイルをアンロードします。

パラメータ:
taskId – ファイルの再生を処理するタスクのID

void ALAudioPlayerProxy::unloadSoundSet(const std::string& setName)
サウンドセットをアンロードします。

パラメータ:
setName – サウンドセットの名前

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Menu

NAOqi - Developer guide

Creating an application?

Programming for a living robot?

Other tutorials?

Choregraphe Suite?

どなたでも編集できます