While bouncing project ideas on the car ride up from College Park, MD to NYU, our hackathon team was listening to a series of mixtapes. Something that interested all of us was to assess the Amazon Echo’s (Alexa) ability to recite and freestyle rap, given certain parameters.
What It Does
Our platform has two main modes; query mode and freestyle mode.
Query Mode: Query mode works by utilizing the search function in RapGenius’ API. Each query is of the form: “Alexa, ask hackathon to rap about my query”. Alexa takes the my query value and uses it as a search parameter to scrape the lyrics of the first result on RapGenius. After doing some preprocessing and lyric sanitization, Alexa will recite the rap. For example, “Alexa, ask hackathon to rap about knees weak arms are heavy”, will prompt Alexa to begin rapping Eminem’s Lose Yourself.
Freestyle Mode: In freestyle mode, Alexa is given a specific artist to emulate. Given the artist, Alexa will create an 8-line freestyle verse that is similar to style of the queried artist. Using RapGenius’ API, we scraped the 50 most popular results of the queried artist and stored each line into a temporary data structure. We then used to DataMuse RhymeZone API to randomly generate the freestyle from the stored rap content we scraped. For example, “Alexa, ask hackathon to rap like Drake’, resulted in the following freestyle:
All my goons so overzealous, I can’t help it, I can’t help it,
I was young and I was selfish,
I made every woman feel like she was mine and no one else’s,
When I look back I might be mad that I gave this attention,
I wanna do the things that I mention,
Who, very important and very pretentious,
I wanna benefit from this friendship,
But it’s like as soon as I cum, I come to my senses
How We Built It
We created a custom skill on the Amazon Echo. This skill captures the string input of the user using and Amazon Lambda function. The Lambda function queries the RapGenius API for that string input and selects the top result. The function then jumps to the corresponding Genius page URL and the webpage is scraped using Beautiful Soup. Using some basic regular expression functionality, we parsed each song into the raw text of verses and chorus sections. Once complete, Alexa then recites the song.
Challenges We Ran Into
Correctly scraping the Genius API for the lyrics of songs was difficult. Genius intended to protect the song lyrics from their API and forced us to create a hack work-around. We also experienced some difficulties setting up the Amazon Echo's custom skills which took a few hours to resolve.
Accomplishments We're Proud Of
Although none of us had ever used the Amazon Echo in a “hacking” capacity, we were surprised that we were able to put our rap program together in only 36 hours.
What We Learned
We learned about Alexa’s functionality and the process of adding new skills. Being able to work with AWS allowed us learned more about the details of their service. This was particularly specific to AWS Lambda, where each Alexa query to the function invoked the Python lyric processing. In the back-end of the script we learned about more about issuing REST commands, specifically with regards to RapGenius' API, and we improved our web scraping skills.
What's Next for "Alexa Rap For Me"
The next stage for this project would be to have Alexa recite the songs in a tone and speed more similar to that of the intended artist. Down the road, it would be interesting to see if we could have Alexa generate her own raps as opposed to creating a song from already existing lyrics.