Cov txheej txheem:

Yuav Ua Li Cas Tsim Alexa Skill: 10 Kauj Ruam
Yuav Ua Li Cas Tsim Alexa Skill: 10 Kauj Ruam

Video: Yuav Ua Li Cas Tsim Alexa Skill: 10 Kauj Ruam

Video: Yuav Ua Li Cas Tsim Alexa Skill: 10 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Hlis ntuj nqeg
Anonim
Yuav Ua Li Cas Tsim Alexa Skill
Yuav Ua Li Cas Tsim Alexa Skill

Dab tsi yog alexa txuj ci?

Kev txawj ntse Alexa zoo li cov apps. Koj tuaj yeem qhib thiab kaw qhov txuj ci, siv Alexa app lossis lub vev xaib, zoo ib yam uas koj nruab thiab tshem tawm cov apps ntawm koj lub xov tooj ntse lossis ntsiav tshuaj. Cov txuj ci yog lub peev xwm hais lus Alexa. Koj tuaj yeem ntxiv Alexa cov txuj ci rau koj li Echo kom coj cov khoom lag luam thiab kev pabcuam rau lub neej. Koj tuaj yeem saib cov txuj ci uas muaj thiab ua haujlwm lossis ua rau lawv siv koj li Alexa app.

Phau ntawv qhia no qhia koj yuav ua li cas tsim kev txawj alexa.

Lub hom phiaj:

Lub hom phiaj yog, txhawm rau tsim txuj ci, uas qhia tus neeg siv cov lus german lom zem txhua lub sijhawm, tus neeg siv nug.

Demo:

Txhawm rau pom, yuav ua li cas cov txuj ci yuav tsum ua haujlwm tom qab, koj tuaj yeem sim nws ntawm no:

www.amazon.com/gp/product/B07ZH9GL9N?ref&r…

Khoom siv

  • Kev paub hauv programming
  • Pib hauv Node.js thiab Javascript

Kauj Ruam 1: Tsim Amazon Tus Tsim Tus Kheej

Tsim tus lej tsim tawm Amazon
Tsim tus lej tsim tawm Amazon

Muab koj tsis muaj Amazon Tus Tsim Kho Tus Kheej koj tuaj yeem sau npe ntawm no. Txwv tsis pub koj tuaj yeem kos npe rau ntawm no.

Kauj Ruam 2: Tsim Tus Kheej Tshiab

Tsim Tus Kheej Tshiab
Tsim Tus Kheej Tshiab
Tsim Tus Kheej Tshiab
Tsim Tus Kheej Tshiab
  1. Ua raws qhov txuas no:
  2. Nyem rau Tsim Kev Txawj Ntse ntawm sab xis. Ib nplooj ntawv tshiab qhib tom qab.
  3. Sau lub npe ntawm koj qhov txuj ci (hauv peb qhov xwm txheej: Cov Lus Zoo Tshaj Lij German) hauv Cov Npe Txawj Ntse.
  4. Teem cov lus hauv Hom Lus Xaiv-Box rau Askiv (Asmeskas)
  5. Peb tab tom yuav tsim kev cai tshwj xeeb, yog li peb xaiv Tus Qauv Tshwj Xeeb
  6. Ntawm Xaiv ib txoj hauv kev los tuav koj qhov kev txawj ntse backend cov peev txheej peb xaiv Alexa-Hosted (Node.js)
  7. Tom qab koj ua tiav nyem rau ntawm Tsim kev txawj
  8. Lub qhov rai tshiab qhib

Kauj ruam 3: Txais tos tus neeg siv

Txais tos tus neeg siv
Txais tos tus neeg siv

Thawj qhov uas tus neeg siv ua nrog koj qhov txuj ci nws qhib nws. Lub hom phiaj, uas qhib qhov txuj ci twb tau ua tiav hauv cov qauv coj ua thiab tsis tas yuav ntxiv ntxiv lawm.

  1. Qhib qhov Code tab → Lub qhov rai chaws nrog cov ntawv index.js qhib

    Txhua tus neeg tuav lub hom phiaj muaj ob txoj haujlwm

    • canHandle ()
    • tuav ()

    CanHandle () muaj nuj nqi suav nrog qhov kev thov, tus tuav haujlwm teb rau.

    Tus kov () muaj nuj nqi xa cov lus teb rau tus neeg siv.

    Yog tias qhov txuj ci tau txais kev thov, canHandle () muaj nuj nqi ntawm txhua tus neeg tuav lub hom phiaj tau hu thiab tshawb xyuas, yog tias nws tuaj yeem xa cov lus teb rau qhov kev thov ntawd.

  2. Hauv kev tuav () ua haujlwm ntawm LaunchRequestHandler rho tawm tag nrho cov cai thiab muab cov hauv qab no tom qab:

    const speakOutput = 'Zoo siab txais tos rau cov lus German lom zem. Tshawb nrhiav cov lus txaus luag uas lus German tau muab thiab lawv txhais li cas. Koj puas xav hnov lo lus luag ntxhi? ';

    const repromptText = 'Koj puas xav hnov cov lus German txaus luag?'; xa rov qab handlerInput.responseBuilder.speak (speakOutput).reprompt (repromptText).getResponse ();

  3. Nyem rau Txuag thiab Siv.

Qhov kev pab cuam lub hom phiaj xav tau hloov pauv kom haum nrog cov txuj ci. Rho tawm cov cai ntawm tus tuav () ua haujlwm thiab ntxig qhov no:

const speakOutput = 'Tshawb nrhiav cov lus txaus luag uas lus German tau muab thiab lawv txhais li cas. Koj puas xav hnov lo lus luag ntxhi? ';

const repromptText = 'Koj puas xav hnov cov lus German txaus luag?'; xa rov qab handlerInput.responseBuilder.speak (speakOutput).reprompt (repromptText).getResponse ();

Tom qab ua tiav qhov no nyem Txuag thiab Siv.

Kauj Ruam 4: Xeem Kev Txais Tos

Xeem Kev Txais Tos
Xeem Kev Txais Tos
Xeem Kev Txais Tos
Xeem Kev Txais Tos

Txhua lub sijhawm koj muaj kev ua haujlwm tau zoo dua rau koj qhov kev txawj, sim yog tias nws ua haujlwm tiag tiag, txhawm rau tshawb pom thaum muaj qhov ua yuam kev, qhov twg tuaj yeem ua yuam kev.

  1. Nyem rau ntawm Test tab → Lub qhov rai tshiab qhib.
  2. Qhib qhov chaw sim, los ntawm kev xaiv Kev Txhim Kho hauv lub thawv xaiv.
  3. Sau lossis hais lus: "oppen lus txaus luag German" skill Cov txuj ci tam sim no yuav tsum teb nrog kev tos txais.

Kauj Ruam 5: Ntxiv Kev Xav

Ntxiv Intents
Ntxiv Intents
Ntxiv Intents
Ntxiv Intents
Ntxiv Intents
Ntxiv Intents

Tam sim no peb yuav ntxiv txoj hauv kev li cas tus neeg siv tuaj yeem cuam tshuam nrog koj cov txuj ci. Lub hom phiaj ua rau nws muaj peev xwm ua kom raug tom qab cov lus tshwj xeeb thiab ua rau tus neeg ua haujlwm tsis txaus siab tom qab.

  1. Nyem rau ntawm Build tab → Lub qhov rais qhib qhib.
  2. Qhov bar qhia ntawm sab xis qhia tag nrho cov kev xav tau qhib. Ua ntej tshaj plaws, rho tawm HelloWorldIntent.
  3. Tom qab ntawv nyem rau ntawm Add Button nyob ib sab ntawm lub siab xav tab hauv qhov bar navigation.

Ua ntej tshaj plaws, peb ntxiv qee qhov ua hauv kev xav los ntawm Alexa lub tsev qiv ntawv built-in

  1. Nyem rau ntawm Siv lub hom phiaj uas twb muaj lawm los ntawm Alexa lub tsev qiv ntawv built-in
  2. Nrhiav YesIntent thiab NoIntent thiab nyem ntxiv los ntawm ob qho tib si.

Tam sim no peb ntxiv peb tus kheej lub hom phiaj kev xav.

  1. Nyem rau ntawm Tsim kev mob siab rau
  2. Muab lub npe TellAFunnyWordIntent rau lub hom phiaj
  3. Nyem rau ntawm Tsim kev mob siab rau

Tam sim no peb yuav ntxiv qee cov lus piv txwv rau peb lub hom phiaj. Cov kab lus piv txwv yog kab lus uas tus neeg siv tuaj yeem hais tau. Tsuas yog sau cov kab lus piv txwv:

  • qhia kuv ib lo lus
  • qhia kuv ib lo lus German lom zem
  • ib lus
  • lus funny
  • los qhia kuv ib lo lus

Tau kawg muaj ntau nqe lus ntau ntxiv uas tus neeg siv tuaj yeem hais. Koj tuaj yeem txuas ntxiv lub hom phiaj yog tias koj xav tau, tab sis peb tau tsom mus rau kev ua haujlwm tau zoo tam sim no.

Tom qab ntxiv cov kab lus, nyem rau Txuag Qauv thiab tom qab ntawd ntawm Tsim Qauv. Tom qab tsim tiav, rov qab mus rau Code tab.

Kauj Ruam 6: Ntxiv Cov Lus Zoo

Txhawm rau ua peb cov txuj ci qhia cov lus txaus luag, nws xav tau qee cov lus lom zem ua ntej.

Txog qhov ntawd, tsim cov ntawv tshiab hu ua words.json hauv daim nplaub tshev lambda.

Ntxig cov lus ntawd rau hauv cov lus.json file:

[{"lo lus": "Lebensabschnittpartner", "piav qhia": "Lo lus no tau piav ntau tshaj li lwm qhov kev xaiv rau tus khub lossis tus hlub, tab sis nrog kev hloov pauv ntau dua." }, {"lo lus": "Unabhängigkeitserklärungen", "piav qhia": "Lo lus no piav qhia txog kev tshaj tawm ntawm kev ywj pheej." }, {"lo lus": "Freundschaftsbezeugung", "piav qhia": "Nws yog kev qhia ua phooj ywg." }, {"lo lus": "Rechtsschutzversicherungsgesellschaften", "piav qhia": "Phau Ntawv Guinness Phau Ntawv Teev Npe Ntiaj Teb lees paub lo lus nyuaj no yog lo lus German ntev tshaj plaws hauv kev siv niaj hnub. Nws txhais tau tias cov tuam txhab pov hwm muab kev tiv thaiv raug cai." }, {"lo lus": "Kaftfahrzeug-Haftpflichtversicherung", "piav qhia": "Nws hais txog kev tuav pov hwm lub tsheb loj." }, {"lo lus": "Donaudampfschiffahrtsgesellschaftskapitän", "piav qhia": "Lo lus no txuas ntxiv lub ntsiab lus ntawm kev thauj mus los, thiab yog plaub lo lus sib dhos ua ke kom hais tau Danube lub nkoj ua lag luam tus thawj coj." }]

Tau kawg koj tuaj yeem ntxiv cov lus yog tias koj paub qee yam. Tab sis rau kev sim nws yuav tsum tau ua haujlwm.

Nyem rau Txuag thiab Deploy dua.

Kauj Ruam 7: Ntxiv Cov Neeg Ua Haujlwm Xav Tau

Cov kev xav yav dhau los tsim tam sim no xav tau tus tswj hwm, uas yog ua los ntawm lub hom phiaj. NoIntentHandler kaw qhov txuj ci. YesIntentHandler thiab TellAFunnyWordIntentHandler teb nrog cov lus lom zem thiab nws cov lus piav qhia.

Rho tawm tag nrho HelloWorldIntentHandler los ntawm cov ntawv index.js thiab ntxiv peb qhov tshiab los hloov:

const TellAFunnyWordIntentHandler = {

canHandle (handlerInput) {xa Alexa.getRequestType (handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName (handlerInput.requestEnvelope) === 'TellAFunnyWordIntent'; }, handle (handlerInput) {const words = JSON.parse (fs.readFileSync ('./ words.json')); const lo lus = lo lus [Math.floor (Math.random () * words.length)]; const hais lusOutput = word.word + '. ' + lo lus.explanation; xa rov qab handlerInput.responseBuilder.speak (speakOutput).getResponse (); }}; const YesIntentHandler = {canHandle (handlerInput) {return Alexa.getRequestType (handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName (handlerInput.requestEnvelope) === 'AMAZON. YesIntent'; }, handle (handlerInput) {const words = JSON.parse (fs.readFileSync ('./ words.json')); const lo lus = lo lus [Math.floor (Math.random () * words.length)]; const hais lusOutput = word.word + '. ' + lo lus.explanation; xa rov qab handlerInput.responseBuilder.speak (speakOutput).getResponse (); }}; const NoIntentHandler = {canHandle (handlerInput) {return Alexa.getRequestType (handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName (handlerInput.requestEnvelope) === 'AMAZON. NoIntent'; }, tuav (handlerInput) {const speakOutput = 'Okay, tej zaum lwm lub sijhawm.'; xa rov qab handlerInput.responseBuilder.speak (speakOutput).getResponse (); }};

Kauj Ruam 8: Sau npe Cov Neeg Ua Haujlwm Xav Tau

Tam sim no peb yuav tsum sau npe tus tswv lub hom phiaj tshiab. Txog qhov ntawd, nqes mus rau qhov kawg ntawm cov ntawv index.js.

Hloov qhov no:

xa tawm.handler = Alexa. SkillBuilders.custom ()

.addRequestHandlers (LaunchRequestHandler, HelloWorldIntentHandler, HelpIntentHandler, ยกเลิก

nrog ntawd:

xa tawm.handler = Alexa. SkillBuilders.custom ()

.addRequestHandlers (LaunchRequestHandler, TellAFunnyWordIntentHandler, YesIntentHandler, NoIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler, SessionEndedRequestHandler, IntentReflectorHandler, // ua kom yuam kev (tsis txhob yuam kev)

Tom qab ntawv nyem rau Save thiab Deploy dua. Tom qab qhov kev xa tawm tau ua tiav qhov kev sim dua.

Kauj Ruam 9: Xeem Txuj Ci

  1. Nyem rau ntawm Test tab → Lub qhov rai tshiab qhib.
  2. Sau lossis hais lus: "oppen lus txaus luag German" skill Cov txuj ci tam sim no yuav tsum teb nrog kev tos txais.
  3. Sau lossis hais lus: "qhia kuv cov lus german lom zem" → Cov txuj ci tam sim no yuav tsum qhia ib qho ntawm cov lus.

Yog tias txhua yam ua haujlwm, koj tuaj yeem xa koj cov txuj ci.

Kauj Ruam 10: Teeb Ua Ntej Ua Ntej Ua Ntej thiab Xa rau Tshawb Xyuas

Teem Skill Preview thiab Xa rau Kev Tshuaj Xyuas
Teem Skill Preview thiab Xa rau Kev Tshuaj Xyuas

Sau tag nrho cov ntawv xav tau nrog koj tus kheej piav qhia txog kev txawj.

Ntawm Piv Cov Kab lus sau:

  • Alexa, qhib Cov Lus German Funny.
  • Alexa, nug Cov Lus German Zoo los qhia kuv cov lus lom zem.

Tom qab koj tau ua tiav txhua qhov chaw xav tau thiab tom qab koj tau rub tawm cov cim, nyem rau Txuag thiab txuas ntxiv.

Xaiv cov lus teb raug ntawm Tsis pub twg paub & Sib piv thiab ntawm Kev Muaj.

Thov ua tibzoo saib daim ntawv teev npe xa ua ntej xa

Tam sim no koj yuav tsum tau ua qee qhov kev xeem. Qhov no tuaj yeem siv sijhawm me ntsis.

Tom qab ntawd koj tuaj yeem xa koj cov txuj ci los tshuaj xyuas. Nws yuav siv sijhawm 1 lossis 2 hnub kom txog thaum koj tau txais cov lus tawm tswv yim rau koj qhov txuj ci. Yog tias koj ua txhua yam raug, koj qhov txuj ci yuav raug tshaj tawm tom qab tshuaj xyuas.

Yog tias koj xav sim qhov txuj ci dhau los, tab sis nws tseem nyob hauv ntawv pov thawj, koj tuaj yeem siv qhov txuj ci no ib txwm:

www.amazon.com/gp/product/B07ZH9GL9N?ref&ref=cm_sw_em_r_as_dp_uCOJljYBKfNx9

Pom zoo: