How to Upload Mp3s to Play on Amazon Echo

Exercise you ain a huge MP3 collection and you want to be able to listen it on your Alexa device? Are y'all an aspiring ring and want to share your music with your fans for free? Or maybe you lot are just curious most how the Alexa Music Skill works.

Photo by Lazar Gugleta on Unsplash

In the following article I will try to explicate how to build a simple music streaming service. You lot can detect the complete source code here: https://github.com/andrei-ace/music-deject

Your Amazon Alexa will be able to reply to commands similar:

  • "Alexa, play music on skill name."
  • "Alexa, play songs by artist proper name on skill name."
  • "Alexa, play the vocal name on skill name."

The songs are from your own private collection, no need to purchase them once again or pay a subscription. Certain, you tin can connect and stream from your phone like with whatsoever other bluetooth speakers, but where is the fun in that? Y'all volition miss all the vocal commands you lot tin can use with Alexa Music Skill.

Let's brainstorm

Prerequisites

  • An Amazon developer account. Sign up is gratis.
  • An AWS business relationship. You host your skill code as an AWS Lambda function. Make sure this is an United states account.
  • A Dropbox Bones (free) account

Step 1 — install all the tools you need

  • Install npm
  • Install awscli
  • Install ask cli and configure AWS credentials
  • Generate an access token for your Dropbox account

Step ii — DynamoDB

Go to AWS Console and create a new table named cloud-music with primary primal id of type Cord and a secondary index named artist_id-id-index with master central artist_id and a Sort key named id:

Provision read and write capacity to not exceed 5 read and 5 write units. This will go on you in the AWS free tier.

Go to IAM and add "dynamodb:*" permissions for the inquire user.

Pace 3 — upload your MP3 files to Dropbox and create your music catalog

            $ git clone https://github.com/andrei-ace/music-cloud
$ cd music-cloud/dropbox-catalog/
$ npm install
#edit .env.template with your Dropbox access token $ node index upload -d ./mp3/
$ node index.js catalog

You lot should see the list of your MP3 files:

The first command, for each MP3 file from the ./mp3/ directory it will:

  • read the ID3 tags — please make sure each file has at to the lowest degree the creative person and the championship
  • upload the file to Dropbox
  • create a shareable link
  • save the ID3 tags and the shareable link to the deject-music table

The 2nd command will create ii files: artists.json and songs.json. These 2 files represent the catalogs which will be uploaded to Alexa and make information technology understand your music collection.

Pace four — create your Alexa Skill

Become to Alexa Developer Console and create a new skill named "Music Cloud". Cull the Music model and press Create skill button. Go to Build tab and press the Endpoint menu (left). Copy the skill id.

Footstep 5 — create your Lambda function

Go to AWS Lambda functions and create a new function named MusicCloudLambda as described here. Make sure your execution role contains permissions for accessing DynamoDB:

            "Action": [
"dynamodb:BatchGetItem",
"dynamodb:PutItem",
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:Query"
],
"Resource": "*"

It should await like this:

Copy the Lambda's ARN (from the upper right corner: ARN — arn:aws:lambda:usa-east-1:*:function:MusicCloudLambda) and go back to your Alexa Skill -> Build -> Endpoint and paste it into the Default endpoint field. Save.

Step 6 — deploy the skill code

Edit the .ask/config.template file with your skill id and lambda ARN. Rename the file to .ask/config. Deploy:

            $ inquire-cli deploy          

Footstep vii — upload the catalog files to Alexa

Start, let'south create the artists catalog:

            $ ask api create-catalog --catalog-type AMAZON.MusicGroup --itemize-title catalog-artists --catalog-usage AlexaMusic.Catalog.MusicGroup          

Save the itemize id and associate it to your Alexa Skill.

            $ enquire api associate-catalog-with-skill -s YOUR-SKILL-ID-Here -c YOUR-ARTISTS-CATALOG-ID-HERE          

Replace the YOUR-SKILL-ID-Here and YOUR-ARTISTS-Catalog-ID-HERE with your skill and creative person catalog id values.

Now let's upload the artists.json file:

            $ enquire api upload-catalog -c YOUR-ARTISTS-CATALOG-ID-HERE -f ./artists.json          

Relieve the upload id, you'll need information technology later to check the condition of the upload.

Build better voice apps. Get more manufactures & interviews from vocalisation applied science experts at voicetechpodcast.com

Now practice the same for the song catalog:

            $ ask api create-itemize --catalog-blazon AMAZON.MusicRecording --catalog-title catalog-songs --catalog-usage AlexaMusic.Catalog.MusicRecording            $ ask api acquaintance-catalog-with-skill -s YOUR-SKILL-ID-Hither -c YOUR-SONGS-Itemize-ID-HERE            $ inquire api upload-itemize -c YOUR-SONGS-Catalog-ID-Here -f ./songs.json          

Save the upload id, yous'll demand it afterward.

Step 8 — expect for the catalogs to be processed

Use the upload ids for both artist and song catalog to query for the upload status.

            $ ask api get-catalog-upload -c YOUR-SONGS-Itemize-ID-Hither -u YOUR-SONGS-UPLOAD-ID-HERE            $ ask api get-catalog-upload -c YOUR-ARTISTS-Catalog-ID-Here -u YOUR-ARTISTS-UPLOAD-ID-HERE          

Only subsequently the ER_INGESTION step succeeds you can consequence commands in the Test Console.

Yous tin can find more about catalogs here.

Step ix— examination your Alexa Skill

Go to Alexa Developer Console -> Music Cloud skill -> Test tab and issue some test commands. If everything worked yous should see something like this:

Don't worry if you run into the warning: "AudioPlayer is currently an unsupported namespace." in the test panel, that is normal. You will be able to listen to your songs on a real device similar an Amazon Echo (or similar) that is linked with your developer business relationship.

How this music skill works

Catalog

In that location are 6 types of catalogs:

In our example nosotros created catalogs merely for the kickoff two types — artists and songs.

An artist catalog looks like:

            {...
"entities":[
{
"id":"g5NYvQMbvrqv76x+ItEErv5MJpE=",
"names":[
{
"language":"en",
"value":"SemMueL"
}
],
"popularity":{
"default":100
},
"lastUpdatedTime":"2019-10-08T14:51:23.326Z",
"deleted":false
}
]
}

A song catalog looks similar:

            {...
"entities":[
{
"id":"wuoQvgudnob9GJeKtqQxrAovVtY=",
"names":[
{
"language":"en",
"value":"Back in Time (Feat: Dylan Anthony Clark, Breanne Ponack)"
}
],
"popularity":{
"default":100
},
"lastUpdatedTime":"2019-10-08T14:51:18.849Z",
"artists":[
{
"id":"g5NYvQMbvrqv76x+ItEErv5MJpE=",
"names":[
{
"language":"en",
"value":"SemMueL"
}
]
}
],
"albums":[],
"deleted":simulated
}
]
}

Alexa Music Skill API

There are 4 types of requests that are mandatory for any music skill:

  • GetPlayableContent — this request is sent when a user requests content to be played from your skill. If a user says: "Alexa, play It's my life past Bon Jovi on music skill name" your skill will need to return the ContentId of that track as listed in your Amazon.MusicRecording catalog. If no entry can exist found, an error bulletin needs to be returned.
  • Initiate — is sent when Alexa is ready for immediate playback of content obtained using a GetPlayableContent request. Alexa will send the ContentId and the skill responds with the stream URI.
  • GetNextItem — is sent when a content queue was created, playback has started and Alexa needs the adjacent item to buffer/enqueue for shine song transition or if the user skipped the current item.
  • GetPreviousItem — is sent when the content is playing and the user requests for the previous item.

GetPlayableContent

The skill needs to respond to 3 types of requests:

  • "Alexa, play music on Music Cloud"
  • "Alexa, play songs by artist proper name on Music Deject"
  • "Alexa, play song name on Music Cloud"

For the showtime type of request the pick criteria volition look like:

            "selectionCriteria": {
"attributes": [
{
"type": "MEDIA_TYPE",
"value": "Runway"
}
]
}

The Music Deject skill will return a random item from the DynamoDB table.

For the second type the selection criteria will look like:

            "selectionCriteria": {
"attributes": [
{
"blazon": "ARTIST",
"entityId": "A2"
},
{
"type": "MEDIA_TYPE",
"value": "Rail"
}
]
}

The Music Deject skill volition return a random song by the requested artist.

And lastly:

            "selectionCriteria": {
"attributes": [
{
"type": "Rail",
"entityId": "138545995"
},
{
"blazon": "MEDIA_TYPE",
"value": "TRACK"
}
]
}

The skill will return the exact song with the ContendId equal with the requested entityId.

Initiate

The of import office from the Initiate request is:

            "payload": {
"filters": {
"explicitLanguageAllowed": truthful
},
"contentId": "1021012f-12bb-4938-9723-067a4338b6d0",
"playbackModes": {
"shuffle": faux,
"loop": false
}
}

The skill volition need to reply with a playable stream:

            "playbackMethod": {
"blazon": "ALEXA_AUDIO_PLAYER_QUEUE",
"id": "Queue-Id",
"rules": {
"feedback": {
"type": "PREFERENCE",
"enabled": true
}
},
"firstItem": {
"id": "1021012f-12bb-4938-9723-067a4338b6d0",
"playbackInfo": {
"blazon": "DEFAULT"
},
"metadata": {
"blazon": "Track",
"name": {
"speech": {
"type": "PLAIN_TEXT",
"text": "jeremy"
},
"display": "Jeremy"
},
"art": {}
},
"controls": [
{
"type": "Command",
"name": "Side by side",
"enabled": true
}
],
"rules": {
"feedbackEnabled": true
},
"stream": {
"id": "STREAMID_92_14629004",
"uri": "https://cdn.instance.com/api/ane/a2f318467fbf2829996adc0880e0abd03d03b1ba6ac.mp3",
"offsetInMilliseconds": 0,
"validUntil": "2020-05-10T19:11:35Z"
},
"feedback": {
"type": "PREFERENCE",
"value": "POSITIVE"
}
}
}

GetNextItem

This will render a random song. The response information is similar with the Initiate response.

GetPreviousItem

This will return an mistake as the queue is not persisted by the skill at this betoken.

Plans for the hereafter

Some ideas for comeback:

  • Add other types of catalogs (genre, playlists similar: top 100 songs this calendar week, etc)
  • Amend the vocalisation modelling by adding more and better data in the catalogs. An case would exist to provide alternative names for artists, spell out numbers and non-alphabetic characters
  • Track user playlists and vocal popularity
  • Create a music recommendation system (maybe using TensorFlow)

Reference

Something just for you

gillencounto.blogspot.com

Source: https://medium.com/voice-tech-podcast/build-your-own-music-streaming-service-with-amazon-alexa-41c7bf1eb66a

0 Response to "How to Upload Mp3s to Play on Amazon Echo"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel