Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Google Assistant with Raspberry Pi

Google Assistant with Raspberry Pi

Yuki Anzai

June 22, 2017
Tweet

More Decks by Yuki Anzai

Other Decks in Technology

Transcript

  1. ඞཁͳ΋ͷ • Raspberry Pi 3ʢRaspberry Pi 2 + WiFiυϯάϧͰ΋ Մʣ

    • Raspbian JessieͷΠϯετʔϧ͞ΕͨmicroSD • ిݯΞμϓλ ΋͘͠͸ microUSBέʔϒϧ • USB ϚΠΫ ΋͘͠͸ϚΠΫ಺ଂܕͷUSBΧϝϥ • εϐʔΧʔʢUSB or 3.5mmδϟοΫʣ
  2. ४උ • Raspberry Pi Ͱ SSH Λ༗ޮʹ͢Δ • Preferences -

    Raspberry Pi Configuration - Interfaces • SSH Λ Enabled ʹͯ͠ OK ΛΫϦοΫ
  3. ४උ2 • ࣌ࠁઃఆΛ֬ೝ͢Δʢ͕࣌ؒਖ਼͚͠Ε͹OKʣ • JST ʹ͍ͨ͠ͳΒ • Preferences - Raspberry

    Pi Configuration - Localisation • Set Timezone ΛΫϦοΫ • Area: Asia, Location: Tokyo • ࠶ىಈ
  4. ४උ3 • Raspberry Pi ʹ PC ͔Β SSH ͰϩάΠϯ͢Δ $

    ssh pi@[ϝϞͨ͠IPΞυϨε] password: [σϑΥϧτ͸raspberry] • ࣌ࠁઃఆΛ֬ೝ͢Δʢ͕࣌ؒਖ਼͚͠Ε͹OKʣ $ date
  5. OAuth Client ID ͷઃఆ - 3 • OAuth ΫϥΠΞϯτ ID

    Λ࡞੒͢Δ • μΠΞϩά͕දࣔ͞ΕͨΒ OK ΛΫϦοΫ
  6. OAuth Client ID ͷઃఆ - 5 • μ΢ϯϩʔυͨ͠ΫϥΠΞϯτ ID secret

    JSON ϑΝΠϧΛ Raspberry Pi ʹసૹ $ scp [μ΢ϯϩʔυͨ͠JSONϑΝΠϧ] pi@[ϝϞ ͨ͠IPΞυϨε]:/home/pi/ password: [σϑΥϧτ͸raspberry]
  7. Ի੠ͷઃఆͱ֬ೝ - 2 • ϚΠΫͷςετʢ5ඵؒ࿥Իʣ • Τϥʔ͕ग़ͳ͔ͬͨΒద౰ʹ͠Ό΂ͬͯ 7 ΁ •

    Τϥʔ͕ग़ͨΒ 3ʢ࣍ʣ΁ $ arecord --format=S16_LE --duration=5 -- rate=16k --file-type=raw out.raw
  8. Ի੠ͷઃఆͱ֬ೝ - 3 • ϚΠΫͷΧʔυ൪߸ͱσόΠε൪߸Λௐ΂Δ • ͜ΕͳΒΧʔυ൪߸͸ 1, σόΠε൪߸͸ 0

    $ arecord -l **** List of CAPTURE Hardware Devices **** card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  9. Ի੠ͷઃఆͱ֬ೝ - 4 • εϐʔΧʔͷΧʔυ൪߸ͱσόΠε൪߸Λௐ΂Δ • ͜ΕͳΒΧʔυ൪߸͸ 0, σόΠε൪߸͸ 0

    $ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  10. pcm.!default { type asym capture.pcm "mic" playback.pcm "speaker" } pcm.mic

    { type plug slave { pcm "hw:[ϚΠΫͷΧʔυ൪߸],[ϚΠΫͷσόΠε൪߸]" } } pcm.speaker { type plug slave { pcm "hw:[εϐʔΧʔͷΧʔυ൪߸],[εϐʔΧʔͷσόΠε൪߸]" } }
  11. pcm.!default { type asym capture.pcm "mic" playback.pcm "speaker" } pcm.mic

    { type plug slave { pcm "hw:1,0" } } pcm.speaker { type plug slave { pcm "hw:1,1" } } ྫʣ
  12. Ի੠ͷઃఆͱ֬ೝ - 6 • Raspberry Pi ͷ /home/pi/ ʹஔ͘ •

    2 ʹ໭Δ $ scp .asoundrc pi@[ϝϞͨ͠IPΞυϨε]:/ home/pi/ password: [σϑΥϧτ͸raspberry]
  13. Python ͷઃఆ • Python virtual environment Λ࢖ͬͯγεςϜͷ Python ύοέʔδ͔Β SDK

    ͱґଘ͢Δ΋Ζ΋ΖΛ ִ཭ • ݱঢ় Google Assistant ͷϥΠϒϥϦ͸ Python 3.x ͰͷΈಈ͘ • Πϯετʔϧͷ్தͰฉ͔ΕͨΒ y ͰਐΜͰͩ͘͞ ͍
  14. Python ͷઃఆ $ sudo apt-get update $ sudo apt-get install

    python3-dev python3-venv $ python3 -m venv env $ env/bin/python -m pip install --upgrade pip setuptools $ source env/bin/activate
  15. αϯϓϧίʔυͷೝূ - 1 • ϒϥ΢βΛ։͍ͯ Google ΞΧ΢ϯτʹϩάΠϯ͢ Δ • ΞΫςΟϏςΟίϯτϩʔϧͷઃఆΛͨ͠΍ͭ

    • ೝূπʔϧΛΠϯετʔϧ͢Δ (env) $ python -m pip install --upgrade google-auth-oauthlib[tool]
  16. αϯϓϧίʔυͷೝূ - 2 • ೝূπʔϧΛ࣮ߦ͢Δ • จࣈίʔυͷΤϥʔ͕ग़ͨΒ (env) $ google-oauthlib-tool

    --client- secrets /home/pi/[લʹసૹ͓͍ͯͨ͠JSON] -- scope https://www.googleapis.com/auth/ assistant-sdk-prototype --save --headless (env) $ export LC_ALL=C.UTF-8 (env) $ export LANG=C.UTF-8
  17. • ͱදࣔ͞ΕΔͷͰ … ෦෼ͷ URL Λίϐʔͯ͠ϒϥ ΢βʹషΓ෇͚ͯදࣔ • ΞΧ΢ϯτΛબ୒ʢඞཁͳ৔߹ʣ͠ɺALLOW ʢڐ

    ՄʣΛΫϦοΫ • දࣔ͞ΕΔίʔυΛίϐʔ͠ Please visit this URL to authorize this application: … Enter the authorization code: • ʹೖྗ