30
25

More than 3 years have passed since last update.

Alexa(Amazon Echo)をコマンドラインから自由に喋らせる方法

Last updated at Posted at 2020-05-21

コマンドラインを使うと Alexa (Amazon Echo) を自由に喋らせることができます。
本記事では alexa_remote_control を使用します。

ちなみに、コマンドラインを使わない方法は以下のようなものがあります。

  1. 定型アクション → トリガーが「時刻、指定フレーズ、スマートホーム、アラーム停止時」しかなく限定的
  2. Node-redhttps://dream-soft.mydns.jp/blog/developper/smarthome/2019/10/362/
  3. 自作スキル → スキルを起動していない状態でも通知は送れるが(黄LED)、ユーザーが「通知を読んで」と言うまで読み上げないので却下

cron を使うと時報などもできます:
Alexaの時報をスキル・定型アクションなしで実現する方法 - Qiita

ダウンロード

alexa_remote_control.sh を適当な場所に保存して、chmod で実行権限を与えます。
brew install jq (Mac) などで jq をインストールします。

Plain バージョン (alexa_remote_control_plain.sh) は jq が必要ありません。

There's also a "plain" version, which lacks some functionality (-z, -i, -p, -P, -S and no radio station names and no routines) but doesn't require 'jq' for JSON processing.

2段階認証を使う場合には、brew install oath-toolkit (Mac) で oathtool をインストールしておきます。

セットアップ

SET_EMAIL: Amazon メールアドレス
SET_PASSWORD: Amazon パスワード
SET_MFA_SECRET: Amazon の2段階認証設定ページ → アプリを追加 → QRコードをスキャンできない場合のコード
SET_LANGUAGE: ja-JP または en-US など
SET_TTS_LOCALE: ja-JP または en-US など
SET_AMAZON='amazon.co.jp'
SET_ALEXA='alexa.amazon.co.jp'

SET_OATHTOOL=: oathtoolコマンドの場所

※ Windows からログインがありましたというメールが来ることがあります。気になる方は SET_BROWSER で UA を変更してください。

:warning: Mac の場合は gsed, ggrep が必要なことがあります。必要に応じてコードを書き換えてください。
:warning: パスワードなどをコードにべた書きは良くないので気をつけましょう。

実行

./alexa_remote_control.sh -e "speak:こんにちは!"

「こんにちは!」と再生されれば成功です!

エラーが表示される場合

  • ブラウザで https://alexa.amazon.co.jp からは音楽を再生できますか?
  • gsed, ggrep は導入していますか?

その他コマンド

ヘルプ

./alexa_remote_control.sh -h

ベルを再生

./alexa_remote_control.sh -e "sound:bell_02"

指定の呼びかけに対する反応

./alexa_remote_control.sh -e "textcommand:今日は何の日"

音量を%で指定(0-100)

./alexa_remote_control.sh -e "vol:15"

英語で発話

./alexa_remote_control.sh -e speak:"<lang xml:lang='en-US'><voice name='Joanna'>Hello</voice></lang>"

男声:Matthew

ささやき声

./alexa_remote_control.sh -e speak:"<amazon:effect name='whispered'>こんにちは</amazon:effect>"

会話風

./alexa_remote_control.sh -e speak:"<amazon:domain name='conversational'>こんにちは</amazon:domain>"

ニュース風

./alexa_remote_control.sh -e speak:"<amazon:domain name='news'>こんにちは</amazon:domain>"

強調

./alexa_remote_control.sh -e speak:"<emphasis level='moderate'>こんにちは</emphasis>"

strong/moderate/reduced

感情のこもった定型文

./alexa_remote_control.sh -e speak:"<say-as interpret-as='interjection'>うふふ</say-as>"

声の音量、高さ、速さ

./alexa_remote_control.sh -e speak:"<prosody pitch='high'>高い声です</prosody>"

rate: x-slow、slow、medium、fast、x-fast
pitch: x-low、low、medium、high、x-high
volume: silent、x-soft、soft、medium、loud、x-loud

30
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
25