
Watson APIの「Language Translator」をPepperで使ってみよう
こんにちは。
AI coordinatorの清水秀樹です。
話しかけた言葉をそのまま英訳してくれるPepperを開発してみましょう。
話しかけた言葉をしっかり認識できるPepperの開発方法は「Watsonと連携したPepper:Speech to Textで音声認識精度を上げてみよう」で紹介していますので参考にしてみてください。
準備するもの
コレグラフの準備。
使用するWatson APIは「Language Translator」です。
Bluemixの登録方法は以下の記事を参考にしてください。
IBM Bluemix登録方法 30日間は無料で使用できるぞ
登録が済んでいる方は「Language Translator」を作成しましょう。
カタログの中から「Language Translator」を選択し、そのまま次画面下部の作成ボタンでアプリを作成しましょう。

プロジェクトファイルの説明

人の発した言葉を認識するために「Watson Speech to Text」を使用しています。
「Watson Speech to Text」で音声をテキスト化したあとに「Language Translator」を使って日本語を英語に英訳しています。
プロジェクトファイル内の「Watson lang」Pythonボックスライブリのソース内は以下の通りです。
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#put initialization code here
pass
def onUnload(self):
#put clean-up code here
pass
def onInput_onStart(self, p):
import requests
user="サービス資格情報のusername"
pswd="サービス資格情報のpassword"
target = "en"
string = p
###Set the url###
url="https://gateway.watsonplatform.net/language-translator/api/v2/translate?source=ja&target="+str(target)+str("&text=")+str(string)
###Send the request###
r = requests.get(url ,auth =(user,pswd))
### print the result###
NewText= r.text
final= NewText.encode('utf-8')
self.onStopped(final)
def onInput_onStop(self):
self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
self.onStopped() #activate the output of the box
プロジェクトファイルのダウンロードはこちらから → Language Translator.zip
実機での動作確認は済んでいます。
ぜひ使ってみてください。
それではまた。
LEAVE A REPLY