Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Google Assistant with Raspberry Pi
Search
Yuki Anzai
June 22, 2017
Technology
3
520
Google Assistant with Raspberry Pi
Yuki Anzai
June 22, 2017
Tweet
Share
More Decks by Yuki Anzai
See All by Yuki Anzai
アプリをリリースできる状態に保ったまま 段階的にリファクタリングするための 戦略と戦術 / Strategies and tactics for incremental refactoring
yanzm
8
3.6k
Kotlinらしいコードを書こう - Convert Java File to Kotlin File のあとにやること / What to do after Convert Java File to Kotlin File
yanzm
1
4.7k
個人アプリ開発 (メンテナンス) 14年の歴史 / My personal app development history
yanzm
1
850
Material 3 やめました / Good-bye M3 design system
yanzm
4
7.6k
Compose Multiplatform で Bluesky のクライアント作ってみた / Bluesky client with Compose Multiplatform
yanzm
0
590
Compose Transition Animation
yanzm
3
700
Material3 with Jetpack Compose
yanzm
3
3.8k
Jetpack Compose 1.2 新機能 / new features of Jetpack Compose 1.2
yanzm
0
490
Now in Android アプリ解説 / Now in Android App
yanzm
2
1.8k
Other Decks in Technology
See All in Technology
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
250
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
200
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
630
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
140
AGIについてChatGPTに聞いてみた
blueb
0
130
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
890
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Scaling GitHub
holman
458
140k
Happy Clients
brianwarren
98
6.7k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
What's new in Ruby 2.0
geeforr
343
31k
Speed Design
sergeychernyshev
25
620
Testing 201, or: Great Expectations
jmmastey
38
7.1k
How STYLIGHT went responsive
nonsquared
95
5.2k
Code Review Best Practice
trishagee
64
17k
Transcript
Raspberry Pi Ͱ Google Assistant Λମݧ͠Α͏ ͋Μ͍͟Ώ͖ʢ@yanzmʣ GTUG Girls Meet
Up #33
ࢿྉ goo.gl/CDHpi4
Google Assistant • https://assistant.google.com/ • SDK • https://developers.google.com/assistant/sdk/ prototype/getting-started-pi-python/
ඞཁͳͷ • Raspberry Pi 3ʢRaspberry Pi 2 + WiFiυϯάϧͰ Մʣ
• Raspbian JessieͷΠϯετʔϧ͞ΕͨmicroSD • ిݯΞμϓλ ͘͠ microUSBέʔϒϧ • USB ϚΠΫ ͘͠ϚΠΫଂܕͷUSBΧϝϥ • εϐʔΧʔʢUSB or 3.5mmδϟοΫʣ
४උ • Raspberry Pi Λ WiFi ʹଓ͢Δ
४උ • Raspberry Pi ͰίϯιʔϧΛ։͖ɺifconfig ίϚϯ υΛ࣮ߦͯ͠IPΞυϨεΛϝϞ͢Δ
४උ • Raspberry Pi Ͱ SSH Λ༗ޮʹ͢Δ • Preferences -
Raspberry Pi Configuration - Interfaces • SSH Λ Enabled ʹͯ͠ OK ΛΫϦοΫ
४උ2 • ࣌ࠁઃఆΛ֬ೝ͢Δʢ͕࣌ؒਖ਼͚͠ΕOKʣ • JST ʹ͍ͨ͠ͳΒ • Preferences - Raspberry
Pi Configuration - Localisation • Set Timezone ΛΫϦοΫ • Area: Asia, Location: Tokyo • ࠶ىಈ
४උ3 • Raspberry Pi ʹ PC ͔Β SSH ͰϩάΠϯ͢Δ $
ssh pi@[ϝϞͨ͠IPΞυϨε] password: [σϑΥϧτraspberry] • ࣌ࠁઃఆΛ֬ೝ͢Δʢ͕࣌ؒਖ਼͚͠ΕOKʣ $ date
։ൃϓϩδΣΫτͱ ΞΧϯτͷઃఆ • https://developers.google.com/assistant/sdk/ prototype/getting-started-pi-python/config-dev- project-and-account Λ։͘ • goo.gl/GxLUSW •
Ҏ߱ɺ͜ͷϖʔδΛʮઃఆखॱυΩϡϝϯτʯͱݺ ͼ·͢ɻ
৽͍͠ϓϩδΣΫτΛ࡞Δ - 1 • ʮઃఆखॱυΩϡϝϯτʯʹ͋Δ GO TO THE PROJECT PAGE
ϘλϯΛΫϦοΫ͢Δ
৽͍͠ϓϩδΣΫτΛ࡞Δ - 2 • ্ͷํʹ͋ΔϓϩδΣΫτΛ࡞ΛΫϦοΫ • ϓϩδΣΫτ໊Λೖྗͯ͠࡞ΛΫϦοΫ • ͳΜͰΑ͍Ͱ͢ɻAssistant with
Raspberry Pi ͱ͔
Google Assistant API ༗ޮԽ • ʮઃఆखॱυΩϡϝϯτʯʹ͋Δ ENABLE THE API ϘλϯΛΫϦοΫ͢Δ
OAuth Client ID ͷઃఆ - 1 • OAuth ಉҙը໘Λઃఆ͢Δ
OAuth Client ID ͷઃఆ - 2 • OAuth ΫϥΠΞϯτ ID
Λ࡞͢Δ
OAuth Client ID ͷઃఆ - 3 • OAuth ΫϥΠΞϯτ ID
Λ࡞͢Δ • μΠΞϩά͕දࣔ͞ΕͨΒ OK ΛΫϦοΫ
OAuth Client ID ͷઃఆ - 4 • ΫϥΠΞϯτ ID secret
JSON ϑΝΠϧΛμϯ ϩʔυ
OAuth Client ID ͷઃఆ - 5 • μϯϩʔυͨ͠ΫϥΠΞϯτ ID secret
JSON ϑΝΠϧΛ Raspberry Pi ʹసૹ $ scp [μϯϩʔυͨ͠JSONϑΝΠϧ] pi@[ϝϞ ͨ͠IPΞυϨε]:/home/pi/ password: [σϑΥϧτraspberry]
ΞΫςΟϏςΟίϯτϩʔϧͷ ઃఆ - 1 • ʮઃఆखॱυΩϡϝϯτʯͷԼͷํʹ͋Δ Activity Controls page ͷϦϯΫΛ։͘
ΞΫςΟϏςΟίϯτϩʔϧͷ ઃఆ - 2 • ҎԼͷ߲Λ༗ޮʹ͢Δ • ΣϒͱΞϓϦͷΞΫςΟϏςΟ • ϩέʔγϣϯཤྺ
• ใ • ԻΞΫςΟϏςΟ
Իͷઃఆͱ֬ೝ - 0 • RaspberryPi ʹ SSH ͰϩάΠϯ͢Δ
Իͷઃఆͱ֬ೝ - 1 • εϐʔΧʔͷςετ • Front, Left ͕܁Γฦ͠ฉ͑͜ΕOK •
Ի͕໐Βͳ͍ਓ࣍ͷεϥΠυ $ speaker-test -t wav
εϐʔΧʔ͔ΒԻ͕໐Βͳ͍ ਓ͜ΕΛΔ $ sudo raspi-config • ʲAdvanced OptionsʳΛબ • ʲAudioʳΛબ
• ʲForce 3.5mmʢ'headphone'ʣjackʳΛબ
Իͷઃఆͱ֬ೝ - 2 • ϚΠΫͷςετʢ5ඵؒԻʣ • Τϥʔ͕ग़ͳ͔ͬͨΒదʹ͠Όͬͯ 7 •
Τϥʔ͕ग़ͨΒ 3ʢ࣍ʣ $ arecord --format=S16_LE --duration=5 -- rate=16k --file-type=raw out.raw
Իͷઃఆͱ֬ೝ - 3 • ϚΠΫͷΧʔυ൪߸ͱσόΠε൪߸ΛௐΔ • ͜ΕͳΒΧʔυ൪߸ 1, σόΠε൪߸ 0
$ arecord -l **** List of CAPTURE Hardware Devices **** card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Իͷઃఆͱ֬ೝ - 4 • εϐʔΧʔͷΧʔυ൪߸ͱσόΠε൪߸ΛௐΔ • ͜ΕͳΒΧʔυ൪߸ 0, σόΠε൪߸ 0
$ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Իͷઃఆͱ֬ೝ - 5 • SSH ͷଓΛΔ • ઃఆϑΝΠϧΛ࡞Δ • ϑΝΠϧ໊
: .asoundrc • ༰: ࣍ͷεϥΠυ
pcm.!default { type asym capture.pcm "mic" playback.pcm "speaker" } pcm.mic
{ type plug slave { pcm "hw:[ϚΠΫͷΧʔυ൪߸],[ϚΠΫͷσόΠε൪߸]" } } pcm.speaker { type plug slave { pcm "hw:[εϐʔΧʔͷΧʔυ൪߸],[εϐʔΧʔͷσόΠε൪߸]" } }
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" } } ྫʣ
Իͷઃఆͱ֬ೝ - 6 • Raspberry Pi ͷ /home/pi/ ʹஔ͘ •
2 ʹΔ $ scp .asoundrc pi@[ϝϞͨ͠IPΞυϨε]:/ home/pi/ password: [σϑΥϧτraspberry]
Իͷઃఆͱ֬ೝ - 7 • 2ͰԻͨ͠ԻΛ࠶ੜ • ͳ͘Ի͞Ε͍ͯΕ OK • Իྔͷௐઅ
$ aplay --format=S16_LE --rate=16k out.raw $ alsamixer
Python ͷઃఆ • Python virtual environment ΛͬͯγεςϜͷ Python ύοέʔδ͔Β SDK
ͱґଘ͢ΔΖΖΛ ִ • ݱঢ় Google Assistant ͷϥΠϒϥϦ Python 3.x ͰͷΈಈ͘ • Πϯετʔϧͷ్தͰฉ͔ΕͨΒ y ͰਐΜͰͩ͘͞ ͍
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
ϥΠϒϥϦͱαϯϓϧίʔυ Λऔͬͯ͘Δ (env) $ python -m pip install --upgrade google-assistant-library
αϯϓϧίʔυͷೝূ - 1 • ϒϥβΛ։͍ͯ Google ΞΧϯτʹϩάΠϯ͢ Δ • ΞΫςΟϏςΟίϯτϩʔϧͷઃఆΛͨͭ͠
• ೝূπʔϧΛΠϯετʔϧ͢Δ (env) $ python -m pip install --upgrade google-auth-oauthlib[tool]
αϯϓϧίʔυͷೝূ - 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
• ͱදࣔ͞ΕΔͷͰ … ෦ͷ URL Λίϐʔͯ͠ϒϥ βʹషΓ͚ͯදࣔ • ΞΧϯτΛબʢඞཁͳ߹ʣ͠ɺALLOW ʢڐ
ՄʣΛΫϦοΫ • දࣔ͞ΕΔίʔυΛίϐʔ͠ Please visit this URL to authorize this application: … Enter the authorization code: • ʹೖྗ
αϯϓϧίʔυͷ࣮ߦ • OK, google. What’s the weather in Tokyo •
ͱݴͬͯΈΑ͏ (env) $ google-assistant-demo