Cov txheej txheem:

"Alexa, Xa Kuv Cov Ntawv rau _____": 9 Kauj Ruam (nrog Duab)
"Alexa, Xa Kuv Cov Ntawv rau _____": 9 Kauj Ruam (nrog Duab)

Video: "Alexa, Xa Kuv Cov Ntawv rau _____": 9 Kauj Ruam (nrog Duab)

Video:
Video: Ib lo lus Remix Dj - Super zab _ Mob lub siab ua luaj no - Nkauj tshiab 2023 2024, Hlis ntuj nqeg
Anonim
Image
Image

Mloog nkauj uas koj xav hu nrog? Koj ib txwm yuav tsum tau mus dhau txoj haujlwm nyuaj ntawm kev ntaus cov nkauj lub npe rau hauv google, tom qab ntawd lo lus "lyrics". Koj kuj tseem ib txwm ua kom muaj ntau qhov yuam kev, ua yuam kev ib qho ntawm cov yuam sij, thiab yuav tsum ua nrog koj lub cuab yeej qhov kev lag luam tsis pom kev. Los ntawm lub sijhawm koj tau pom cov lus, koj pom tias koj zaj nkauj dhau mus thiab txhua qhov haujlwm ntawd tsis muaj dab tsi.

Tej zaum koj nyob nruab nrab ntawm kev sib kis thoob ntiaj teb thiab qiv koj tus phooj ywg lub xov tooj tsis zoo li lub tswv yim loj tshaj, tsis tshua kov lub tshuab Karaoke uas nyob hauv lub ces kaum. Koj xav tau kev tiv thaiv, tab sis paub cov ntsiab lus rau zaj nkauj yuav luag yog qhov tseem ceeb. Koj xav tau txoj hauv kev yooj yim, tsis muaj kev sib cuag los tshawb nrhiav cov nkauj.

Tej zaum ob qho xwm txheej no yog qhov hais me ntsis (thawj qhov yog qhov tseeb dua), tab sis tseem, muaj cov nkauj nkauj xa ncaj qha rau koj tus email thib ob uas koj thov kom lawv xa tuaj yuav yooj yim heev. Qhov ntawd yog Qhov Qhia Ntawv (nrog rau Alexa, Wayscript thiab Python me ntsis) los rau hauv. Tsuas yog nug Alexa rau cov nkauj rau koj cov nkauj nyiam thiab hauv ob peb feeb lawv yuav xa ncaj qha rau koj lub inbox.

Raws li cov tub ntxhais kawm theem siab nkag mus rau kuv xyoo xyoo laus, kuv tau pom qhov haujlwm no muaj txiaj ntsig zoo thiab tau siv nws qhov txiaj ntsig tseem ceeb txij li tau tsim nws (tsis tshua muaj neeg pom - feem ntau ntawm kuv cov phiaj xwm tau pom tsis pom lub hlis tom qab).

Cov ntawv qhia no yog qib pib zoo nkauj, tab sis nws yog qhov muaj txiaj ntsig kom paub qee Python ua ntej nkag mus.

Khoom siv

Cov ntaub ntawv:

  1. Amazon Echo/Txhua Tus Alexa-Raws Tus Hais Lus Ntse
  2. WayScript tus account (Yuav tau teeb tsa hauv cov theem hauv qab no)
  3. Tus account RapidAPI
  4. Qee Qhov Kev Paub Python (Tsis tsim nyog, tab sis pab tau)

Kauj ruam 1: Teeb Wayscript thiab Alexa

Teeb Wayscript thiab Alexa
Teeb Wayscript thiab Alexa
Teeb Wayscript thiab Alexa
Teeb Wayscript thiab Alexa
Teeb Wayscript thiab Alexa
Teeb Wayscript thiab Alexa

Wayscript yog dab tsi?

Wayscript yog cov cuab yeej muaj zog uas tso cai rau koj los khiav cov haujlwm siv ntau yam ua rau. Peb yuav siv lub Alexa txhais hauv Cov Lus Qhia no, tab sis xav tias yuav sim/tshawb xyuas software - muaj txhua yam kev ua haujlwm uas koj tuaj yeem ntxiv.

Txhawm rau pib, cia ua tus lej nrog Wayscript:

  1. Nyem rau ntawm 'Pib Pib Dawb' lossis 'Sau Npe' cov nyees khawm. Kuv siv qhov 'Sau npe nrog Github' xaiv raws li nws xav tias yooj yim tshaj plaws.
  2. Thaum koj tau ua tus as khauj, koj yuav yog tus coj mus rau Wayscript txoj kev txhim kho ib puag ncig. Nws yog qhov muaj txiaj ntsig zoo los ntawm kev qhia ua ntej peb pib.
  3. Thaum koj tau ua tiav qhov kev qhia, mus rau koj qhov profile. Nyem rau ntawm 'Tsim tsab ntawv tshiab' khawm thiab koj yuav raug nug kom sau koj lub phiaj xwm. Kuv tau hu nws 'Song Lyrics', tab sis koj tuaj yeem sau nws txhua yam koj xav tau. Tsuas yog xyuas kom nws yooj yim hais raws li koj yuav siv lub npe program thaum nug Alexa xa koj cov nkauj.
  4. Thaum koj tau ua koj lub npe, nyem rau 'tsim' khawm thiab koj yuav yog tus coj mus rau Txoj Kev Tsim Kho Tshiab Txoj Kev. Peb yuav rov qab los sai sai no.

Ua ntej peb txuas ntxiv, cia peb txuas koj li Wayscript account rau Alexa:

  1. Lub taub hau hla mus rau amazon.com thiab nkag mus rau koj tus lej nyiaj-tshwj xeeb yog ib qho uas txuas nrog koj tus neeg hais lus Alexa.
  2. Mus rau qhov txuas no: https://www.amazon.com/WayScript-Inc/dp/B07QXXG32… thiab nyem 'pab kom'. Yog tias qhov txuas tsis ua haujlwm vim li cas los xij, tshawb rau Wayscript Alexa Skill - dua, nyem 'pab'
  3. Thaum koj tau nyem qhib, koj yuav tsum txuas nws mus rau koj tus lej Wayscript. Nyem 'Txuas Tus Kheej' thiab koj yuav tsum raug coj mus rau lub vev xaib lub vev xaib. Thaum koj nkag mus rau hauv, ib qho screen hais tias 'Koj tus account tau txuas nrog ua tiav' yuav tsum tshwm sim.

Thaum koj tau teeb tsa txhua qhov no, peb tuaj yeem (yuav luag) pib ua haujlwm!

Kauj Ruam 2: Ua Tus Zauv RapidAPI

Ua tus lej RapidAPI
Ua tus lej RapidAPI
Ua tus lej RapidAPI
Ua tus lej RapidAPI
Ua tus lej RapidAPI
Ua tus lej RapidAPI

Txhawm rau tshawb nrhiav zaj nkauj cov nkauj, peb yuav siv 'Canarado Lyrics API' uas nkag tau los ntawm RapidAPI. Yog tias koj twb muaj tus lej RapidAPI, koj tuaj yeem hla cov kauj ruam no, tab sis yog tias tsis yog, nyeem txuas ntxiv.

Pib los ntawm kev ua koj tus lej RapidAPI:

  1. Nyem rau 'Sau Npe' Khawm nyob ze rau saum kaum sab xis thiab kos npe nrog ib qho ntawm cov kev xaiv uas lawv muaj (Google, Github, Facebook lossis sau npe tsis tu ncua).
  2. Thaum koj tau kos npe, nkag mus rau Canarado Lyrics API:

Yog tias koj pom lub vijtsam zoo ib yam li daim duab thib peb txuas saum toj no, koj tau ua tiav cov theem no. Peb thaum kawg tau npaj pib lub program.

Kauj Ruam 3: Sau Qhov Txheej Txheem

Sau ib qho Program Basic
Sau ib qho Program Basic
Sau ib qho Program Basic
Sau ib qho Program Basic
Sau ib qho Program Basic
Sau ib qho Program Basic

Raws li tau hais hauv qib dhau los, Canarado Lyrics API nyob ntawm:

Thaum muaj, lub taub hau mus rau sab xis ib nrab ntawm qhov screen nrog lub taub hau 'Code Snippets'. Kuv yuav siv Python hauv cov lus qhia no, tab sis yog tias koj xav tau lwm yam lus ua ntej thiab siv qhov ntawd.

Nyem rau ntawm cov ntawv qhia zaub mov nco nrog daim ntawv lo '(Node.js) Tsis Txaus Siab' thiab mus rau koj hom lus uas koj xaiv. Ib zaug ntxiv, Kuv yuav siv Python - tshwj xeeb Python (Thov) - raws li txoj haujlwm no xav tau kev thov rau API tus tswv rau feem ntau ntawm cov ntaub ntawv. Luam cov cai los ntawm txhaj rau lub pob 'theej code' nyob ze rau sab xis saum toj. Muab tus lej no tso rau hauv koj tus lej editor uas kuv xaiv - Kuv yuav siv Jupyter's Phau Ntawv ib puag ncig.

Thaum koj tau dhau qhov program, ntshuam Python's json module. Qhov no yuav pab kom peb luam tawm cov nkauj. Ntxiv cov cai hauv qab no nyob ze rau saum (hauv qab thov kev thov ntshuam)

ntshuam json

Thaum koj tau import json module, koj qhov program yuav tsum zoo li no:

ntshuam thov

ntshuam json url = "https://canarado-lyrics.p.rapidapi.com/lyrics/zenith%2520denzel%2520curry" headers = {'x-rapidapi-host': "canarado-lyrics.p.rapidapi.com", 'x-Rapidapi-key': "KOJ-API-KEY-HERE"} teb = thov.request ("Tau", url, headers = headers) print (teb lus.text)

Ua kom ntseeg tau tias koj cov haujlwm zoo ib yam (nrog API sib txawv) thiab tom qab ntawd nkag mus rau 'url' sib txawv. Koj yuav pom tias Canarado qhov ntsuas tsis raug yog 'Zenith' los ntawm Denzel Curry. Koj tuaj yeem hloov qhov ntawd los ntawm kev nkag ib zaj nkauj uas koj nyiam. Piv txwv li, yog tias kuv xav tshawb nrhiav cov ntsiab lus hais txog Michael Jackson's Thriller, Kuv tuaj yeem nkag mus "thriller" nyob rau qhov chaw "zenith denzel curry", xws li qhov url tam sim no zoo li:

url = "https://canarado-lyrics.p.rapidapi.com/lyrics/thriller"

Koj kuj tseem tuaj yeem ntxiv qhov chaw yam tsis muaj kev poob siab - browser yuav cia li ntxiv %2520 tus cim (Koj yuav pom lawv nyob rau qhov chaw ntawm qhov chaw hauv qhov URL tsis yog). Piv txwv li, kev tshawb nrhiav Gangstas Paradise yuav zoo li no:

url = "https://canarado-lyrics.p.rapidapi.com/lyrics/gangstas vaj kaj siab"

Khiav qhov kev zov me nyuam los ntawm kev hloov pauv tus nqi "zenith%2520denzel%2520curry" nrog txhua zaj nkauj uas koj xaiv. Koj yuav pom tias cov ntawv tau luam tawm, tab sis nyeem nyuaj. Dab tsi ntxiv - lwm cov ntaub ntawv, suav nrog hnub tso tawm nkauj, npe thiab API cov xwm txheej xwm txheej cuam tshuam qhov pom ntawm zaj nkauj. Wb kho qhov no hauv cov kauj ruam tom ntej.

Kauj ruam 4: Formatting Lyrics

Formatting Cov Ntawv
Formatting Cov Ntawv

Kev tsim cov lus xws li lawv nyeem tau yooj yim tsis nyuaj. Cov neeg feem coob nrog qee qhov kev paub txog lub cajmeem yuav tuaj yeem ua qhov no yooj yim zoo nkauj. Hloov chaw yooj yim luam tawm "teb lus.text", cia peb siv.json () txuj ci. Qhov no yuav teeb tsa API cov ntaub ntawv rau hauv phau ntawv txhais lus thiab ua txhua yam kom nkag tau yooj yim dua.

Txhawm rau pib, tsim qhov sib txawv los tuav 'response.json ()'. Kuv tau hu kuv qhov hloov pauv 'cov ntaub ntawv'.

cov ntaub ntawv = response.json ()

Tom ntej no, siv cov hauv qab no 'rau' lub voj kom nkag tau cov nkauj.

rau kuv hauv cov ntaub ntawv ['cov ntsiab lus']:

print (kuv ['lyrics'])

Cov cai saum toj no mus rau phau ntawv txhais lus cov ntsiab lus 'cov ntsiab lus'. Tsis pub dhau cov ntsiab lus tseem ceeb, rau lub voj tso cai rau koj mus rau lub ntsiab lus 'ntsiab lus'. Tam sim no cov cai yuav tsum zoo ib yam li qhov no:

ntshuam thov

ntshuam json url = "https://canarado-lyrics.p.rapidapi.com/lyrics/YOUR-SONG- HERE" headers = {'x-rapidapi-host': "canarado-lyrics.p.rapidapi.com", 'x-rapidapi-key': "KOJ-API-KEY-HERE"} teb = thov.request ("Tau", url, headers = headers) data = response.json () rau kuv hauv cov ntaub ntawv ['ntsiab lus']: print (kuv ['lyrics'])

Khiav qhov program no thiab koj yuav pom tias cov nkauj tau nyeem ntau dua. Hauv cov kauj ruam tom ntej peb yuav ntxiv ob peb qhov hloov pauv ntxiv, yog li peb tuaj yeem siv cov nkauj lub npe los ua cov lus nkag thiab kom peb tuaj yeem tso cov nkauj mus rau Alexa.

Kauj Ruam 5: Tawm tswv yim thiab tso tawm

Input's thiab Output's
Input's thiab Output's
Input's thiab Output's
Input's thiab Output's

Txog tam sim no, peb tau sau cov nkauj lub npe ntawm qhov kawg ntawm URL. Nws yuav zoo yog tias peb tuaj yeem siv qhov sib txawv los ntawm kev nkag mus thiab sib txuas ob txoj hlua (url thiab npe nkauj). Ua qhov ntawd yog qhov yooj yim zoo nkauj.

Rau lub sijhawm tam sim no, cia siv Python qhov kev ua haujlwm nkag. Thaum peb xa cov cai rau Wayscript, peb yuav siv peb cov lus hais los ua kev tawm tswv yim xwb. Cia peb tsim cov nkauj npe hloov pauv tau teeb tsa rau cov lus nkag uas nug rau tus neeg siv "nkag mus rau lub npe nkauj":

song_title = input ("Sau nkauj kom pom cov nkauj rau:")

Tom qab ntawd, txuas cov hlua no rau qhov url, siv Python's '+' tus neeg teb xov tooj rau Cov hlua

url = "https://canarado-lyrics.p.rapidapi.com/lyrics/" + nkauj_title

Tam sim no, thaum koj ua haujlwm program, koj tsis tas yuav kho qhov url hauv qhov haujlwm. Hloov chaw, tsuas teb rau cov lus nkag nrog koj zaj nkauj lub npe, thiab zaj nkauj zaj nkauj yuav tsum luam tawm.

Koj qhov program yuav tsum zoo li qhov no:

ntshuam thov

ntshuam json nkauj = nkag ("Sau nkauj kom pom cov nkauj rau:") url = "https://canarado-lyrics.p.rapidapi.com/lyrics/" + nkauj headers = {'x-rapidapi-host': "canarado-lyrics.p.rapidapi.com", 'x-rapidapi-key': "KOJ-API-KEY-HERE"} teb = thov.request ("Tau", url, headers = headers) cov ntaub ntawv = teb.json () rau kuv hauv cov ntaub ntawv ['cov ntsiab lus']: luam tawm (kuv ['lyrics'])

Thaum kawg, cia peb tsim qhov sib txawv los tso cov nkauj. Pib los ntawm kev tsim qhov sib txawv teeb tsa rau txoj hlua khoob. Tom qab ntawd, txuas 'i [' lyrics ']' rau qhov kawg ntawm nws. Luam tawm qhov txawv txav sab nraud ntawm lub voj.

lus = ""

rau kuv hauv cov ntaub ntawv ['ntsiab lus']: nkauj += kuv ['lyrics'] luam tawm (cov lus)

Qhov kev zov me nyuam kawg yuav tsum zoo li no:

ntshuam thov

ntshuam json nkauj = nkag ("Sau nkauj kom pom cov nkauj rau:") url = "https://canarado-lyrics.p.rapidapi.com/lyrics/" + nkauj headers = {'x-rapidapi-host': "canarado-lyrics.p.rapidapi.com", 'x-rapidapi-key': "KOJ-API-KEY-HERE"} teb = thov.request ("Tau", url, headers = headers) cov ntaub ntawv = teb.json () lyrics = "" rau kuv hauv cov ntaub ntawv ['cov ntsiab lus']: cov ntawv += kuv ['lyrics'] luam tawm (cov lus)

Qhov kev zov me nyuam yuav luam tawm qhov tseeb ib yam, tab sis tam sim no koj muaj qhov sib txawv uas koj tuaj yeem siv ua qhov tso tawm. Tam sim no, thaum kawg peb tuaj yeem ntxiv Alexa thiab Email ua haujlwm nrog Wayscript.

Kauj Ruam 6: Ntxiv Alexa Trigger

Ntxiv Alexa Trigger
Ntxiv Alexa Trigger
Ntxiv Alexa Trigger
Ntxiv Alexa Trigger
Ntxiv Alexa Trigger
Ntxiv Alexa Trigger

Txhawm rau ntxiv koj thawj qhov tshwm sim, nyem rau ntawm 'Add Trigger' khawm:

  1. Qhov tshawb nrhiav yuav tshwm - tshawb rau 'Alexa' thiab koj yuav pom qhov Alexa txhais. Yog tias koj tsis tau siv Alexa txhais ua ntej rau qhov no, lossis yog tias qhov no yog koj thawj qhov haujlwm, koj yuav tau nyem 'ntshuam'. Thaum tuaj txawv teb chaws, tsuas yog nyem rau nws, thiab nws yuav tsum tau ntxiv.
  2. Pab kom lub ntsuas los ntawm txhaj rau lub ntsiav tshuaj zoo li tus hloov. Nws yuav tsum ntsuab. Ntawm sab laug, koj yuav pom ib ntu uas hais tias 'Outputs'. Nyem rau ntawm lub npov uas hais tias 'Hais Lus Hais Lus' thiab nkag mus rau tus nqi zoo ib yam li peb zaj nkauj yav dhau los yav dhau los. Tam sim no peb tuaj yeem siv koj cov lus hais los ntawm cov lus hais tawm uas peb tau siv yav tas los
  3. Ua kom ntseeg tau tias koj tau sau qhov tsis raug (koj nyiam nkauj tej zaum), zoo li tsis muaj ib qho koj yuav ntsib qee qhov yuam kev.

Hauv cov kauj ruam tom ntej, peb yuav ntxiv peb Txoj Haujlwm Python, Xa Email txoj hauv kev thiab peb yuav muaj Alexa lees paub tias txoj hauv kev tau ua tiav.

Kauj Ruam 7: Ntxiv Koj Txoj Haujlwm Python

Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python
Ntxiv Koj Txoj Haujlwm Python

Txhawm rau ntxiv koj cov haujlwm rau koj li kev siv Wayscript tam sim no, nyem rau ntawm 'Ntxiv Kauj Ruam'

  1. Tshawb nrhiav Python thiab nyem rau ntawm Python kev nqis tes ua. Qhov no yuav tsum rov ua dua tshiab thiab koj yuav pom daim ntawv sab laug tshwm.
  2. Hover hla txoj haujlwm ntawm lub vaj huam sib luag sab thiab koj yuav pom qhov 'Kho Cai' khawm pop up. Nyem rau nws thiab tus kws tshuaj ntsuam puv npo yuav tshwm sim.
  3. Hauv qhov khoos phis tawj puv npo, theej thiab muab cov program nab nab uas peb tau tsim yav tas los.
  4. Rho tawm song_title = input ("….") Qhov sib txawv peb tau sau thiab ntxiv cov lus hais sib txawv uas peb tau tsim hauv cov kauj ruam dhau los. Cov kev hloov pauv uas tau tsim hauv cov kauj ruam dhau los tuaj yeem pom nyob hauv qab kaum sab laug.
  5. Koj qhov haujlwm tshiab yuav tsum zoo ib yam li daim duab 6 txuas rau saum toj no.
  6. Thaum kawg, peb xav teeb tsa peb cov nkauj sib txawv raws li qhov tso tawm. Txhawm rau ua qhov no, theej thiab luam cov cai hauv qab no hauv qab ntawm koj qhov haujlwm (hauv qab no lossis qhov chaw ntawm daim ntawv tshaj tawm)

variables ['Song_Lyrics'] = lyrics

Qhov no tsim qhov sib txawv tso tawm hu ua Song_Lyrics thiab teeb nws sib npaug rau 'cov ntsiab lus' sib txawv uas peb tau tsim ua ntej. Koj qhov haujlwm kawg yuav tsum zoo ib yam li cov duab kawg txuas rau saum toj no. Khiav cov cai ib zaug nkaus xwb - yog li ntawd Wayscript paub tias muaj dab tsi tshwm sim thiab tuaj yeem tsim koj li kev hloov pauv. Qhov no yuav siv sijhawm me ntsis, tab sis yog tias nws siv sijhawm ntev heev, koj yuav tau rov ua nplooj ntawv dua. Wayscript muaj ob peb kab, yog li qhov xwm txheej tsis zoo tuaj yeem suav nrog kev rov tsim tsab ntawv.

Kauj Ruam 8: Xa Cov Ntawv thiab Pom Zoo Nrog Alexa

Xa Cov Ntawv thiab Pom Zoo Nrog Alexa
Xa Cov Ntawv thiab Pom Zoo Nrog Alexa
Xa Cov Ntawv thiab Pom Zoo Nrog Alexa
Xa Cov Ntawv thiab Pom Zoo Nrog Alexa
Xa Cov Ntawv thiab Pom Zoo Nrog Alexa
Xa Cov Ntawv thiab Pom Zoo Nrog Alexa

Peb muaj ob kauj ruam ntxiv los ntxiv rau peb txoj kev WayScript - ib kauj ruam uas tso cai rau koj xa email rau koj tus kheej thiab lwm qhov uas lees paub tias email tau xa tuaj. Cia peb pib los ntawm kev tsim email kauj ruam.

  1. Nyem 'Ntxiv Kauj Ruam', tshawb rau 'Xa Email' thiab nrhiav lub tab sab laug
  2. Siv qhov hloov pauv tau tsim hauv cov kauj ruam dhau los xws li 'Song_Name' (lossis Song_Title) thiab 'Song_Lyrics'
  3. Koj tuaj yeem ua tus email li cas koj xav tau. Piv txwv li, Kuv tau ntxiv lo lus "Cov Ntawv" tom qab 'Song_Name' sib txawv thiab tau ntxiv kab lus "Nov yog cov nkauj rau zaj nkauj koj thov" nyob ze rau saum.

Tsab ntawv no yuav xa lus mus rau email uas koj tau sau npe nrog. Yog tias koj xav xa nws mus rau lwm tus email, tej zaum koj yuav tsum siv SMTP Email Ua Haujlwm hloov.

Thaum kawg, cia peb lees paub tias email tau xa nrog Alexa.

  1. Nyem 'Ntxiv Kauj Ruam' thiab tshawb rau 'Alexa' dua. Ntxiv qhov Alexa nqis tes ua.
  2. Kuv tau teeb tsa nws kom thaum xa email, Alexa hais tias 'Lyrics rau [Nkauj_Name] tau xa tuaj'

Koj ua tiav! Khiav qhov kev zov me nyuam ib zaug los ntawm txhaj 'Khiav' khawm. Yog tias tsis muaj qhov yuam kev, tam sim no koj tuaj yeem siv nws nrog Alexa.

Kauj ruam 9: Koj tau ua tiav

Txhawm rau siv nws nrog Alexa, koj yuav tsum siv cov lus txib hauv qab no:

'Alexa, tso tawm Wayscript'

Thaum Alexa tau lees paub tias Wayscript tau pib, hais tias:

'Khiav [Lub Npe Txoj Haujlwm] nrog [Nkauj Lub Npe]'

Piv txwv li, kuv qhov program hu ua 'Song Lyrics' - Yog tias kuv xav Alexa xa kuv cov nkauj mus rau Thriller, Kuv yuav hais:

'Khiav Nkauj Lyrics nrog Thriller'

Pom zoo: