Cov txheej txheem:

Pi Tsev, Raspberry Powered Virtual Assistant: 11 Kauj Ruam (nrog Duab)
Pi Tsev, Raspberry Powered Virtual Assistant: 11 Kauj Ruam (nrog Duab)

Video: Pi Tsev, Raspberry Powered Virtual Assistant: 11 Kauj Ruam (nrog Duab)

Video: Pi Tsev, Raspberry Powered Virtual Assistant: 11 Kauj Ruam (nrog Duab)
Video: Dej myab: rov los tsev (Flooding ReEnter Home - Hmong) 2024, Kaum ib hlis
Anonim
Pi Tsev, Raspberry Powered Virtual Assistant
Pi Tsev, Raspberry Powered Virtual Assistant

Google Tsev yog qhov muaj txiaj ntsig kom muaj nyob ib puag ncig hauv tsev Nws yog lub cuab yeej zoo nkauj nrog built -in Google Assistant - Lub xeev ntawm kev kos duab digital tus pabcuam tus kheej los ntawm Google. Nws tuaj yeem ua si xov xwm, khaws koj cov lus ceeb toom thiab sau ntawv, qhia koj ntev npaum li cas ntawm koj txoj kev mus, ua lub tsev tsis siv neeg. tsis paub tseeb tias koj yuav siv nws. Xov xwm zoo txawm li cas los xij, koj tuaj yeem ua tiav ib qho uas siv Raspberry Pi.

Txog qhov kawg ntawm phau ntawv qhia no, koj yuav muaj lub Tsev Google ua haujlwm zoo uas teb rau koj cov lus txib. Txwv tsis pub, nws yog Tus Pabcuam nrog txhua tus yam ntxwv ntawm Google Tsev. Uas txhais tau tias nws tuaj yeem ua chav sib pauv, ua xov xwm, txheeb xyuas cov qhab nia, nyeem phau ntawv suab rau koj, txheeb xyuas huab cua, thiab ntau ntxiv. Nws tseem yuav ua haujlwm nrog ntau yam khoom siv hauv tsev zoo li lub teeb ci ntse, yog li koj tuaj yeem tswj hwm lawv nrog koj lub suab. Zoo li Google Assistant tiag tiag, koj lub DIY Google Tsev tuaj yeem txuas nrog ntxiv cov yam ntxwv ntxiv, xws li ntxiv rau-ua rau Evernote lossis kom tau txais kev ceeb toom ntawm koj lub xov tooj thaum lub sijhawm poob lawm.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau

Koj Yuav Tsum Tau:

  • Raspberry Pi 3 lossis 2 nrog Raspbian teeb tsa, thiab teeb tsa Wi-nkaus.
  • Fais Fab Khoom thiab MicroUSB Fais Fab Cable. (Yam tsawg kawg 5V, 2A)
  • MicroSD daim npav. (Yam tsawg kawg 8GB)
  • USB Microphone. (Koj yuav tau txais ntau yuav ua li cas teeb tsa hauv is taws nem, kuj nyob ntawm no …)
  • Hais lus
  • Keyboard thiab Mouse rau teeb tsa
  • LED thiab ob peb ntawm cov xov hlau los txuas

Txhua yam khoom sib sau ua ke, txuas nrog thiab txuas nrog, Cia peb pib nws.

Kauj ruam 2: Teeb USB USB Mic

Teeb USB USB Mic
Teeb USB USB Mic
  • Tus Pi tsis muaj lub microphones inbuilt. Koj yuav tsum txuas lub USB microphone yog tias koj xav kaw suab.
  • Txuas koj lub microphone USB rau hauv ib qho ntawm USB qhov chaw ntawm koj Pi.
  • Ntaus cov lus txib hauv qab no hauv lub davhlau ya nyob twg.

cov -l

Cov lus txib no yuav teev txhua yam khoom siv kaw suab uas muaj. Nws yuav tsis muaj dab tsi yog tias koj lub USB mic txuas nrog. Koj yuav tsum tau txais cov txiaj ntsig hauv qab no

pi@raspberrypi: ~ $ arecord -l

**** List of CAPTURE Hardware Devices **** card 1: Device [USB PnP Sound Device], ntaus ntawv 0: USB Audio [USB Audio] Subsevices: subdevice #0: subdevice #0

Koj tuaj yeem pom tias koj lub cuab yeej USB txuas nrog daim npav 1 thiab tus lej ntaus ntawv yog 0. Raspberry Pi lees paub daim npav 0 ua daim npav sab hauv, uas yog, bcm2835 thiab lwm daim npav suab sab nraud raws li daim npav suab sab nraud hu ua daim npav 1, daim npav 2 thiab ua raws …

Tam sim no, peb yuav tau hloov lub suab teeb tsa. Txhawm rau kho cov ntaub ntawv asound.conf, ntaus cov lus txib hauv qab no

sudo nano /etc/asound.conf

Ntxiv kab hauv qab no hauv cov ntawv. Tom qab ntawd nyem Ctrl+X thiab tom qab ntawd Y txhawm rau khaws cov ntawv

pwm! default {

ntaus asym capture.pcm "mic" playback.pcm "speaker"} pcm.mic {ntaus ntsaws qhev {pcm "hw: 1, 0"}} pcm.speaker {hom hw card 0} ctl.! default {hom hw card 0}

Qhov no yuav teeb tsa koj lub mic sab nraud (pcm.mic) ua lub cuab yeej kaw suab (pcm!

Tsim cov ntaub ntawv tshiab npe.asoundrc hauv phau ntawv qhia tsev (/tsev/pi) los ntawm kev tshaj tawm cov lus txib hauv qab no thiab muab tshuaj txhuam saum toj no teeb tsa (uas tau ntxiv hauv /etc/asound.conf file.) Rau cov ntawv no

sudo nano.asoundrc.

Kauj Ruam 3: Teeb Koj Cov Lus Hais Tawm

Teeb Koj Cov Lus Hais Tawm
Teeb Koj Cov Lus Hais Tawm
  • Txuas koj tus neeg hais lus rau 3.5mm lub mloog pob ntseg ntawm Raspberry Pi.
  • Khiav hauv qab cov lus txib kom qhib pi lub vijtsam teeb tsa.

sudo raspi-teeb tsa

Mus rau Advanced Options> Suab thiab xaiv cov khoom tso tawm. (3.5mm nkaus lossis HDMI)

Kauj Ruam 4: Kuaj Mic thiab Hais Lus

Ntsuas Mic thiab Hais Lus
Ntsuas Mic thiab Hais Lus

Txhawm rau sim koj tus neeg hais lus khiav cov lus txib hauv qab no hauv lub davhlau ya nyob twg. Qhov no yuav ua suab xeem. Nias Ctrl+C kom tawm mus. Yog tias koj tsis tuaj yeem hnov lub suab ntsuas ntsuas koj lub txuas txuas thiab lub zog. Kev xeem suab zoo li-

Pem Hauv Ntej Sab laug, Pem Hauv Ntej Txoj Cai

speaker -test -t yav

Txhawm rau sim koj lub mic, khiav cov lus txib hauv qab no. Qhov no yuav kaw lub suab luv luv ntawm 5 vib nas this. Yog tias koj tau txais ib qho yuam kev xyuas cov kauj ruam dhau los dua

arecord --format = S16_LE --duration = 5 --rate = 16k --file-type = raw tawm.raw

Ua si lub kaw suab thiab paub meej tias txhua yam ua haujlwm tau zoo los ntawm kev ntaus cov lus txib hauv qab no

aplay --format = S16_LE --rate = 16k tawm.raw

Peb kho vajtse tau teeb tsa

Kauj Ruam 5: Rub Cov Pob Yuav Tsum Tau Ua thiab teeb tsa Python Ib puag ncig:

Rub tawm Cov Pob Yuav Tsum Muaj thiab teeb tsa Python Ib puag ncig
Rub tawm Cov Pob Yuav Tsum Muaj thiab teeb tsa Python Ib puag ncig

Ua ntej, Hloov kho koj lub operating system los ntawm kev ua cov lus txib ib tus los ntawm ib qho hauv lub davhlau ya nyob twg

sudo apt-tau hloov tshiab

sudo apt-tau hloov tshiab

Khiav cov lus txib ib los ntawm ib qho hauv lub davhlau ya nyob twg yuav tsim Python 3 ib puag ncig (Google Assistant lub tsev qiv ntawv sau ntawm Python 3 nkaus xwb) hauv koj Pi thiab teeb tsa cov khoom xav tau

sudo apt-tau nruab python3-dev python3-venv

$ python3 -m venv env $ env/bin/python -m pip nruab -hloov kho pip setuptools

Qhib cov nab hab sej ib puag ncig. Qhov no yuav coj cov ntawv "(env)" nyob rau hauv pem hauv ntej ntawm koj tus Pi cov lus txib davhlau ya nyob twg

qhov chaw env/bin/qhib

Nruab Google Assistant SDK pob, uas muaj tag nrho cov cai xav tau los ua Google Assistant ntawm Pi. Nws yuav tsum rub tawm Google Assistant Library thiab qhov tseem ceeb

nab hab sej -m pip nruab-hloov kho google-assistant-library

Kauj Ruam 6: Pab kom Google Assistant Cloud Project

Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
Pab kom Google Assistant Cloud Project
  • Qhib Google Cloud Console thiab tsim txoj haujlwm tshiab. (Lub npe nws yog dab tsi.) Tus lej uas koj kos npe nkag yuav raug siv los xa lus nug rau Google Assistant thiab tau txais koj cov lus teb rau tus kheej.
  • Lub taub hau dhau mus rau tus thawj tswj hwm API thiab pab Google Assistant API.
  • Nco ntsoov tias koj qhib Web & App Kev Ua Haujlwm, Cov Lus Qhia Txog Ntaus Ntawv thiab Suab & Suab Ua Si hauv Kev Tswj Xyuas Haujlwm rau tus as khauj.
  • Mus rau "Cov Ntawv Pov Thawj" thiab teeb tsa OAuth Cov Ntsiab Lus Ntsuam Xyuas.
  • Mus rau "Cov Ntawv Pov Thawj" tab thiab Tsim OAuth tus lej tshiab
  • Xaiv hom ntawv thov ua "Lwm yam" thiab muab lub npe yuam sij.
  • Rub tawm JSON cov ntaub ntawv uas khaws cov ntaub ntawv tseem ceeb OAuth thiab khaws nws tseg.

Kauj Ruam 7: Kev lees paub tus Raspberry Pi

Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi
Kev lees paub Raspberry Pi

Nruab qhov cuab yeej tso cai los ntawm kev ua haujlwm hauv qab cov lus txib

(env) python -m pip install-upgrade google-auth-oauthlib [cuab yeej]

Khiav lub cuab yeej los ntawm kev ua raws cov lus txib hauv qab no. Nco ntsoov tias koj muab txoj hauv kev raug rau JSON cov ntaub ntawv koj rub tawm hauv qib 6

(env) google-oauthlib-tool --client-secrets "JSON_FILE_PATH" --cov https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

Nws yuav tsum tso saib raws li qhia hauv qab no. Luam qhov URL thiab muab tshuaj txhuam rau hauv qhov browser. Yog tias tsis yog, nws qhia:

InvalidGrantError

ces tus lej tsis raug tau nkag mus. Sim dua

Thov mus rau qhov URL no:

Sau cov cai tso cai:

Kauj Ruam 8: Teeb Teeb Qhov Taw Qhia LED

Teeb Teeb Qhov Taw Qhia LED
Teeb Teeb Qhov Taw Qhia LED
  • Txuas koj lub LED ntawm GPIO tus pin 25 thiab hauv av.
  • Peb tab tom yuav teeb GPIO tus pin 25 ua tus pin tso tawm.
  • Google Assistant SDK muab kev hu rov qab EventType. ON_CONVERSATION_ END_TURN_STARTED thaum hloov pauv nrog Google Assistant pib. Thaum ntawd, peb tab tom teeb tsa GPIO 25 kom ci LED.
  • Thaum twg los qhov kev sib tham xaus EventType. ON_CONVERSATION_ END_TURN_FINISHED yuav tau txais rov qab. Txog ntawm qhov ntawd, peb yuav rov pib dua GPIO 25 kom tua LED.

Kauj Ruam 9: Pib ntawm Boot tiav:

Initialise ntawm Boot tiav
Initialise ntawm Boot tiav
  • Thaum twg los xij koj tus Pi ua tiav khau raj, peb yuav sau tsab ntawv nab nab uas yuav txheeb xyuas thiab qhia Google Assistant ntawm khau raj.
  • Ua ntej tshaj RPi. GPIO pob ntxiv GPIO txhawb nqa siv cov lus txib hauv qab no.

pip nruab RPi. GPIO

Khiav cov kauj ruam ib tus zuj zus. Mus rau tus neeg siv phau ntawv teev npe. Tsim cov ntaub ntawv nab npawb tshiab main.py

cd /home /pib

sudo nano main.py

Sau cov ntawv txuas thiab khaws cov ntawv

Tam sim no tsim ib tsab ntawv plhaub uas yuav pib thiab ua haujlwm Google Assistant

sudo nano google-assistant-init.sh

Muab cov kab hauv qab no tso rau hauv cov ntawv thiab khaws cov ntawv

#!/bin/sh

/tsev/pi/env/bin/python3 -u /home/pi/main.py

Muab kev tso cai ua

sudo chmod +x google-assistant-init.sh

Koj tuaj yeem khiav google-assistant-init.sh los pib Google Assistant txhua lub sijhawm.

Kauj ruam 10: Pib Google Assistant Thaum Booting

Pib Google Assistant Thaum Pib
Pib Google Assistant Thaum Pib

Txhawm rau pab Google Assistant ntawm Boot muaj ob txoj hauv kev. Cia peb pom lawv txhua tus

1. Autostart nrog Pixel Desktop ntawm khau raj:

  • Qhov no yuav pib Google Assistant sai li sai tau Pixel desktop khau raj. Nco ntsoov tias koj muaj "Desktop" khau raj xaiv hauv Raspberry Pi teeb tsa.
  • Ntaus hauv qab cov lus txib.

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

Ntxiv cov hauv qab no tom qab @xscreensaver -no -splash

@lxterminal -e "/home/pi/google-assistant-init.sh"

Txuag thiab tawm los ntawm nias "Ctrl+X" thiab tom qab ntawd "Y

2. Autostart nrog CLI ntawm khau raj: (Kuv tus kheej siv qhov no, txawm hais tias autostart ua haujlwm txiav tawm zoo.)

  • Qhov no yuav pib Google Assistant yog tias koj tau teeb tsa CLI khau raj. Nco ntsoov tias koj muaj "CLI" khau raj xaiv hauv Raspberry Pi teeb tsa.
  • Ntaus hauv qab cov lus txib.

sudo nano /thiab /profile

Ntxiv kab hauv qab ntawm qhov kawg ntawm cov ntawv

sudo /home/pi/google-assistant-init.sh

Txuag thiab tawm los ntawm nias "Ctrl+X" thiab tom qab ntawd "Y"

Kauj Ruam 11: Xaus

Xaus
Xaus

Dab tsi yog qhov sib txawv ntawm Tsev Pi no? Tsis muaj dab tsi, tsuas yog cov nuj nqis. Qhov kawg tshwm sim yog qhov zoo ib yam, koj tuaj yeem qhib koj lub DIY Google Tsev los ntawm kev hais lo lus "Ok Google/ Hey Google," thiab lub cuab yeej ua haujlwm zoo li tus Pabcuam tiag tiag. Koj tuaj yeem ua ntau yam haujlwm txhua hnub nrog koj Google Tsev. Yog tias koj xav ua koj txoj haujlwm tshwj xeeb xws li kaw lub teeb, tshuaj xyuas lub qhov rooj, koj tuaj yeem ua nws nrog kev ua haujlwm Google Ua Haujlwm hauv koj Google Assistant. Yog tias koj muaj teeb meem nrog pib Google Assistant, tawm lus tawm hauv qab no. Kuv yuav sim daws lawv ntau npaum li kuv ua tau.

Pom zoo: