Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
avatar
Master Guru

As a follow-up to my article on downloading and playing MIDI files (https://community.hortonworks.com/content/kbentry/65154/nifi-1x-for-automatic-music-playing-pipeline...) This quick article highlights how you can support both MP3 and MIDI. As you can see it's very easy to have multiple channels in, multiple processing paths and process many types of inputs and files in NIFI.

9192-flow4.png

So how do we add MP3 playback to our Jukebox?

Add another GetHTTP processor

http://192.168.1.2:8080/extract/url?url=http://www.amclassical.com/piano//&type=mp3

Still using my Microservice to convert web pages into links in JSON, this time filtering out MP3s. Fortunately there's a few web pages out there with free classical MP3s.

Next after UpdateAttribute, I check file extension in a Route on Attribute.

${filename:contains('midi')}

If it's MIDI, call the same MIDI player.

I added a second PutFile to save to /opt/demo/mp3, so that I keep my music files seperately.

Otherwise, call OSX's command line MP3 player.

In my second ExecuteStreamCommand I call /usr/bin/afplay to play those newly downloaded MP3s. It will play and once completed the next song will play. I don't recommend feeding both MIDI and MP3 pages full at the same time. It's best to pick one and let it load up a lot of files in the queues from one type and play those. I keep my GetHTTP's stopped once I get the page in as I don't want more. it is very easy to feed in a list of pages to load, add a scheduler or other feed logic in the start to control your experience. I like to manually control this part so I have control. You could also trigger this by the presence of a file or maybe when a Jenkins build fails. It's limited by your imagination and over 180 processors.

Another thing that can be added to the flow is some Audio Processing via Simon Elliston Ball's Audio Processors, that you can easily add to your NIFI.

https://community.hortonworks.com/content/repo/47306/nifi-audio-processors.html

2,154 Views
Comments
avatar
Master Guru

Next steps, use the audio processor.

Next step generate music with DL4J and TensorFlow.

Next steps connect NIFI to a MIDI synthesizer or Raspberry PI SonicPi.

avatar
Master Guru
hdfs dfs -cat /music/meta/amclassical_beethoven_fur_elise.mp3
{"xmpDM:trackNumber":"","invokehttp.tx.id":"b4690a5a-ec60-4f68-8d1a-de9344eced8d","xmpDM:releaseDate":"2001","Server":"Apache","gethttp.remote.source":"192.168.1.2","xmpDM:artist":"A-M Classical","fragment.identifier":"d8b6da55-c512-42c5-b9a0-a93b0f32fd71","link":"http://www.amclassical.com/mp3/amclassical_beethoven_fur_elise.mp3","dc:creator":"A-M Classical","Last-Modified":"Sun, 05 Oct 2008 20:59:37 GMT","title":"Für Elise","xmpDM:audioChannelType":"Stereo","uuid":"d1e6b6cb-63cc-46a8-ac63-a588da01ecff","invokehttp.request.url":"http://www.amclassical.com/mp3/amclassical_beethoven_fur_elise.mp3","path":"./","xmpDM:logComment":"eng -","xmpDM:audioSampleRate":"44100","dc:title":"Für Elise","OkHttp-Sent-Millis":"1478537014168","segment.original.filename":"mp3.json","Content-Length":"3393536","Content-Type":"audio/mpeg","samplerate":"44100","Keep-Alive":"timeout=2, max=95","xmpDM:genre":"Classical","xmpDM:composer":"Ludwig van Beethoven","X-Parsed-By":"org.apache.tika.parser.DefaultParser, org.apache.tika.parser.mp3.Mp3Parser","creator":"A-M Classical","xmpDM:album":"","meta:author":"A-M Classical","invokehttp.status.code":"200","Connection":"Keep-Alive","fragment.index":"0","xmpDM:audioCompressor":"MP3","mime.type":"audio/mpeg","version":"MPEG 3 Layer III Version 1","Date":"Mon, 07 Nov 2016 16:38:13 GMT","Accept-Ranges":"bytes","descr":"Beethoven: Für Elise","filename":"amclassical_beethoven_fur_elise.mp3","OkHttp-Received-Millis":"1478537014194","channels":"2","ETag":"\"33c800-45887d8256040\"","Author":"A-M Classical","fragment.count":"28","invokehttp.status.message":"OK","xmpDM:duration":"211996.546875"}

I added an ExtractMediaMetaData processor and examined the mp3s