Alexa | Echo dot bluetooth接続時に「接続しました」を止める。(不完全)

なに?

基本的に個人的なメモです。
誰かのヒントにはなるかもしれないけど、見たままやればできるような説明はないです。めんどくさいので。すいません。

Background

Echo に bluetooth で接続している機材があると、たまに、外れたり接続復活したりした時にいきなり喋ります。
止めるオプションはない模様。
jp.amazonforum.com USのフォーラムでは チップにハードコードされている といった書き込みもあり、amazon staff も

"We're sorry for this frustration. The Bluetooth connection notification cannot be disabled."

と言い切っちゃってる。
以下参照

amazonforums.force.com

Alexa | Echo dot 4 clock で音楽ファイルを再生しようとしてわかったこと。 - Mobile Development Memorandum の後、ラズパイを使って再生するとかを見て、余ってるAndroid端末を使いAlexaから手持ちの音楽を再生してました。(node-red と Node-RED Alexa Home Skill Bridge をつかう)
いきなり喋るのやめて欲しい。

本題

接続しました。 を止める方法

1.まずは、不意なタイミングで鳴るのを止める方法

bluetooth に繋いでいるデバイス(自分の場合Android)側で bluetooth を Off にしてれば勝手に喋ることはないので、使う時だけ On にし、使い終わったら(再生が終了したら) 自動で Off にする。(Android の自動化はmacrodorid)
Echo がわの bluetooth の On/Off を node-red からコントロールも試したがいまいちうまくない。

2.使う時(On/Off時)に喋るのを(できるだけ)止める方法

Alexa の 定型アクション で音量変更をすると確認音が鳴るのを、直前に「echo のオーディオを停止」(echo は付けたechoの名前)を入れると、音が鳴らないのに気づいたので、bluetooth に接続する時にこれを入れるようにする。だけです。
だけですけど、bluetooth 接続は完了するタイミングが不定なのでオーディオ停止を1度入れただけでは、ほとんど止まらないです。
ので、node-red で 何度もコマンドを送る感じです。
あとは、alexa の定型アクション と macrodroid と node-red (Node-RED Alexa Home Skill Bridge, node-red-contrib-alexa-remote2-v2) を組み合わせて、ゴニョゴニョやっただけです。
不完全 のタイトル通り、完璧な動作には至りません。
タイミング的に、ぴぽっ! の半分くらいは鳴ることが多い。「接続しました」とか「〜〜〜で再生します」の部分はほぼ鳴らないです。 なんかうまくいかなくなった。めんどくさいので放置。
ちなみに、DND(Do not disturb/おやすみモード)では、この音は止まらないようです。何のためのDND??
ちなみにちなみに、鳴る間だけvolume 0 にする方法ではだめでした。勝手にvolume 1 になる。

beep 音は諦める。方法。(未確認)

Beep 音ではなく、喋る音声だけなら以下の方法で止まる模様。(未確認)

I checked with Customer Service on disabling this feature and this worked for me. I have Echo dot 4th Gen.

  1. Go to Settings on the Alexa app

  2. Choose Device settings

  3. Select the specific device

  4. In that device specific settings, you'll find an option called Communication

  5. Under Communications disable Announcements.

After disabling I restarted my Echo device. Now, it is only making the beep sound when connecting to and disconnecting from my laptop with Bluetooth. Also, it's not making the "Playing from ..." announcement when media is played. Hope this helps.

以下参照 www.reddit.com

以下メモ

CentOS8(常時稼働自家サーバー) に node-red のインストール

以下を参照 serverarekore.blogspot.com

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/rpm/update-nodejs-and-nodered)

boot 時に node-red 実行

以下を参照 nodered.jp

sudo npm install -g pm2

pm2 start /usr/bin/node-red -- -v

pm2 save
#  pm2 startup
[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=ssh
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/home/ssh/.local/bin:/home/ssh/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/root/.pm2
PIDFile=/root/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-ssh.service
Command list
[ 'systemctl enable pm2-ssh' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-ssh.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-ssh...
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd

再起動したらどうもうまく行かないので、以下参照

https://yasuttiblog.inet-yt.jp/2018/09/28/pm2%E3%81%A7node-red%E3%82%92%E8%B5%B7%E5%8B%95/yasuttiblog.inet-yt.jp

が、内容が違うので、まぁ、ドキュメント読むより勘で、以下でうまく行ったっぽい。root です。外に開いてないので。

sudo env PATH=$PATH:/usr/local/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u root --hp /root

node-red

使ったのは Node-RED Alexa Home Skill Bridge

alexa-node-red.bm.hardill.me.uk

以下も参照

chasuke.com

qiita.com

と node-red-contrib-alexa-remote2-v2 3.10.5

flows.nodered.org

node-red-contrib-alexa-remote2 (node) - Node-RED というのもあるけど、v2が新しい。ぽい。違いはわからない。どっちも、amazon.co.jp で使うにはソースの改変が必要。(同じで大丈夫ぽい。alexa-cookie2が同じかな?)

[root@nas alexa-cookie2]# pwd
/root/.node-red/node_modules/alexa-cookie2
[root@nas alexa-cookie2]# ls -la
合計 64
drwxr-xr-x   5 root root   171  2月  4 20:54 .
drwxr-xr-x 103 root root  4096  2月  4 20:54 ..
-rw-r--r--   1 root root    78 10月 26  1985 .commitmessage
-rw-r--r--   1 root root    65 10月 26  1985 .gitattributes
-rw-r--r--   1 root root  1102 10月 26  1985 LICENSE
-rw-r--r--   1 root root  7059 10月 26  1985 README.md
-rw-r--r--   1 root root 33210 10月 26  1985 alexa-cookie.js
drwxr-xr-x   2 root root    42  2月  4 20:54 example
drwxr-xr-x   2 root root    50  2月  4 20:57 lib
drwxr-xr-x   3 root root    20  2月  4 20:54 node_modules
-rw-r--r--   1 root root  1840  2月  4 20:54 package.json
[root@nas alexa-cookie2]# cp alexa-cookie.js alexa-cookie.js.org
[root@nas alexa-cookie2]# ls -la
合計 100
drwxr-xr-x   5 root root   198  2月  4 20:59 .
drwxr-xr-x 103 root root  4096  2月  4 20:54 ..
-rw-r--r--   1 root root    78 10月 26  1985 .commitmessage
-rw-r--r--   1 root root    65 10月 26  1985 .gitattributes
-rw-r--r--   1 root root  1102 10月 26  1985 LICENSE
-rw-r--r--   1 root root  7059 10月 26  1985 README.md
-rw-r--r--   1 root root 33210 10月 26  1985 alexa-cookie.js
-rw-r--r--   1 root root 33210  2月  4 20:59 alexa-cookie.js.org
drwxr-xr-x   2 root root    42  2月  4 20:54 example
drwxr-xr-x   2 root root    50  2月  4 20:57 lib
drwxr-xr-x   3 root root    20  2月  4 20:54 node_modules
-rw-r--r--   1 root root  1840  2月  4 20:54 package.json
[root@nas alexa-cookie2]# vim alexa-cookie.js

line 261 _options.baseAmazonPage を 日本ドメイン

_options = __options;
_options.baseAmazonPage='amazon.co.jp';  //<--この行を追加
[root@nas alexa-cookie2]# cd lib
[root@nas lib]# pwd
/root/.node-red/node_modules/alexa-cookie2/lib
[root@nas lib]# ls -la
合計 24
drwxr-xr-x 2 root root    50  2月  4 20:57 .
drwxr-xr-x 5 root root   198  2月  4 21:00 ..
-rw-r--r-- 1 root root   777  2月  4 20:57 formerDataStore.json
-rw-r--r-- 1 root root 19280 10月 26  1985 proxy.js
[root@nas lib]# cp proxy.js proxy.js.org
[root@nas lib]# ls -la
合計 44
drwxr-xr-x 2 root root    70  2月  4 21:01 .
drwxr-xr-x 5 root root   198  2月  4 21:00 ..
-rw-r--r-- 1 root root   777  2月  4 20:57 formerDataStore.json
-rw-r--r-- 1 root root 19280 10月 26  1985 proxy.js
-rw-r--r-- 1 root root 19280  2月  4 21:01 proxy.js.org
[root@nas lib]# vim proxy.js

line 181 returnedInitUrl を 日本ドメインに(詳細は知らない。)
//returnedInitUrl = https://www.${_options.baseAmazonPage}/ap/signin?openid.return_to=https%3A%2F%2Fwww.${_options.baseAmazonPage}%2Fap%2Fmaplanding&openid.assoc_handle=amzn_dp_project_dee_ios${_options.baseAmazonPageHandle}&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&pageId=amzn_dp_project_dee_ios${_options.baseAmazonPageHandle}&accountStatusPolicy=P1&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns.oa2=http%3A%2F%2Fwww.${_options.baseAmazonPage}%2Fap%2Fext%2Foauth%2F2&openid.oa2.client_id=device%3A${deviceId}&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.oa2.response_type=token&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.pape.max_auth_age=0&openid.oa2.scope=device_auth_access&language=${_options.amazonPageProxyLanguage};

returnedInitUrl = https://www.amazon.co.jp/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Falexa.amazon.co.jp%2F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee_jp&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&;

はてなMarkdownのコードシンタックスが1行が長いと文字が切れてしまうんだがなんだこれ。)

node-red restart

[root@nas lib]# systemctl restart nodered.service

以下参照 dream-soft.mydns.jp

で node-red はこんな感じ。

alexa に ミュージックプレーヤー とか言えば、定型アクションからnode-redがトリガーされhttp request から webhook で macrodroid をトリガーして、音楽プレーヤーアプリ(AIMP)を起動し再生開始。
set msg.counter -> switch -> delay 1s -> increment -> routine stop audio のループは while 的な感じ。
routine stop audio が 「echo のオーディオを停止」を 単独で 定型アクションとしてalexa に登録したもの。
[get] /stop_audio は get request で macrodroid 側から任意のタイミングで「echo のオーディオを停止」を 呼べるようにしたもの。
これ以上の説明はめんどくさいんで略。あとは察して。