經由 Linkit Smart 7688 將文字傳送給 IBM Watson,並透過 Text To Speech 的服務將文字轉換為語言後傳送回 Linkit Smart 7688 。
前置準備作業
準備一片 Linkit Smart 7688 開發板
將 Linkit Smart 7688 連接至電腦
更新 Firmware 為 0.9.3
http://goo.gl/dVLQ2Y將 USB 音效卡透過 OTG Cable 安裝於 Linkit Smart 7688
安裝 MIC 與 Speaker 於外接 USB 音效卡上
安裝 USB 音效卡相關套件
REF: http://goo.gl/D5rHtu
Linkit Smart 7688 與 USB 外接音效卡連接圖
IBM Watson 端
Step 1. 到 IBM Bluemix 網站申請帳號 https://console.ng.bluemix.net/
Step 2. 登入 IBM Bluemix 網站
Step 3. 點擊上方型錄
Step 4. 點擊左方的 Watson
Step 5. 點擊右邊的 Text to Speech 服務
Step 6. 點擊建立服務
Step 7. 建立 Text to Speech 服務完成的畫面
Step 8. 服務認證畫面 其中 password 與 username 的部份之後會使用到。
Linkit Smart 7688 端
Step 1. SSH 進入 Linkit Smart 7688 中
Step 2. 安裝 Watson 套件
pip install watson-developer-cloud
Step 3. 於 Linkit Smart 7688 中建立 Watson Text to Speech 的 Python Code
PS. 其中 username 與 password 請更新為服務認證畫面中的 password 與 username
# coding=utf-8
import json
from os.path import join, dirname
from watson_developer_cloud import TextToSpeechV1
text_to_speech = TextToSpeechV1(
username='<USERNAME>',
password='<PASSWORD>',
x_watson_learning_opt_out=True) # Optional flag
print(json.dumps(text_to_speech.voices(), indent=2))
with open(join(dirname(__file__), './resources/output.wav'), 'wb') as audio_file:
audio_file.write(text_to_speech.synthesize('I come from Taiwan', accept='audio/wav', voice="en-US_AllisonVoice"))
print(json.dumps(text_to_speech.pronunciation('Watson', pronunciation_format='spr'), indent=2))
print(json.dumps(text_to_speech.customizations(), indent=2))
- Step 4. 執行 Python Code
python text_to_speech_v1.py
- Step 5. 播放 Watson 所產生的 Text to Speech 之 Wav 檔案
aplay -D plughw:1,0 output.wav