LoginSignup
3
2

More than 5 years have passed since last update.

My Alexa の知見2 implementing Alexa to Raspberry Pi zero

Last updated at Posted at 2017-02-12

はじめに

この投稿は私がラズパイで自作Alexaを開発した知見を投稿するシリーズです。
こんかいは、ラズパイゼロにインプリメントしたときのポイントです。
* ほとんどラズパイの内容です。

ラズパイゼロ

IMG_2879.jpg

サンプル動画はこちら

前提

インプリメントするAlexaのクライアントにはAlexaPiというpythonで書かれたクライアントを使います。

このクライアントは、
録音にpyaudio,
再生にmpg321
を使います。
(クライアントのインストールは割愛します。)

再生/録音デバイス

再生デバイス

aplay -lで確認。
スクリーンショット 2017-02-13 2.56.35.png
USBスピーカーはデバイス0のカード2なので、alsaのpcm.Name は、hw:2,0

スクリーンショット 2017-02-13 2.56.54.png
USBマイクはデバイス0のカード1なので、alsaのpcm.Name は、hw:1,0

~/.asoundrc にcaptureデバイスとplaybackデバイスの設定を記載する。

~/.asoundrc
pcm.!default{
  type asym
  playback.pcm{
    type plug
    slave.pcm "hw:2,0"
  }
  capture.pcm{
    type plug
    slave.pcm "hw:1,0"
  }
}

2017年1月11日版(作成時点で最新)のRaspbianでは、この設定だけでは動作しない場合がある。(ゼロでは動作しなかった)

結論は、/lib/modprobe.d/alias.confを修正して、最初に見つかったUSBデバイスをデフォルトに設定すること。
(他によい方法があればおしえていただきたいところです)

/lib/modprobe.d/alias.conf
# These are the standard aliases and dependencies.
# This file does not need to be modified.

# prevent unusual drivers from appearing as the first sound device ###########
options snd-pcsp index=-2
# options snd-usb-audio index=-2 <-- comment outする
options cx88_alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2

# work around other kernel issues ############################################
# The EHCI driver should be loaded before the ones for low speed controllers
# or some devices may be confused when they are disconnected and reconnected.
softdep uhci-hcd pre: ehci-hcd
softdep ohci-hcd pre: ehci-hcd

電力不足

スピーカーは5V/500mAのELECOMスピーカーを購入。
最初に接続したバータイプのスピーカーは電力消費が大きく、動作不安定になる。

補足

Alexa からの応答はmp3として保存して再生します。再生するライブラリにはこれまで、mpg123を利用してきましたが、再生の最後にノイズが走るので、mpg321に切り替えました。

USBスピーカーをデフォルトにする方法は、ググるとたくさんでてきますが、どれも古いので要注意です。

3
2
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
3
2