2018年12月15日 AITCシニア成果発表会 想い楽器(おもいがき)
- 13. Google Speech API
Google Apps Script
防水スピーカー
¥1,050
バッテリー
¥1,364
ケーブル
¥390
アルミケース
¥1,985
USBマイク
流用
ラズパイ
流用
タッパ
¥100
ルーター
流用
ドングル
流用
用意するもの
PC
流用
- 15. 【Bluetooth、サウンドサーバのサービス化】
sudo systemctl enable hciuart.service
sudo systemctl enable pulseaudio.service
sudo systemctl enable ofono
【防水スピーカーとBluetooth接続】
sudo su -s /bin/bash pulse
bluetoothctl
pair 00:58:56:09:9C:15
connect 00:58:56:09:9C:15
【アプリケーション起動】
python ai-dialog.py
準備と起動
- 16. 【ai-dialog.py】
GOOGLE_APIKEY = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx‘
LISTEN_SECONDS = 5
VOICE_IN_PATH = '/home/pi/ai-samples/tmp.flac‘
VOICE_OUT_PATH = '/home/pi/ai-samples/tmp.wav‘
BLUETOOTH_BTS = 'bluez_sink.00_58_56_09_9C_15.a2dp_sink‘
# 録音
def listen(seconds):
cmdline = 'AUDIODEV=hw:0,0 rec -c 1 -r 16000 ' + VOICE_IN_PATH + ' trim 0 ' + str(seconds)
os.system(cmdline)
cmdline = 'paplay -d ' + BLUETOOTH_BTS + ' ' + VOICE_IN_PATH
os.system(cmdline)
# 音声認識
def recognize():
f = open(VOICE_IN_PATH, 'rb')
voice = f.read()
f.close()
url = 'https://www.google.com/speech-api/v2/recognize?xjerr=1&client=chromium&'¥
'lang=ja-JP&maxresults=1&pfilter=0&xjerr=1&key=' + GOOGLE_APIKEY
hds = {'Content-type': 'audio/x-flac; rate=17000'}
# スプレッドシートへ記録
def setSpreadsheet(text):
url = "https://script.google.com/macros/s/yyyyyyyyyyyyyyyyyyyyy/exec"
s = requests.session()
params = {"value": text}
response = requests.post(url, data=json.dumps(params))
# 読み上げ
def speak(message):
JDIC_DIR='/var/lib/mecab/dic/open-jtalk/naist-jdic/‘
VOICE_DATA='/home/pi/ai-samples/ai/mei/mei_happy.htsvoice‘
cmdline = 'echo ' + message + ' | open_jtalk -x ' + JDIC_DIR + ¥
' -m ' + VOICE_DATA + ' -ow ' + VOICE_OUT_PATH + ' -s 17000 -p 100 -a 0.03‘
os.system('paplay -d ' + BLUETOOTH_BTS + ' ' + VOICE_OUT_PATH)
プログラムソース(抜粋)
- 18. 【Bluetooth機器(BTS-06)のプロフィール】
pactl list
カード #1
名前: bluez_card.00_58_56_09_9C_15
ドライバー: module-bluez5-device.c
モジュール: 13
プロパティ:
device.description = "BTS-06"
device.string = "00:58:56:09:9C:15"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "headset"
bluez.path = "/org/bluez/hci0/dev_00_58_56_09_9C_15"
bluez.class = "0x240404"
bluez.alias = "BTS-06"
device.icon_name = "audio-headset-bluetooth"
device.intended_roles = "phone"
プロフィール:
a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
off: オフ (sinks: 0, sources: 0, priority: 0, available: yes)
有効なプロフィール: a2dp_sink
ポート:
headset-output: Headset (priority: 0, latency offset: 0 usec)
Part of profile(s): a2dp_sink, headset_head_unit
headset-input: Headset (priority: 0, latency offset: 0 usec, not available)
Part of profile(s): headset_head_unit
Bluetooth音声入力できない
- 19. Bluetooth音声入力できる
【Bluetooth機器(PLT_M70)のプロフィール】
pactl list
カード #5
名前: bluez_card.E4_22_A5_7F_F6_4C
ドライバー: module-bluez5-device.c
モジュール: 17
プロパティ:
device.description = "PLT M70"
device.string = "E4:22:A5:7F:F6:4C"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "headset"
bluez.path = "/org/bluez/hci0/dev_E4_22_A5_7F_F6_4C"
bluez.class = "0x240404"
bluez.alias = "PLT_M70"
device.icon_name = "audio-headset-bluetooth"
device.intended_roles = "phone"
プロフィール:
headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
off: オフ (sinks: 0, sources: 0, priority: 0, available: yes)
有効なプロフィール: headset_head_unit
ポート:
headset-output: Headset (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit, a2dp_sink
headset-input: Headset (priority: 0, latency offset: 0 usec)
Part of profile(s): headset_head_unit
- 24. • 初めてのラズパイ
• 久しぶりのunixと、はんだ付け
• 3Dプリンタでケース作り→購入
• ダイソーのスピーカー品切れ→代替品
• チーム要員が半減し寂しい
• スタート時は4名、今では2名→機能縮小
• 困ったときには、ネット検索
• Google、Qiita、Yahoo、・・・・
助かった、でも、結論が微妙!
【蒔田】