OpenHRI Manual¶
Manual in other languages:
OpenHRIマニュアル¶
English document is here
Contents:
イントロダクション¶
OpenHRIは、音声認識・音声合成・対話制御など、ロボットのコミュニケーショ ン機能の実現に必要な各要素を実現するコンポーネント群です。
フリーで利用できる各オープンソースソフトウェアを使い易いコンポーネント としてまとめました。
チュートリアル¶
Contents:
Step1: インストール¶
ここでは、プラットホームごとのOpenHRIのインストール方法を説明します。:
Windowsへのインストール¶
インストーラを以下のURLよりダウンロード・実行してください。
http://openhri.net/getinstaller.php
インストーラを実行するとウィザードが起動し必要なパッケージを順次ダウンロード・インストールします。
OpenHRIAudioの場合を以下に示します。OpenHRIVoice、SEATSATも同様にインストールしてください。
言語を選びます。”Japanese”を選択して[OK]ボタンを押してください。
ウィザードが起動します。[次へ(N)]のボタンを押してください。
ライセンス契約書が表示されます。[同意する(A)]のボタンを押してください。
コンポーネント選択画面が表示されます。すべてチェックして[次へ(N)]のボタンを押してください。
インストール場所の選択です。デフォルトは”C:Program FilesOpenHRIAudio”にインストールされます。
インストール場所を変更する場合は[参照(R)]ボタンを押してインストールする場所を指定してください。
インストール場所に問題がなければ[インストール]ボタンを押してインストールが開始されます。
インストール実行中です。インストールが完了したら[次へ(N)]のボタンを押してください。
インストールが完了しました。[完了(F)]ボタンを押してください。
OpenHRIAudio・OpenHRIVoice・SEATSATのすべてのパッケージのインストールが完了したら、続いてコンポーネントの動作を確認しましょう。
Ubuntuへのインストール¶
コマンドラインを使ったインストール(推奨)¶
ターミナルを開いて以下のコマンドを入力してください:
$ sudo apt-add-repository ppa:openhri/ppa
$ sudo apt-get update
$ sudo apt-get install openhriaudio openhrivoice seatsat
インストールに必要な作業はこれだけです。
GUIを使ったインストール¶
OpenHRIソフトウェアのリポジトリを登録しておくことで、Synapticパッケージマネージャで最新のソフトウェアが導入ができるようになります。
「システム」>「システム管理」>「Synapticパッケージ・マネージャ」を開きます。(パスワード入力あり)
「設定(S)」>「リポジトリ(R)」を開き、「他のソフトウェア」(または「サードパーティのソフトウェア」)タブを開きます。
「+追加」をクリックし、「APT line:」に以下のアドレス:
deb http://ppa.launchpad.net/openhri/ppa/ubuntu lucid main
を入力して「ソースの追加(A)」をクリックします。
![]()
Note
上記のアドレスはubuntu 10.04の場合です。OpenHRIはバイナリパッケージとして現在ubuntu 10.04のみをサポートしています。
左上にある「再読み込み」をクリックしてパッケージ情報をダウンロードします。
以上の操作でリポジトリの登録が完了しました。続けて音声コンポーネントのインストールを行いましょう。
クイック検索欄や検索ウィンドウ(検索ボタンを押すと現れる)を利用して、パッケージ名”openhriaudio”、”openhrivoice”、”seatsat”を検索して現れた項目を選び、右クリックメニューのインストール指定をクリックします。
クイック検索
検索したパッケージを選び、右クリックメニューから「インストール指定」を選ぶと、パッケージ名左のチェックボックスに印がつく。
チェックしたのち、「適用」ボタンをクリックしてインストールを開始します。
以上でコンポーネントのインストールが完了しました。続いてコンポーネントの動作を確認しましょう。
インストールが完了しましたら、次へ進んでください。 Step2: RTSystemEditorの使い方と音声入出力コンポーネントのテスト.
Step2: RTSystemEditorの使い方と音声入出力コンポーネントのテスト¶
このステップでは、オーディオコンポーネントの動作テストを行います。
音声入力コンポーネントと音声出力コンポーネントを直接つないで、オーディオコンポーネントが正常に動作していることを確認します。
準備¶
- RT-SystemEditorが組み込まれたeclipseをインストールします。
- Ubuntuの場合、このページに書かれた手順に従ってください: http://openrtm.org/openrtm/en/node/945
- Windowsの場合、このページからダウンロードできるOpenRTM-aist-Pythonパッケージをインストールしてください: http://openrtm.org/openrtm/ja/node/932#toc3
- マイクとスピーカ(イヤホン、ヘッドフォン)を用意し、PCと接続します。
- rtc.confファイルを作成します。
RTCコンフィギュレーションファイル “rtc.conf” を作成します。作業ディレクトリ に、次のような内容のテキストファイル“rtc.conf” を作成し配置してください。
corba.nameservers: localhost:9876 naming.formats: %n.rtc logger.file_name:stdoutWindowsの場合、rtc.confはインストーラが自動で作成してくれます。
- ネームサーバを立ち上げます。
rtc.confファイルでポート番号を指定したときは、指定したポート番号でネームサーバを起動します。(上記の例なら9876)
$ rtm-naming 9876![]()
- RT-SystemEditorを立ち上げます。
RT-SystemEditorの基本的な使い方¶
音声入出力コンポーネントの起動とRT-SystemEditorの基本的な使用方法を説明します。
AudioInputコンポーネントおよびAudioOutputコンポーネントを立ち上げます。
Warning
Ubuntuで使用する場合Uubuntuのバージョンにより立ち上げるコンポーネントを変更します。 Ubuntu9.10以降はPulseAudioInput、PulseAudioOutputコンポーネントを使用します。 それ以前のバージョンではPortAudioInput、PortAudioOutputコンポーネントを使用します。
- Ubuntu9.10以降の場合:端末上より以下のコマンドを入力してください。
$ pulseaudioinput
$ pulseaudiooutput
- それ以前のバージョンの場合:端末上より以下のコマンドを入力してください。
$ portaudioinput
$ portaudiooutput
RT-SystemEditorを開きます。
ネームサービス内の「ネームサーバを追加」を選択してrtc.confファイルで指定したネームサーバを登録します。
(上記の例なら localhost:9876)
左上のアイコンをクリックし新規エディタ画面を開きます。
ネームサービスビュー(左のパネル)のAudioInput(およびAudioOutput)をエディタ画面にドラッグ&ドロップして配置します。
配置したコンポーネントのデータポート同士を接続します。
データポートのコネクタ部分をクリックして、
そのままもう一方の端子までドラッグします。
ドロップすると接続設定ダイアログが出現します。設定は変更しません。
OKボタンを押すと接続されます。(コネクタの色が緑に変化します)
コンポーネントのアクティブ化と動作確認¶
- RTCをアクティブ状態にします。
“All Activate” ボタンを押して、すべてのRTCコンポーネントをアクティブ状態に遷移させます。
![]()
AudioInputとAudioOutputがアクティブ化し、オブジェクトの色が青から緑に変化します。
![]()
動作を確認します。
マイクに音声を入力してスピーカに音声が流れることを確認します。
Step2ではオーディオコンポーネントのテストからRT-SystemEditorの基本的な使い方を説明しました。
Step3: 音声合成コンポーネントのテスト¶
ここでは、音声合成コンポーネントの使い方を学びます。
準備¶
- テスト用コンポーネントの準備
定期的にテキストデータを出力するコンポーネントを用意します。以下のようなテストプログラムを作成して下さい。
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time import OpenRTM_aist import RTC consolein_spec = ["implementation_id", "ConsoleIn", "type_name", "ConsoleIn", "description", "Console input component", "version", "1.0", "vendor", "sample", "category", "example", "activity_type", "DataFlowComponent", "max_instance", "10", "language", "Python", "lang_type", "script", ""] class ConsoleIn(OpenRTM_aist.DataFlowComponentBase): def __init__(self, manager): OpenRTM_aist.DataFlowComponentBase.__init__(self, manager) self._data = RTC.TimedString(RTC.Time(0,0),"") self._outport = OpenRTM_aist.OutPort("out", self._data) def onInitialize(self): self.registerOutPort("out", self._outport) return RTC.RTC_OK def onExecute(self, ec_id): self._data.data = "testing" OpenRTM_aist.setTimestamp(self._data) self._outport.write() time.sleep(5) return RTC.RTC_OK def MyModuleInit(manager): profile = OpenRTM_aist.Properties(defaults_str=consolein_spec) manager.registerFactory(profile, ConsoleIn, OpenRTM_aist.Delete) comp = manager.createComponent("ConsoleIn") def main(): mgr = OpenRTM_aist.Manager.init(sys.argv) mgr.setModuleInitProc(MyModuleInit) mgr.activateManager() mgr.runManager() if __name__ == "__main__": main()以後、このテスト用コンポーネントをConsoleInコンポーネントと呼称します。
- rtc.confの用意
Step2: RTSystemEditorの使い方と音声入出力コンポーネントのテスト で使用したものと同等の設定ファイルを用意します。
テスト手順¶
- ConsoleInコンポーネント、OpenJTalkコンポーネントを起動します。
ターミナルを開き、以下のコマンドを入力します。
% python ConsoleIn.py% openjtalkrtcRT SystemEditorのネームサービスビューに起動したコンポーネントが表示されていることを確認します。
![]()
- RT-SystemEditorにConsoleInコンポーネント、OpenJTalkコンポーネントを配置します。
ドラッグ&ドロップでエディタに配置します。
![]()
- AudioInput-AudioOutput間のリンクを削除します。
リンクを選択してDeleteキーまたは右クリックメニューから”Delete”を選ぶと、リンクが削除されます。
![]()
- ConsoleIn、OpenJTalk、AudioOutputをそれぞれ接続します。
- ConsoleInの出力ポートとOpenJTalkの入力ポートを接続します。
- OpenJTalkの出力ポート「result」とAudioOutputの入力ポートを接続します。
(違うポートに接続しないように注意して下さい。)
![]()
- アクティブ化して動作を確認します。
“All Activate” ボタンを押してで全コンポーネントをアクティブ化します。
ConsoleInコンポーネントに設定した文が音声として出力されることを確認してください。
次は、音声認識コンポーネントと接続することで簡単な対話システムを作ってみましょう。
Step4: 対話システムを作ろう¶
音声認識コンポーネントと対話マネージャコンポーネントと組み合わせることで、入力した音声に対して応答を返す簡単な対話システムを作成してみましょう。
準備¶
- 音声認識コンポーネントの準備
音声認識コンポーネントに設定する音声認識文法を用意します。
以下のようなテキストデータを作成して下さい。テキストデータの文字コードはUTF-8を使用します。
sample.xml
<?xml version="1.0" encoding="UTF-8" ?> <grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd" xml:lang="jp" version="1.0" mode="voice" root="command"> <rule id="command"> <one-of> <item>こんにちは</item> <item>さようなら</item> </one-of> </rule> </grammar>Windowsの メモ帳から作成する場合、コードを貼り付けたあと、[ファイル>名前をつけて保存]を選び、開いたウィンドウ下部の[文字コード]から[UTF-8]
を選択して保存してください。
![]()
![]()
- 対話マネージャコンポーネントの準備
対話マネージェコンポーネントに設定するスクリプトデータを用意します。
以下のようなテキストデータを作成して下さい。
sample.seatml
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="speechout" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>こんにちは</key> <command host="speechout">こんにちは</command> </rule> <rule> <key>さようなら</key> <command host="speechout">バイバイ</command> </rule> </state> </seatml>
- 設定ファイルrtc.confの用意
Step2: RTSystemEditorの使い方と音声入出力コンポーネントのテスト で使用したものと同等の設定ファイルを用意します。
テスト手順¶
- SEATコンポーネント、Juliusコンポーネントを起動します。
Juliusコンポーネントは準備1.で用意した文法ファイル(sample.xml)を読み込みます。
$ juliusrtc sample.xmlSEATコンポーネントは準備2.で用意したスクリプトファイル(sample.seatml)を読み込みます。
$ seat sample.seatmlRT System Editorのネームサービスビューに起動したコンポーネントが表示されていることを確認します。
![]()
- RT System EditorにSEATコンポーネント、Juliusコンポーネントを配置します。
- 各コンポーネントを接続します。
- ConsoleInとOpenJTalk間のリンクを削除します。
- AudioInputの出力ポートとJuliusの入力ポートを接続します。
- Juliusの出力ポート“result”とSEATの入力ポート接続します。
- SEATの出力ポートとOpenJTalkの入力ポート接続します。
![]()
- アクティブ化して動作を確認します。
“All Activate” ボタンを押して全コンポーネントをアクティブ状態に遷移させます。
台詞「こんにちは」「さようなら」をマイクの前でしゃべって、応答音声が出力されるのを確認しましょう。
Note
うまく認識できない場合の注意:
うまく認識できない場合は以下の点を確認してみてください。
- 静かなところで行う
- 背景雑音が入っていないかどうか、周囲の雑音に注意してください。雑音が多い環境で認識したい場合はヘッドセットマイクや指向性マイクなど、雑音が入りにくいマイクの使用を検討してください。
- マイクの入力音量を変えてみる
- マイクの音量が大きすぎたり小さすぎたりすると音声認識をすることができません(Juliusを起動したコンソールに”Warning: strip~”などの警告が表示されている場合、マイクの音量設定が適切でない可能性があります)。ボリュームメーターを見ながらメーターが振り切れない程度の大きさに調整してください。
Step5: 対話システムを外部に接続しよう¶
対話システムを外部のコンポーネントに接続してみましょう。
対話マネージャへ与えるスクリプトを以下のように編集してください。
sample2.seatml
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="speechout" type="rtcout" datatype="TimedString" /> <agent name="commandout" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>こんにちは</key> <command host="speechout">こんにちは</command> <command host="commandout">hello</command> </rule> <rule> <key>さようなら</key> <command host="speechout">バイバイ</command> <command host="commandout">bye</command> </rule> </state> </seatml>
- SEATコンポーネントを起動している端末をCtrl+Cなどで停止させて、編集したスクリプトファイルを引数に与えて再度起動します。
% seat sample2.seatml
再起動した対話マネージャは出力ポートがひとつ増えています。
このポートに外部のコンポーネントを接続することで、対話システムからコマンドを出すことができるようになります。
例えば、以下のスクリプトに示されるコンポーネントを接続してみましょう。
ConsoleOut.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time import OpenRTM_aist import RTC consoleout_spec = ["implementation_id", "ConsoleOut", "type_name", "ConsoleOut", "description", "Console output component", "version", "1.0", "vendor", "sample", "category", "example", "activity_type", "DataFlowComponent", "max_instance", "10", "language", "Python", "lang_type", "script", ""] class ConsoleOut(OpenRTM_aist.DataFlowComponentBase): def __init__(self, manager): OpenRTM_aist.DataFlowComponentBase.__init__(self, manager) self._data = RTC.TimedString(RTC.Time(0,0),"") self._inport = OpenRTM_aist.InPort("in", self._data) def onInitialize(self): # Set OutPort buffer self.registerInPort("in", self._inport) return RTC.RTC_OK def onExecute(self, ec_id): while self._inport.isNew(): data = self._inport.read() print "command : %s" % data.data time.sleep(0.1) return RTC.RTC_OK def MyModuleInit(manager): profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec) manager.registerFactory(profile, ConsoleOut, OpenRTM_aist.Delete) comp = manager.createComponent("ConsoleOut") def main(): mgr = OpenRTM_aist.Manager.init(sys.argv) mgr.setModuleInitProc(MyModuleInit) mgr.activateManager() mgr.runManager() if __name__ == "__main__": main()
このコンポーネントは受け取ったコマンドを端末に表示します。マイクに「こんにちは」「さようなら」と発話することで、音声による応答があると同時に、スクリプトに追加したコマンドが表示されるか確認して下さい。
対話マネージャへのスクリプトを変更することにより、応答メッセージの追加はもちろん、任意のデータタイプのポートを作成し情報を送出できます。この機能を用いることで、例えば外部の車輪型機構コントローラに接続し、「前進」「後退」などの台詞でコントロールするといったことが実現できます。
外部への接続のより具体的な例は「 ワールドシミュレータの使い方 」を参照してください。
音声認識文法の作成方法¶
はじめに¶
音声認識文法は、音声認識器に与える認識可能な文法(単語の構造)を定義し ます。
OpenHRIのJulius音声認識コンポーネントは、W3C-SRGS形式を使用して音声認識 文法を定義します。
ここでは、W3C-SRGS形式の音声認識文法について解説するとともにOpenHRIで用 意している文法作成用のツールについて説明します。
W3C-SRGS音声認識文法¶
W3C-SRGS(Speech Recognition Grammar Specification)は音声認識文法を定義 する規格の1つです。使用するXML形式のタグを以下に示します。
タグ¶
- lexicon
- W3C-PLS辞書(次のセクション)のURIを定義します。 任意。
- rule
- IDによって区別された各文法を定義します。 IDは音声認識文法の相互参照や、Julius音声認識コンポーネントによって認識されるアクティブな文法を 切り換えるのに利用します。
- item
- 認識される単語や文を定義します。repeatプロパティで繰り替えされる回数を指定できます。
- one-of
- 子項目で定義される文法がすべて許容できることを示します。
- ruleref
- uriで指定される文法を参照します。
例¶
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="jp"
version="1.0" mode="voice" root="main">
<lexicon uri="sample-lex-jp.xml"/>
<rule id="main">
<one-of>
<item><ruleref uri="#greet" /></item>
<item><ruleref uri="#command" /></item>
</one-of>
</rule>
<rule id="greet">
<one-of>
<item>おはよう</item>
<item>こんにちは</item>
<item>こんばんは</item>
<item>さようなら</item>
</one-of>
</rule>
<rule id="command">
<item repeat="0-1">その</item>
<one-of>
<item>りんご</item>
<item>ケーキ</item>
<item>リモコン</item>
</one-of>
<item>を</item>
<one-of>
<item>取って</item>
<item>渡して</item>
</one-of>
<item repeat="0-1">ください</item>
</rule>
</grammar>
W3C-PLS音声認識辞書¶
W3C-PLS(Pronunciation Lexicon Specification)は音声認識辞書を定義する規格の1つです。 次のタグからなるXMLフォーマットを使用します。
タグ¶
- lexeme
- 表記と発音のセットを定義します。
- grapheme
- 単語の表記を定義します。
- phoneme
- 単語の発音を定義します。
例¶
<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
alphabet="x-KANA" xml:lang="jp">
<lexeme>
<grapheme>こんにちは</grapheme>
<phoneme>{{x-KANA|こんにちわ}}</phoneme>
</lexeme>
<lexeme>
<grapheme>リモコン</grapheme>
<phoneme>{{x-KANA|りもこん}}</phoneme>
</lexeme>
<lexeme>
<grapheme>ケーキ</grapheme>
<phoneme>{{x-KANA|けーき}}</phoneme>
</lexeme>
<lexeme>
<grapheme>さようなら</grapheme>
<phoneme>{{x-KANA|さよーなら}}</phoneme>
</lexeme>
<lexeme>
<grapheme>取って</grapheme>
<phoneme>{{x-KANA|とって}}</phoneme>
</lexeme>
<lexeme>
<grapheme>こんばんは</grapheme>
<phoneme>{{x-KANA|こんばんわ}}</phoneme>
</lexeme>
<lexeme>
<grapheme>りんご</grapheme>
<phoneme>{{x-KANA|りんご}}</phoneme>
</lexeme>
<lexeme>
<grapheme>を</grapheme>
<phoneme>{{x-KANA|を}}</phoneme>
</lexeme>
<lexeme>
<grapheme>ください</grapheme>
<phoneme>{{x-KANA|ください}}</phoneme>
</lexeme>
<lexeme>
<grapheme>渡して</grapheme>
<phoneme>{{x-KANA|わたして}}</phoneme>
</lexeme>
<lexeme>
<grapheme>その</grapheme>
<phoneme>{{x-KANA|その}}</phoneme>
</lexeme>
<lexeme>
<grapheme>おはよう</grapheme>
<phoneme>{{x-KANA|おはよー}}</phoneme>
</lexeme>
</lexicon>
ツール¶
検証ツール¶
“validatesrgs”はW3C-SRGS形式の文法を検証することができるツールです。
検証ツールは以下のコマンドで実行できます。:
$ validatesrgs [grammarfile]
文法が正しい形式で書かれていれば以下のようなメッセージが出力されます。:
$ validatesrgs sample-en.grxml
Validating SRGS file sample-en.grxml...
SRGS file is valid.
Validating PLS file sample-lex-en.xml...
PLS file is valid.
文法の形式が正しくないとき、以下のようなエラーメッセージが出力されます。:
$ validatesrgs sample-invalid.grxml
Validating SRGS file sample-invalid.grxml...
[error] Invalid SRGS file.
Element '{http://www.w3.org/2001/06/grammar}one-of': Missing child element(s). Expected is ( {http://www.w3.org/2001/06/grammar}item )., line 12
視覚化ツール¶
OpenHRIは、W3C-SRGS形式の文法を検証するより強力なツールを用意しています。 “juliustographviz”は、音声認識文法をグラフ表示させて正しさをチェックするツールです。
以下のコマンドでグラフ描画処理を行います。:
$ srgstojulius sample-jp.grxml | juliustographviz | dot -Txlib
以下のような画像が出力されます。:
単語辞書生成ツール¶
W3C-SRGS音声認識文法の作成が終わったら、W3C-PLS辞書を用意しなければならないことがあります (音声認識文法の中に特殊な読み方をする単語があった場合、必要になります)。
OpenHRIは、W3C-SRGS文法からW3C-PLS辞書を自動的に生成するツールを用意しています。
“srgstopls”ツールは以下のコマンドで実行できます。:
$ srgstopls sample-jp.grxml > sample-lex-jp.xml
このツールは現在、英語読み(julius-voxforge辞書を使用)と日本語読み(julius-runkit辞書を使用)をサポートしています。
Note
辞書に含まれない単語は出力XMLファイルの該当個所が空欄になります。出力されたXMLファイルは必ずチェックし、空欄箇所には手動で単語を登録してください。
対話マネージャのスクリプト書式¶
はじめに¶
対話マネージャは対話機能を管理する機能を持ち、対話システムの中核となる部分です。
OpenHRIは2つの対話マネージャを用意しており、目的に応じて選択することができます(独自の対話マネージャを書くこともできます)。
SEAT: シンプルな対話マネージャ¶
SEAT (Speech Event Action Transfer) はシンプルな状態遷移モデルに基づく対話マネージャです。 以下のXMLタグを使用してシステムの動作を定義することができます。
タグ¶
アダプタの定義
SEATには、名前と通信方法(RTMとソケット)を対応付けるアダプタ機構を持っています。 アダプタ機構は、通信方法の差異を隠蔽化することで、システムのハードウェア構成の変化に適応し、対話ロジックの再利用性を向上させます。
- general
アダプタ定義部を示します。
- agent
名前と通信方法の対応を示します。 “type”属性は”rtcin”、”rtcout”、”socket”を取ることができます。 タイプが”rtcin”か”rtcout”と定義されたとき、”datatype”属性を定義できます(データ型に関しては、RTMの仕様を参照してください)。 タイプが”socket”と定義されたとき、”host” 、”port” 属性を定義できます。
スクリプト定義
- state
状態遷移モデルで状態を示します。
- rule
キーワードとコマンドの組を定義します。
- key
キーワードを示します。
- command
キーワードと入力が一致したとき実行されるコマンドを示します。
- statetransition
状態遷移を示します。
例¶
<?xml version="1.0" encoding="UTF-8"?>
<seatml>
<general name="sample">
<agent name="speechin" type="rtcin" datatype="TimedString" />
<agent name="speechout" type="rtcout" datatype="TimedString" />
</general>
<state name="OPEN">
<rule>
<key>こんにちは</key>
<command host="speechout">こんにちは</command>
</rule>
<rule>
<key>こんばんは</key>
<command host="speechout">こんばんは</command>
</rule>
<rule>
<key>バイバイ</key>
<command host="speechout">バイバイ</command>
<statetransition>CLOSE</statetransition>
</rule>
</state>
<state name="CLOSE">
<rule>
<key>こんにちは</key>
<command host="speechout">はい。なんでしょう。</command>
<statetransition>OPEN</statetransition>
</rule>
<rule>
<key>こんばんは</key>
<command host="speechout">休憩中です</command>
</rule>
<rule>
<key>バイバイ</key>
<command host="speechout">休憩中です</command>
</rule>
</state>
</seatml>
検証ツール¶
“validateseatml”は、SEATML形式のスクリプトの検証を行うツールです。
検証ツールは以下のコマンドで実行できます。:
$ validateseatml [scriptfile]
スクリプトが正しい形式で書かれていれば以下のようなメッセージが出力されます。:
$ validateseatml sample-jp.seatml
validating script file sample-jp.seatml...
script file is valid.
スクリプトの形式が正しくないとき、以下のようなエラーメッセージが出力されます。:
$ validateseatml sample-invalid.seatml
validating script file sample-invalid.seatml...
[error] invalid script file.
Element 'transition': This element is not expected. Expected is one of ( command, statetransition )., line 23
視覚化ツール¶
OpenHRIは、SEATMLスクリプトの構造を検証するより強力なツールを用意しています。 “seatmltographviz”は、スクリプトをグラフ表示させて構造をチェックするツールです。
以下のコマンドでグラフ描画処理を行います。:
$ seatmltographviz sample-jp.seatml | dot -Txlib
以下のような画像が出力されます。:
Soar: General Artificial Intelligence¶
Soar ( http://sitemaker.umich.edu/soar/home ) はプロダクションシステムベースのAIで最も人気がある実装の1つです。
OpenHRIは、RTMベースのシステムにコンポーネントとしてSoarを埋め込むためのラッパーを提供します。
More documents T.B.D
ワールドシミュレータの使い方¶
OpenHRIでは、実ロボットがなくてもロボットとのインタラクション機能をテストすることができるワールドシミュレータを用意しています。
この章では、ワールドシミュレータの使い方について説明します。
インストール¶
Windowsへのインストール¶
- OpenHRIWorldsパッケージのインストール
インストーラを以下のURLよりダウンロード・実行してください。
http://openhri.net/getinstaller.php
インストール可能なパッケージが順次表示されますので、「OpenHRIWorlds」パッケージを選択します。
- OpenHRPSDKのインストール
以下のページの一番下から「OpenHRP SDK Windows版」をダウンロードしてインストールしてください。
Ubuntuへのインストール¶
Ubuntuには現在対応していません(開発中です)。
BlocksWorldシミュレータ¶
BlocksWorldシミュレータは、三菱重工PA10アームのモデルを使ってブロックを操作するワールドシミュレータです。
起動方法¶
- OpenHRPの起動
エクスプローラを開き「C:\Program Files (x86)\OpenHRPSDK\GrxUI」フォルダの中にある「GrxUI.exe」を起動します。
Note
今後のためにデスクトップにショートカットなどを作っておくとよいでしょう。
- BlocksWorldの起動
「スタートメニュー > OpenHRI > worlds」から「BlocksWorld」を選択します。
OpenHRPの画面上にPA10アームと複数のブロックが表示され、ロボットがテスト動作「一つの箱を取って置く」をすることを確認してください。
Note
BlocksWorldがうまく起動しない場合の対処法
BlocksWorldが起動に失敗しロボットがテスト動作をしない場合があります(原因は調査中です)。その場合は、以下の手順を試してみてください。
- OpenHRP付属のサンプルプロジェクトをロードする。
メニューバーの「GrxUI > プロジェクトの読み込み」を選択し、「C:\Program Files (x86)\OpenHRPSDK\share\OpenHRP-3.1\sample\project」の中から「PA10Sample」をロードしてください。
- OpenHRPのシミュレーションを一度実行する。
シミュレーションの開始ボタンを押してシミュレーションを開始してください(すぐに終了しても構いません)。
- OpenHRPのビューをクリアする。
メニューバーの「GrxUI > 新規プロジェクト」を選択し、ビュー画面をクリアしてください。
- BlocksWorldを実行する。
BlocksWorldコンポーネントを起動して動作を確認してください。
コンポーネントの機能¶
BlocksWorldコンポーネントは、commandポートから入力を受け付けます。
下記のテキストコマンドを与えることでロボットが動作します。
- grasp
- ハンドの下にあるものを拾います。
- release
- ハンドで持ったものを放します。
- moveHandToBox [name]
- [name]で指定されたブロックの上にハンドを移動します。「box1」「box2」「box3」が指定できます。
- moveHandXY [X] [Y]
- 現在の位置から[X][Y]で指定された距離、ハンドを移動します。
テストスクリプト¶
対話によってPA10アームを操作するスクリプトの例を示します。
- 音声認識文法
<?xml version="1.0" encoding="UTF-8" ?> <grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd" xml:lang="jp" version="1.0" mode="voice" root="command"> <rule id="command"> <one-of> <item> <item repeat="0-1">少し</item> <one-of> <item>前</item> <item>後</item> <item>左</item> <item>右</item> </one-of> </item> <item> <one-of> <item>赤</item> <item>青</item> <item>緑</item> </one-of> <item repeat="0-1">の箱</item> </item> <item>取って</item> <item>置いて</item> </one-of> </rule> </grammar>
- 対話スクリプト
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="command" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>取って</key> <command host="command">grasp</command> </rule> <rule> <key>置いて</key> <command host="command">release</command> </rule> <rule> <key>緑[の箱]</key> <command host="command">moveHandToBox box1</command> </rule> <rule> <key>赤[の箱]</key> <command host="command">moveHandToBox box2</command> </rule> <rule> <key>青[の箱]</key> <command host="command">moveHandToBox box3</command> </rule> <rule> <key>前</key> <command host="command">moveHandXY 0.1 0.0</command> </rule> <rule> <key>後</key> <command host="command">moveHandXY -0.1 0.0</command> </rule> <rule> <key>左</key> <command host="command">moveHandXY 0.0 0.1</command> </rule> <rule> <key>右</key> <command host="command">moveHandXY 0.0 -0.1</command> </rule> <rule> <key>少し前</key> <command host="command">moveHandXY 0.05 0.0</command> </rule> <rule> <key>少し後</key> <command host="command">moveHandXY -0.05 0.0</command> </rule> <rule> <key>少し左</key> <command host="command">moveHandXY 0.0 0.05</command> </rule> <rule> <key>少し右</key> <command host="command">moveHandXY 0.0 -0.05</command> </rule> </state> </seatml>
それぞれのファイルをJuliusコンポーネントとSEATコンポーネントに読み込ませ、SEATコンポーネントの「command」ポートとBlocksWorldコンポーネントの「command」ポートを接続してください。
音響フィルタの使い方¶
音声認識器の認識精度は入力音声の品質に強く影響されます。音声認識の結果 は後段の対話システムの挙動にも影響を与えるため、雑音の少ない環境下では 動いていた対話システムが、別の環境では思ったように動かないこともありま す。
ロボットは雑音環境下に置かれることが多く、一般的な音声対話システムより も多くの考慮が必要になります。
OpenHRIでは、これら雑音の影響を低減するための音響フィルタコンポーネント をいくつか用意しています。この章では「音響エコー除去」を例にして、それ ら音響フィルタコンポーネントの使い方について解説します。
音響エコー除去¶
音響エコーとは、スピーカから出力された音声をマイクロフォンが拾ってしま うことで発生するループのことです。音響エコーが発生すると、正確な音声認 識が難しくなります。
OpenHRIでは、音響エコーの問題を軽減するため2種類ののコンポーネントを用 意しています。それぞれ長所・短所がありますので用途に応じて使い分けてく ださい。
エコーサプレッサ¶
音声出力コンポーネントからの出力を検出し、それと同じタイミングで音声入 力を減衰させることで、スピーカからマイクへの収音を防ぐコンポーネントで す。以下の特徴があります。
- 長所
- 高速で処理できる。入力音声の変形が少ない。
- 短所
- 音声出力中は音声入力できないため、常に音声出力している場合などは使用が難しい。
エコーキャンセラ¶
音声出力コンポーネントからの出力信号よりエコー成分を推測して、マイクか ら収音した信号から推測したエコー成分を除去するコンポーネントです。以下 の特徴があります。
- 長所
- 音声出力中でも音声入力できる。
- 短所
- 適応フィルタ係数を毎回更新するため処理が重い。入力音声を加工するため、 その影響による変形が認識に悪影響を及ぼす場合がある。
使い方¶
以下に Step4: 対話システムを作ろう にて作成した対話システムにエコーサプレッサを接続する例を示します。
コンポーネントの接続¶
AudioInputの出力ポートとJuliusRTCの入力ポートのリンクを削除し、以下のリンクを接続します。
- AudioInputの出力ポートとEchoSuppressorの入力ポート「from_input」
- AudioOutputの出力ポートとEchoSuppressorの入力ポート「from_output」
- EchoSuppressorの出力ポートとJuliusRTCの入力ポート
リンクを作成すると、以下のスクリーンショットのようになります。

動作確認¶
All Activateボタンで全コンポーネントをアクティブ状態に遷移させます。ス ピーカとマイクを近づけて発声し、返事が連続しないことを確認しましょう。
音源定位とビームフォーミング¶
音源定位とは¶
音源の位置(角度)を測定します。
複数のマイクを利用し、各マイクへの音声到達時間のずれとマイク間の距離から音源の位置(角度)を計算します。
OpenHRIAudioでは、DSArrayコンポーネントで音源定位を行います。
ビームフォーミングとは¶
指定角度の音声信号を取り出します。
音源定位と同じく複数のマイクを利用し、指定角度での各マイクへの音声到達時間のずれを計算して補正します。
OpenHRIAudioでは、BeamFormingコンポーネントでビームフォーミングを行います。
使い方¶
Kinectをアレイマイクとして使用した方法¶
kinectはマイクロソフトのHPからKinectSDKをインストールして使用できるようになります。(Windows7以降)
コンポーネントは
- PortAudioInput
- PortAudioOutput
- DSArray
- BeamForming
の4つを使用します。
また、マイク配置の設定ファイル”micset.csv”が必要になります。
OpenHRIAudioのインストールファイルには、Kinectのマイク配置設定ファイル”micset.csv”が含まれています。
コンポーネントの接続
- PortAudioInputの出力ポートにDSArrayの入力ポート、BeamFormingの入力ポートの2つのリンクを接続
- DSArrayの出力ポートに BeamFormingの入力ポートを接続
- BeamFormingの出力ポートにPortAudioOutputの入力ポートを接続
リンクを作成すると、以下のスクリーンショットのようになります。
![]()
- AudioInput、DSArray、BeamFormingのマイク数を”4”に設定してください。
- サンプリングレート、ビット深度はすべて同じ値にしてください。(初期設定16kHz,16bit)
BeamFormingコンポーネントにはパラメータ”Mode”があります。
- Const
- パラメータ”ConstAngle”で指定した角度からの音声入力を強調します。一定の角度からの音声を取り出す場合に使用します。
- Variable
- 入力ポート”angle”の角度からの音声入力(DSArrayコンポーネントで音源定位した角度)を強調します。音源が移動した場合、強調角度が移動先に追従します。
サンプル¶
Contents:
旗上げゲーム¶
「旗上げゲーム」は左右の手に持った赤と白の旗を指示に応じてあげたり下げ たりするゲームです。
ここでは、SEATの状態遷移モデル作成の例としてとりあげます。
音声認識文法を作成する¶
旗上げゲームの文法モデルを定義しましょう。旗上げゲームの入力は「赤あげ て」「赤あげない」「赤さげて」「赤さげない」「白あげて」「白あげない」 「白さげて」「白さげない」のいずれかです。one-ofタグを使うことで各入力 を記述しても良いのですが、ここではよりコンパクトな文法を定義してみましょ う。
flaggame-ja.grxml
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="jp"
version="1.0" mode="voice" root="command">
<rule id="command">
<one-of>
<item>赤</item>
<item>白</item>
</one-of>
<one-of>
<item>あげて</item>
<item>あげない</item>
<item>さげて</item>
<item>さげない</item>
</one-of>
</rule>
</grammar>
上記の文法モデルは、「赤」または「白」の次に、「あげて」「あげない」 「さげて」「さげない」のいずれかが続くという文法を定義しています。
グラフ表現によって文法の構造を確認してみましょう。:
$ srgstojulius flaggame-ja.grxml | juliustographviz | dot -Txlib

対話スクリプトを作成する¶
旗上げゲームでは、両手に持った旗を上げたり下げたりしますが、一度上げた 旗はもう一度上げることができません(ロボットにこれをやらせてしまうと腕 が一回転してしまいます)。
ここでは旗上げゲームを「状態遷移モデル」を使って記述してみます。
「状態遷移モデル」では、システムの「状態」を定義した上で、その状態の間 の「遷移」と「遷移条件」を記述することでシステムの振る舞いを定義します。
旗上げゲームでは、システムに以下の4つの状態があると考えられるでしょう:
- 両方下げる
- 左を上げる
- 右を上げる
- 両方上げる
旗上げゲームは両手を下げた状態で始まります。ここで、左に赤い旗、右に白 い旗を持っていたと考えると、「赤あげて」はシステムの状態を左を上げた状 態に遷移させます。
システムが左を上げた状態で「白下げて」と命令するとシステムの状態は「両 方上げる」になります。
システムが両方上げた状態で「赤あげて」と命令してもそれ以上の状態遷移は 起こりません。
SEATは状態遷移モデルをXML形式で記述することができます。上記で説明した旗 上げゲームは以下のように記述できます。
flaggame-ja.seatml
<?xml version="1.0" encoding="UTF-8"?>
<seatml>
<general name="flaggame">
<agent name="speechin" type="rtcin" datatype="TimedString" />
<agent name="speechout" type="rtcout" datatype="TimedString" />
</general>
<state name="both_down">
<rule>
<key>赤あげて</key>
<command host="speechout">はい</command>
<statetransition>left_up</statetransition>
</rule>
<rule>
<key>白あげて</key>
<command host="speechout">はい</command>
<statetransition>right_up</statetransition>
</rule>
</state>
<state name="both_up">
<rule>
<key>赤さげて</key>
<command host="speechout">はい</command>
<statetransition>right_up</statetransition>
</rule>
<rule>
<key>白さげて</key>
<command host="speechout">はい</command>
<statetransition>left_up</statetransition>
</rule>
</state>
<state name="left_up">
<rule>
<key>赤さげて</key>
<command host="speechout">はい</command>
<statetransition>both_down</statetransition>
</rule>
<rule>
<key>白あげて</key>
<command host="speechout">はい</command>
<statetransition>both_up</statetransition>
</rule>
</state>
<state name="right_up">
<rule>
<key>赤あげて</key>
<command host="speechout">はい</command>
<statetransition>both_up</statetransition>
</rule>
<rule>
<key>白さげて</key>
<command host="speechout">はい</command>
<statetransition>both_down</statetransition>
</rule>
</state>
</seatml>
グラフ表現によって状態遷移モデルの構造を確認してみましょう。:
$ seatmltographviz flaggame-ja.seatml | dot -Txlib

コンポーネントを起動し接続する¶
audioinput コンポーネント、audiooutputコンポーネント、juliusコンポーネ ント、openjtalkコンポーネント、SEATコンポーネントをそれぞれ起動します。
$ pulseaudioinput (portaudioinput)$ pulseaudioutput (portaudiooutput)$ juliusrtc flaggame-ja.grxml$ seat flaggame-ja.seatml
RT-SystemEditorを使って以下のリンクを作成してください:
- audioinput -> julius
- julius (result) -> SEAT
- SEAT -> openjtalk
- openjtalk (result) -> audiooutput
すべてのコンポーネントをアクティベートして動作を確認してください。
SEATコンポーネントを起動したコンソールを見ると、システムが現在どの状態 にいるかが表示されます。どの状態でどの遷移条件が有効になったのかを意識 しながらコマンドを発話してください。
開発者向け情報¶
OpenHRIは主にgithubとUbuntuを使って開発されています。
最新のソースコード(機能が不安定だったりバグがある可能性があります)をテストしたい場合、 以下の手順に従ってコンポーネントをコンパイルしてください。
OpenHRIAudio¶
音響コンポーネント群(OpenHRIAudio)はconfigureスクリプトを使ってパッケージ化されたC++プログラムです。
以下の手順でコンパイルしてインストールすることができます。
依存ライブラリをインストールする:
$ sudo apt-get install autotools-dev pkg-config omniidl4 uuid-dev libomniorb4-dev libspeex-dev libspeexdsp-dev libresample1-dev openrtm-aist openrtm-aist-dev portaudio19-dev libpulse-dev
最新のソースコードをチェックアウトする:
$ git clone https://yosuke@github.com/yosuke/OpenHRIAudio.git
ソースコードがあるフォルダに移動してconfigureスクリプトをセットアップする:
$ cd OpenHRIAudio
$ ./autogen.sh
configureスクリプトを起動してプロジェクトをコンパイルする:
$ ./configure
$ make
コンポーネントをインストールする:
$ sudo make install
$ sudo ldconfig
OpenHRIVoice¶
音声コンポーネント群(OpenHRIVoice)はsetupスクリプトを使ってパッケージ化されたPythonプログラムです。
以下の手順でコンパイルしてインストールすることができます。
依存ライブラリをインストールする:
$ sudo apt-get install python-beautifulsoup python-lxml python-matplotlib openrtm-aist-python
最新のソースコードをチェックアウトする:
$ git clone https://yosuke@github.com/yosuke/OpenHRIVoice.git
ソースコードがあるフォルダに移動してコンポーネントをインストールする:
$ cd OpenHRIVoice
$ sudo python setup.py install
ライセンス¶
OpenHRIのライセンスは、Eclipse Public License (EPL)です。
http://www.eclipse.org/legal/epl-v10.html
EPLは、コードの改変や再配布、営利利用を許可するオープンソースライセンス ですが、場合によっては改変内容をライセンス元に開示する必要があります。
OpenHRIが内部で用いているJuliusやOpen JTalkなどのそれぞれのソフトウェア については、各自のライセンスに従います。
Contents:
Introduction¶
OpenHRI is a set of components required to realize the communication function of the robot, such as speech recognition, speech synthesis, and dialog managements.
OpenHRI gives unified interface for open source softwares available for public.
Tutorial¶
Contents:
Step1: Install¶
Here, we explain installation procedure for each platforms:
Installation procedure for Windows¶
Download and execute the installer from following URL.
http://openhri.net/getinstaller.php
When the installer is executed, the installation wizard will start. Each package will be automatically downloaded and installed by the installer.
The case of OpenHRIAudio is shown as follows. Install OpenHRIVoice and SEATSAT similarly.
- Select “English” and push the [OK] button.
- The wizard starts. Push [Next (N)].
- The licensing policy is displayed. Push [Agree (A)].
- The component selection screen is displayed. Please check everything and push [Next (N)].
- Select the installation location. Default is installed in “C:Program FilesOpenHRIAudio”.
- The installation is being executed. Push [Next (N)] when the installation is completed.
- The installation was completed. Push [Finish (F)] button.
After you have installed all packages (OpenHRIAudio, OpenHRIVoice and SEATSAT), let’s proceed to confirm the operation of the components.
Proceed to Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
Installation procedure for Ubuntu¶
Command-line based installation (recommended)¶
Enter following commands on the terminal:
$ sudo apt-add-repository ppa:openhri/ppa
$ sudo apt-get update
$ sudo apt-get install openhriaudio openhrivoice seatsat
This is it!
Proceed to Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
GUI based installation¶
OpenHRI software repository can be registered using the Synaptic Package Manager.
Open the “Synaptic Package Manager” from “System” > “Systems Management”. (Password required)
Follow “Setting (S)” > “Open Repository (R)” > “Other Software” (or “Third-party Software”) tab.
Click “APT line:” and add the following address:
http://ppa.launchpad.net/openhri/ppa/ubuntu lucid main deb
Click “Add source (A)”.
Note
this address is for ubuntu 10. 04. OpenHRI binary packages currently only support ubuntu 10.04.
Click “Reload” to download the package information.
Repository registration is finished. Let’s install OpenHRI components.
Select the items by using the quick search box. Enter “openhriaudio”, “openhrivoice”, “seatsat” on the search box. Use the right-click menu to install.
Quick search box
Right click the left check box and choose “install”.
Click the “apply” button to begin the installation.
Component installation now finished. Let’s check the behavior of the component.
Proceed to Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
If you have already done with the procedure, please proceed to Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
Step2: Basic Usage of RT-SystemEditor and Testing Audio Components¶
In this step, we will directly connect the audio input and the audio output component and verify that the components are working properly.
Preparation¶
- Download and install eclipse with RT-SystemEditor.
- On Ubuntu, please refer to the instruction on this page: http://openrtm.org/openrtm/en/node/945
- On Windows, please download and install the OpenRTM-aist-Python package provided from this page: http://openrtm.org/openrtm/en/node/949#toc3
- Prepare a microphone and a speaker (earphone and headphone) connect to PC.
- Create rtc.conf file.
Create a configuration file “rtc.conf” and save to working directory. Content of rtc.conf is as follows
corba.nameservers: localhost:9876 naming.formats: %n.rtc logger.file_name:stdoutOn Windows, rtc.conf file is alread allocated by the installer.
- Launch the name server.
Start the name server with port number as specified in rtc.conf file. (In the above example 9876)
$ rtm-naming 9876![]()
- Launch eclipse with RT-SystemEditor installed.
Basic usage of the RT-SystemEditor¶
In this section, we describes the basic usage of the RT-SystemEditor and test audio components.
Launch AudioInput and AudioOutput components.
Warning
If you are using ubuntu 9.10 or later, please use PulseAudioInput and PulseAudioOutput components. If you are using version older than 9.10, please use PortAudioInput and PortAudioOutput components.
- ubuntu9.10 or later: enter the following commands on each terminal.
$ pulseaudioinput
$ pulseaudiooutput
- older version: enter the following commands on each terminal.
$ portaudioinput
$ portaudiooutput
Open the eclipse RT-SystemEditor perspective.
Select “Add name servers” button and register the name servers specified by the rtc.conf file.
(In above example “localhost:9876”)
Click the icon on the left to open the new editor screen.
From the name service views (left panel) drag and drop the AudioInput (and AudioOutput) component to the editor screen.
Connected the dataport between the components.
Click the connector part of the data port.
Drag to the other data port.
When you drop the link, a connection settings dialog will appear. No configuration change is required.
Press OK (connector changes to green color)
Activate the component and check the operation¶
Activate all components.
Press “All Activate” button.
AudioInput and AudioOutput activate and change from blue to green.
Verify the operation.
Verify that sound input entered from the microphone is played from speakers.
In this step we have learned basic usage of the RT System Editor through testing the audio components.
Proceed to Step3: Testing Voice Synthesis Component.
Step3: Testing Voice Synthesis Component¶
Here we will learn how to use text-to-speech component.
Preparation¶
- Preparation of test components
Test component will output a text data in some period. Please create a test program as follows.
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time import OpenRTM_aist import RTC consolein_spec = ["implementation_id", "ConsoleIn", "type_name", "ConsoleIn", "description", "Console input component", "version", "1.0", "vendor", "sample", "category", "example", "activity_type", "DataFlowComponent", "max_instance", "10", "language", "Python", "lang_type", "script", ""] class ConsoleIn(OpenRTM_aist.DataFlowComponentBase): def __init__(self, manager): OpenRTM_aist.DataFlowComponentBase.__init__(self, manager) self._data = RTC.TimedString(RTC.Time(0,0),"") self._outport = OpenRTM_aist.OutPort("out", self._data) def onInitialize(self): self.registerOutPort("out", self._outport) return RTC.RTC_OK def onExecute(self, ec_id): self._data.data = "testing" OpenRTM_aist.setTimestamp(self._data) self._outport.write() time.sleep(5) return RTC.RTC_OK def MyModuleInit(manager): profile = OpenRTM_aist.Properties(defaults_str=consolein_spec) manager.registerFactory(profile, ConsoleIn, OpenRTM_aist.Delete) comp = manager.createComponent("ConsoleIn") def main(): mgr = OpenRTM_aist.Manager.init(sys.argv) mgr.setModuleInitProc(MyModuleInit) mgr.activateManager() mgr.runManager() if __name__ == "__main__": main()We will call this component “ConsoleIn component” hereafter..
- Prepare the rtc.conf
You may copy the setting used in Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
Test procedures¶
- Start the ConsoleIn and Festival components.
- Open two terminals and enter following commands respectively
% python ConsoleIn.py% festivalrtcMake sure you start naming service view component is displayed.
![]()
- Place the ConsoleIn and Festival component to RT System Editor.
Drag and drop the components to the editor panel.
![]()
- Remove the links between AudioInput-AudioOutput.
Select the link and choose “Delete” from the right-click menu.
![]()
- Connect the ConsoleIn, Festival, and AudioOutput, respectively.
- Connect ConsoleIn output port and Festival input port.
- Connect the Festival “result” output port and AudioOutput input port.
(Please be careful not to connect to the different port. )
![]()
- Activate and verify the behavior.
Press “All Activate” button to activate all the components.
Verify the text you set the ConsoleIn component is synthesized as audio.
In the next step, we will create a complete dialog system by connecting the speech recognition component.
Proceed to Step4: Creating Dialog System.
Step4: Creating Dialog System¶
Let’s create a simple dialog system by combining speech recognition component and the dialog manager component.
Preparation¶
- Preparation of the speech recognition components
We have to provide a speech recognition grammar to run the speech recognition component.
Create the following text data.
sample-en.xml
<?xml version="1.0" encoding="UTF-8" ?> <grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd" xml:lang="en" version="1.0" mode="voice" root="command"> <rule id="command"> <one-of> <item>hello</item> <item>bye</item> </one-of> </rule> </grammar>
- Dialog Manager component preparation
Create the following text data.
sample-en.seatml
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="speechout" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>hello</key> <command host="speechout">hello</command> </rule> <rule> <key>bye</key> <command host="speechout">bye bye</command> </rule> </state> </seatml>
- Prepare the setting file rtc.conf
You may copy the setting used in Step2: Basic Usage of RT-SystemEditor and Testing Audio Components.
Test procedures¶
- Start the SEAT and Julius components.
$ juliusrtc sample-en.xml$ seat sample-en.seatmlMake sure the component is displayed in Eclipse name service view.
![]()
- Drag and drop SEAT and Julius components to the editor panel.
- Connect between the components.
- Remove the link between ConsoleIn component and Festival component.
- Create a link between AudioInput output port and Julius input port.
- Create a link between Julius “result” output port and SEAT input port.
- Create a link between SEAT output port and Festival input port.
Make sure that everything is connected!
![]()
- Activate and verify the behavior.
Press “All Activate” button.
Check to receive the response by speaking “Hello” or “Goodbye” in front of the microphone.
Note
If it does not work:
Check the following points.
- Check environmental noises
- Check whether you have the background or ambient noise. If you want to recognize the noisy environments, consider using headset microphone or directional microphones.
- Adjust audio input volume
- Speech recognition will show low performance when the audio volume is too large or too small (if you see the warnings such as “Warning: strip to...” in the terminal where you have launched julius component, audio volume may not appropriate). Adjust size of volume by looking at the volume meter.
Proceed to Step5: Extending the Dialog System.
Step5: Extending the Dialog System¶
Here, we connect our dialog system to the external components.
Edit the script given to the dialog manager as follows.
sample-en2.seatml
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="speechout" type="rtcout" datatype="TimedString" /> <agent name="commandout" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>hello</key> <command host="speechout">hello</command> <command host="commandout">command-hello</command> </rule> <rule> <key>bye</key> <command host="speechout">bye bye</command> <command host="commandout">command-bye</command> </rule> </state> </seatml>
Stop the SEAT components (by entering Ctrl + C in the terminal) and start again with the edited script.
% seat sample-en2.seatml
Dialog manager starts with one more output ports.
You can give command to external components by connecting to this port.
For example, we can connect the components shown in the following script.
ConsoleOut.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time import OpenRTM_aist import RTC consoleout_spec = ["implementation_id", "ConsoleOut", "type_name", "ConsoleOut", "description", "Console output component", "version", "1.0", "vendor", "sample", "category", "example", "activity_type", "DataFlowComponent", "max_instance", "10", "language", "Python", "lang_type", "script", ""] class ConsoleOut(OpenRTM_aist.DataFlowComponentBase): def __init__(self, manager): OpenRTM_aist.DataFlowComponentBase.__init__(self, manager) self._data = RTC.TimedString(RTC.Time(0,0),"") self._inport = OpenRTM_aist.InPort("in", self._data) def onInitialize(self): # Set OutPort buffer self.registerInPort("in", self._inport) return RTC.RTC_OK def onExecute(self, ec_id): while self._inport.isNew(): data = self._inport.read() print "command : %s" % data.data time.sleep(0.1) return RTC.RTC_OK def MyModuleInit(manager): profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec) manager.registerFactory(profile, ConsoleOut, OpenRTM_aist.Delete) comp = manager.createComponent("ConsoleOut") def main(): mgr = OpenRTM_aist.Manager.init(sys.argv) mgr.setModuleInitProc(MyModuleInit) mgr.activateManager() mgr.runManager() if __name__ == "__main__": main()
This component shows the command to the terminal. Please check the received commands, by saying “Hello” “Bye” to the microphone.
By editing the script given to the dialog manager, you can create a port you like and send data of any type. By using this feature, for example, you can connect the dialog system to the actual robot to send command “moving forward” or “retreat”.
Working with Speech Recognition Grammar¶
Introduction¶
Speech recognition grammar defines syntactical structure of the words to be recognized.
Julius speech recognition component provided by OpenHRI uses W3C-SRGS format to define the speech recognition grammar.
In this section, we explain the W3C-SRGS format and introduce the tools provided by OpenHRI to help authoring the grammar.
W3C-SRGS Grammar¶
W3C-SRGS (Speech Recognition Grammar Specification) is one of the standard to define the speech recognition grammar. It uses XML format with following tags to
Tags¶
- lexicon
- Indicates URI of W3C-PLS lexicon (see next section). Optional.
- rule
- Indicates set of grammar distinguished by an ID. This will be used to reference the grammar from the other grammar or to switch the active grammar recognized by the Julius speech recognition component.
- item
- Indicates a word or a sentence (space separated words) to be recognized. “repeat” property can be used.
- one-of
- Indicates the child items are all acceptable.
- ruleref
- Import the rule defined by the uri.
Example¶
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en"
version="1.0" mode="voice" root="main">
<lexicon uri="sample-lex-en.xml"/>
<rule id="main">
<one-of>
<item><ruleref uri="#greet" /></item>
<item><ruleref uri="#command" /></item>
</one-of>
</rule>
<rule id="greet">
<one-of>
<item>hello</item>
<item>good afternoon</item>
<item>good evening</item>
<item>good bye</item>
<item>bye</item>
</one-of>
</rule>
<rule id="command">
<one-of>
<item>pick</item>
<item>give me</item>
</one-of>
<item repeat="0-1">the</item>
<one-of>
<item>apple</item>
<item>cake</item>
<item>remote</item>
</one-of>
<item repeat="0-1">please</item>
</rule>
</grammar>
W3C-PLS Lexicon¶
W3C-PLS (Pronunciation Lexicon Specification) is one of the standard to define the speech recognition lexicon. It uses XML format with following tags to
Tags¶
- lexeme
- Set of grapheme and phoneme.
- grapheme
- Indicates how you write the word.
- phoneme
- Indicates how you pronounce the word.
Example¶
<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
alphabet="x-ARPAbet" xml:lang="en">
<lexeme>
<grapheme>me</grapheme>
<phoneme>{{x-ARPAbet|m iy}}</phoneme>
</lexeme>
<lexeme>
<grapheme>good</grapheme>
<phoneme>{{x-ARPAbet|g uh d}}</phoneme>
</lexeme>
<lexeme>
<grapheme>remote</grapheme>
<phoneme>{{x-ARPAbet|r ix m ow t}}</phoneme>
</lexeme>
<lexeme>
<grapheme>apple</grapheme>
<phoneme>{{x-ARPAbet|ae p ax l}}</phoneme>
</lexeme>
<lexeme>
<grapheme>give</grapheme>
<phoneme>{{x-ARPAbet|g ih v}}</phoneme>
</lexeme>
<lexeme>
<grapheme>please</grapheme>
<phoneme>{{x-ARPAbet|p l iy z}}</phoneme>
</lexeme>
<lexeme>
<grapheme>evening</grapheme>
<phoneme>{{x-ARPAbet|iy v n ix ng}}</phoneme>
</lexeme>
<lexeme>
<grapheme>afternoon</grapheme>
<phoneme>{{x-ARPAbet|ae f t er n uw n}}</phoneme>
</lexeme>
<lexeme>
<grapheme>pick</grapheme>
<phoneme>{{x-ARPAbet|p ih k}}</phoneme>
</lexeme>
<lexeme>
<grapheme>cake</grapheme>
<phoneme>{{x-ARPAbet|k ey k}}</phoneme>
</lexeme>
<lexeme>
<grapheme>the</grapheme>
<phoneme>{{x-ARPAbet|dh ax}}</phoneme>
</lexeme>
<lexeme>
<grapheme>bye</grapheme>
<phoneme>{{x-ARPAbet|b ay}}</phoneme>
</lexeme>
<lexeme>
<grapheme>hello</grapheme>
<phoneme>{{x-ARPAbet|hh ax l ow}}</phoneme>
</lexeme>
</lexicon>
Tools¶
Validation tool¶
You can validate your grammar in W3C-SRGS format by using “validatesrgs” tool.
You can use the validation tool by simply entering the following command:
$ validatesrgs [grammarfile]
If the grammar is correct, you will get the following output:
$ validatesrgs sample-en.grxml
Validating SRGS file sample-en.grxml...
SRGS file is valid.
Validating PLS file sample-lex-en.xml...
PLS file is valid.
If the grammar is not correct, you will get error messages for example as follows:
$ validatesrgs sample-invalid.grxml
Validating SRGS file sample-invalid.grxml...
[error] Invalid SRGS file.
Element '{http://www.w3.org/2001/06/grammar}one-of': Missing child element(s). Expected is ( {http://www.w3.org/2001/06/grammar}item )., line 12
Visualization tool¶
OpenHRI has more powerful tool to validate the structure of the W3C-SRGS grammar. “juliustographviz” tool can visualize the grammar in graph to check the correctness.
To draw the graph, enter following command:
$ srgstojulius sample-en.grxml | juliustographviz | dot -Txlib
For example, you will get the following output:
Lexicon generation tool¶
After you have finished writing W3C-SRGS grammar, you sometime have to prepare W3C-PLS lexicon (this process is required when you have designed a grammar which contains words with special readings).
OpenHRI provides a tool to automatically generate W3C-PLS lexicon from the W3C-SRGS grammar.
The “srgstopls” tool can be used as follows:
$ srgstopls sample-en.grxml > sample-lex-en.xml
English lexicon (by using julius-voxforge dictionary) and Japanese lexicon (by using julius-runkit dictionary) are supported by this tool at the moment.
Note
Words not in the dictionary remains blank in output XML file. You should always check the output XML and fill in manually for such words.
Scripting Dialog Manager¶
Introduction¶
Dialog manager is the core part of the dialog system which defines interactive behavior of the system.
OpenHRI provides two dialog manager that you can chose at your preference.
SEAT: Simple Dialog Manager¶
SEAT (Speech Event Action Transfer) is a simple state-transition model based dialog manager. You can define the behavior of the system by using following XML tags.
Tags¶
Adaptor definition
SEAT has an adaptor mechanism which gives mappings between the name and the actual connection method (RTM and socket). The adaptor mechanism abstracts the hardware configuration of the system and assists the reuse of the dialog logic.
- general
This tag is used to indicate the adaptor definition part.
- agent
Map of the name and actual connection method. Attribute “type” can take “rtcin”, “rtcout” or “socket”. When type is defined as “rtcin” or “rtcout”, you can define “datatype” attribute (see RTM’s specification for standard data types). When type is defined as “socket”, you can define “host” and “port” attributes.
Script definition
- state
Indicates a state in state-transition model.
- rule
Defines set of keywords and commands.
- key
Keywords to be matched to the inputs.
- command
Command to be executed when the keyword matches the input.
- statetransition
Transit to different state.
Example¶
<?xml version="1.0" encoding="UTF-8"?>
<seatml>
<general name="sample">
<agent name="speechin" type="rtcin" datatype="TimedString" />
<agent name="speechout" type="rtcout" datatype="TimedString" />
</general>
<state name="OPEN">
<rule>
<key>hello</key>
<command host="speechout">Hello.</command>
</rule>
<rule>
<key>good afternoon</key>
<command host="speechout">Good afternoon.</command>
</rule>
<rule>
<key>good evening</key>
<command host="speechout">Good evening.</command>
</rule>
<rule>
<key>good bye</key>
<command host="speechout">Good bye.</command>
<statetransition>CLOSE</statetransition>
</rule>
</state>
<state name="CLOSE">
<rule>
<key>hello</key>
<command host="speechout">Hello there.</command>
<statetransition>OPEN</statetransition>
</rule>
<rule>
<key>good afternoon</key>
<command host="speechout">I'm not available.</command>
</rule>
<rule>
<key>good evening</key>
<command host="speechout">I'm not available.</command>
</rule>
</state>
</seatml>
Validation tool¶
You can validate your script in SEATML format by using “validateseatml” tool.
You can use the validation tool by simply entering the following command:
$ validateseatml [scriptfile]
If the script is correct, you will get the following output:
$ validateseatml sample-en.seatml
validating script file sample-en.seatml...
script file is valid.
If the script is not correct, you will get error messages for example as follows:
$ validateseatml sample-invalid.seatml
validating script file sample-invalid.seatml...
[error] invalid script file.
Element 'transition': This element is not expected. Expected is one of ( command, statetransition )., line 23
Visualization tool¶
OpenHRI has more powerful tool to validate the structure of the SEATML script. “seatmltographviz” tool can visualize the script in graph to check the correctness.
To draw the graph, enter following command:
$ seatmltographviz sample-en.seatml | dot -Txlib
For example, you will get the following output:
Soar: General Artificial Intelligence¶
Soar ( http://sitemaker.umich.edu/soar/home ) is one of the most popular software to realize production system based AI.
OpenHRI provides a wrapper to embed Soar into RTM based systems as a component.
More documents T.B.D
Usage of World Simulators¶
OpenHRI has a virtual simulation environments to test human robot interaction function without using real robot.
In this chapter we explain the usage of the world simulators.
Install¶
Windows platform¶
- Install OpenHRIWorlds package
Download and run the installer from following URL:
http://openhri.net/getinstaller.php
The installer will show the current available packages. Select “OpenHRIWorlds” package.
- Install OpenHRPSDK
Download and run the “OpenHRP SDK Windows” installer available from following URL:
Ubuntu platform¶
Ubuntu version is currently not available.
BlocksWorld Simulator¶
In BlocksWorld simulator, we can examine the scenario of handling boxes using Mitsubishi Heavy Industries PA10 arm robot.
Running the simulation¶
- Run OpenHRP
Open the explorer and double click the “GrxUI.exe” in “C:\Program Files (x86)\OpenHRPSDK\GrxUI” folder.
Note
We recommend to create a shortcut of GrxUI.exe on the desktop for later use.
- Run BlocksWorld simulator
Choose “BlocksWorld” from “Start Menu > OpenHRI > worlds”.
Please confirm multiple blocks and PA10 arm will show up on the view panel of OpenHRP (the robot should perform single pick-and-place demonstrative movement).
Note
When the BlocksWorld simulator fails to run
It may happen that the BlocksWorld simulator fails to run (we are still investigating the reason yet). In that case, please follow the next procedure:
- Load sample OpenHRP project.
Select “GrxUI > Read Project” from the menu. Load “PA10Sample” from “C:\Program Files (x86)\OpenHRPSDK\share\OpenHRP-3.1\sample\project”.
- Run OpenHRP simulation once.
Press “Start” button to run the simulation (you can stop any time).
- Clear the OpenHRP view.
Select “GrxUI > New Project” from the menu.
- Run the BlocksWorld simulator.
Now, run the BlocksWorld simulator again and check the behavior.
Function of the BlocksWorld Component¶
BlocksWorld simulator provides OpenRTM port interface to communicate with the other component.
PA10 arm of the BlocksWorld simulator can be controlled by sending following text commands to the “command” port:
- grasp
- Grasp hand to pick object.
- release
- Release hand to place object.
- moveHandToBox [name]
- Move hand above the block specified by the [name]. You can specify “box1”, “box2” and “box3”.
- moveHandXY [X] [Y]
- Move hand to [X][Y] meters relative to the current position.
Test Script¶
Here, we show the example of controlling PA10 arm using voice commands.
- Speech recognition grammar:
<?xml version="1.0" encoding="UTF-8" ?> <grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/06/grammar http://www.w3.org/TR/speech-grammar/grammar.xsd" xml:lang="en" version="1.0" mode="voice" root="command"> <rule id="command"> <one-of> <item> <item repeat="0-1">little more</item> <one-of> <item>front</item> <item>back</item> <item>left</item> <item>right</item> </one-of> </item> <item> <one-of> <item>red</item> <item>blue</item> <item>green</item> </one-of> <item repeat="0-1">box</item> </item> <item>pick it</item> <item>put it</item> </one-of> </rule> </grammar>
- Dialogue script:
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="command" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>pick it</key> <command host="command">grasp</command> </rule> <rule> <key>place it</key> <command host="command">release</command> </rule> <rule> <key>green [box]</key> <command host="command">moveHandToBox box1</command> </rule> <rule> <key>red [box]</key> <command host="command">moveHandToBox box2</command> </rule> <rule> <key>blue [box]</key> <command host="command">moveHandToBox box3</command> </rule> <rule> <key>forward</key> <command host="command">moveHandXY 0.1 0.0</command> </rule> <rule> <key>back</key> <command host="command">moveHandXY -0.1 0.0</command> </rule> <rule> <key>left</key> <command host="command">moveHandXY 0.0 0.1</command> </rule> <rule> <key>right</key> <command host="command">moveHandXY 0.0 -0.1</command> </rule> <rule> <key>little more forward</key> <command host="command">moveHandXY 0.05 0.0</command> </rule> <rule> <key>little more back</key> <command host="command">moveHandXY -0.05 0.0</command> </rule> <rule> <key>little more left</key> <command host="command">moveHandXY 0.0 0.05</command> </rule> <rule> <key>little more right</key> <command host="command">moveHandXY 0.0 -0.05</command> </rule> </state> </seatml>
Load each files to Julius component and SEAT component. And connect “command” port of SEAT component to “command” port of BlocksWorld component.
License¶
OpenHRI is developed and licensed under Eclipse Public License (EPL):
http://www.Eclipse.org/legal/EPL-v10.html
EPL is the open source license that allows code modification, redistribution and commercial use, but there is a case that the redistributor is required to disclose the modified code to the licenser.
OpenHRI internally uses softwares such as Julius, Open JTalk and Festival. These softwares follow their own licenses.