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
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
620
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
990
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
フルカイテン株式会社 採用資料
fullkaiten
0
40k
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
990
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
600
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
300
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Faster Mobile Websites
deanohume
305
30k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
For a Future-Friendly Web
brad_frost
175
9.4k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Designing the Hi-DPI Web
ddemaree
280
34k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Building Flexible Design Systems
yeseniaperezcruz
327
38k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
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