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
MediaPipe と ML Kit ってどう ちがうの? / What is the difference between MediaPipe and ML Kit?
yanzm
0
850
アプリをリリースできる状態に保ったまま 段階的にリファクタリングするための 戦略と戦術 / Strategies and tactics for incremental refactoring
yanzm
8
4.1k
Kotlinらしいコードを書こう - Convert Java File to Kotlin File のあとにやること / What to do after Convert Java File to Kotlin File
yanzm
1
5k
個人アプリ開発 (メンテナンス) 14年の歴史 / My personal app development history
yanzm
1
880
Material 3 やめました / Good-bye M3 design system
yanzm
4
8k
Compose Multiplatform で Bluesky のクライアント作ってみた / Bluesky client with Compose Multiplatform
yanzm
0
620
Compose Transition Animation
yanzm
3
730
Material3 with Jetpack Compose
yanzm
3
3.9k
Jetpack Compose 1.2 新機能 / new features of Jetpack Compose 1.2
yanzm
0
520
Other Decks in Technology
See All in Technology
【JAWS-UG大阪 reInvent reCap LT大会 サンバが始まったら強制終了】“1分”で初めてのソロ参戦reInventを数字で振り返りながら反省する
ttelltte
0
140
三菱電機で社内コミュニティを立ち上げた話
kurebayashi
1
360
商品レコメンドでのexplicit negative feedbackの活用
alpicola
2
370
Reactフレームワークプロダクトを モバイルアプリにして、もっと便利に。 ユーザに価値を届けよう。/React Framework with Capacitor
rdlabo
0
130
.NET AspireでAzure Functionsやクラウドリソースを統合する
tsubakimoto_s
0
190
実践! ソフトウェアエンジニアリングの価値の計測 ── Effort、Output、Outcome、Impact
nomuson
0
2.1k
iPadOS18でフローティングタブバーを解除してみた
sansantech
PRO
1
150
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
170
メンバーがオーナーシップを発揮しやすいチームづくり
ham0215
2
140
20250116_JAWS_Osaka
takuyay0ne
2
200
JAWS-UG20250116_iOSアプリエンジニアがAWSreInventに行ってきた(真面目編)
totokit4
0
140
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
170
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
40
2.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
RailsConf 2023
tenderlove
29
970
Gamification - CAS2011
davidbonilla
80
5.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
Adopting Sorbet at Scale
ufuk
74
9.2k
Visualization
eitanlees
146
15k
Scaling GitHub
holman
459
140k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Docker and Python
trallard
43
3.2k
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