一半君的总结纸

听话只听一半君

用 raspberry pi 3 当 amazon echo

想用alexa控制我的tp-link smart plug hs-105 两只装,此外用自带的kasa app,或者google assistant都可以的

准备材料

  • raspberry pi 3
  • 麦克风(lz用的是网上推荐的淘宝的ps3 eye, 25元)
  • 音箱 3.5mm 接口

安装步骤:
按照rpi教程 Raspberry Pi Quick Start Guide with Script

  1. Register your product and create a security profile
  2. wget https://raw.githubusercontent.com/alexa/avs-device-sdk/master/tools/RaspberryPi/setup.sh && wget https://raw.githubusercontent.com/alexa/avs-device-sdk/master/tools/RaspberryPi/config.txt
    

    修改文件里的 Client ID, Client Secret, 和 Product ID 并保存

  3. 运行
    sudo bash setup.sh config.txt
    
  4. 编译完成后运行
    sudo bash startsample.sh
    

疑难解答

  • rpi通过hdmi连接显示器,结果显示器自带音箱,3.5mm的小音箱不出声
    需要运行这行,强制声音从3.5mm输出(假设你开机的时候插着hdmi线的话,就算显示器没开,他还是默认从hdmi出声音)

    amixer cset numid=3 1
    
  • ps3 eye的麦克风没声音
    显示麦克风设备

    pi@raspberrypi:~ $ arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
      Subdevices: 0/1
      Subdevice #0: subdevice #0
    

    配置文件

    # ps3 eye + 3.5mm speaker Raspberry Pi
    ## Suggested by http://julius.sourceforge.jp/forum/viewtopic.php?f=9&t=66
    ## Modified by https://github.com/afzalive
    pcm.jack {
      type hw
      card ALSA
    }
    pcm.array {
      type hw
      card CameraB409241
    }
    pcm.softvol {
      type softvol
      slave.pcm "jack"
      control {
        name Master
        card 0
      }
    }
    pcm.cap {
      type plug
      slave.pcm "array"
      slave.channels 4
      ttable {
        0.0 30.0
        1.1 30.0
      }
    }
    pcm.!default {
        type asym
        playback.pcm "plug:softvol"
        capture.pcm {
          type plug
          slave.pcm "cap"
        }
    }
    ctl.!default {
      type hw
      card 0
    }
    ctl.softvol {
      type hw
      card 0
    }
    
  • alexa回答的声音还没说完就断了
    MediaPlayer/src/MediaPlayer.cpp 第92行附近

    // The amount to wait before stopping the pipeline on an end-of-stream message to avoid cutting audio short prematurely
    static const std::chrono::milliseconds SLEEP_AFTER_END_OF_AUDIO{300};

    把300改大,如800,重新编译

  • 开机时自动启动
    在下面文件中加上

    @amixer cset numid=3 1
    @bash /home/pi/Downloads/startsample.sh
    

参考:
github 项目 alexa/avs-device-sdk
An .asoundrc ALSA config for the PS3 Eye
Raspberry Pi Command Line Audio
Alexa gets cut off before finished speaking #469
Execute script on start-up

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

%d 博主赞过: