💾 Archived View for gmi.bacardi55.io › blog › 2017 › 11 › 15 › kalliope-as-your-personal-dj captured on 2023-07-22 at 16:45:31. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Posted on 2017-11-15
A quick blog post about how I managed my music via Kalliope :)
The basic idea is simple: I want to ask Kalliope to play music for me, and manage spotify playlist/search and radio
To do this, I need:
I wanted to have a simple flow:
1: https://kalliope-project.github.io
2: https://github.com/bacardi55/kalliope-mpd
Me: "I want to listen to music" Kalliope: "Of course, what do you want to listen to?" Me: Option 1: Me: "My favorite spotify playlist" Kalliope: "Ok, starting your favorite playlist" Option 2: Me: "spotify playlist <Name Of a playlist>" Kalliope: "Ok, launching <Name of a playlist>" Option 3: Me: "I want to listen to the radio" Kalliope: Which radio sir? Me: "<radio name>" Kalliope: "launching radio <radio name>" Option 4: Me: "music from <artist name>" Kalliope: "searching for music of <artist name>" Option 5: Me: "I'll try some fashion music" Kalliope: "Starting some fashion music"
First, install Kalliope. For this, follow the documentation[4]. Once it's done and working, install the MPD neuron[5] as indicated on the README[6].
4: https://github.com/kalliope-project/kalliope/blob/master/README.md
5: https://github.com/bacardi55/kalliope-mpd
6: https://github.com/bacardi55/kalliope-mpd/blob/master/README.md
We'll get to the brain configuration in the next step.
Then, you need to install mopidy. Either on the same device as Kalliope or on another one. For this, same as above, follow the documentation[7] :)
7: https://docs.mopidy.com/en/stable/
If you have the same use cases as me, and want to plug spotify and the radio, you will also need to install mopidy-spotify[8], tunein[9], and spotify_tunigo[10] and of corse the core mpd backend[11].
8: https://github.com/mopidy/mopidy-spotify
9: https://github.com/kingosticks/mopidy-tunein
10: https://github.com/trygveaa/mopidy-spotify-tunigo
11: https://docs.mopidy.com/en/stable/ext/mpd/
Mon fichier de conf .config/mopidy/mopidy.conf pour exemple:
[mpd] enabled = true hostname = 127.0.0.1 port = 8080 password = MyPassword max_connections = 10 connection_timeout = 60 zeroconf = Mopidy MPD server on $hostname command_blacklist = listall,listallinfo default_playlist_scheme = m3u [core] cache_dir = $XDG_CACHE_DIR/mopidy config_dir = $XDG_CONFIG_DIR/mopidy data_dir = $XDG_DATA_DIR/mopidy max_tracklist_length = 10000 restore_state = false [logging] color = true console_format = %(levelname)-8s %(message)s debug_format = %(levelname)-8s %(asctime)s [%(process)d:%(threadName)s] %(name)s\n %(message)s debug_file = mopidy.log config_file = [spotify] username = MyLogin password = MyPassword enabled = true bitrate = 320 timeout = 100 client_id = MyClientId client_secret = MyClientSecret [spotify_tunigo] enabled: true [tunein] timeout = 5000
PS: You need to adapt the hostname if your mopidy server is not installed on the same machine as Kalliope!, see mopidy hostname configuration here[12].
12: https://docs.mopidy.com/en/stable/config/
Let's create a new brain file called mpd.yml in your brains directory, and configure the first step of the flow:
- name: "ask-and-play-music" signals: - order: "I want to listen to music" neurons: - say: message: "Of course, what do you want to listen to?" - neurotransmitter: from_answer_link: - synapse: "play-favorite-spotify-playlist" answers: - "My favorite spotify playlist" - synapse: "play-asked-spotify-playlist" answers: - "spotify playlist {{query}}" - synapse: "play-fashion-music" answers: - "I'll try some fashion music" - synapse: "play-asked-radio" answers: - "I want to listen to the radio" - synapse: "play-asked-music" answers: - "search for {{query}}" default: "didnt-understand"
So here we have the first step for our full flow. Kalliope is asking what kind of music I want to listen to, and depending on my answer, different synapse will be triggered.
Now I need to define the actions for each of these choices.
That's easy, just like said in the doc of the neuron:
- name: "play-favorite-spotify-playlist" signals: - order: "start my favorite spotify playlist" neurons: - kalliopempd: mpd_action: "playlist" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "1" mpd_volume: "50" query: "{{favorite_playlist_name}}" - say: message: "Ok, starting your favorite playlist"
I could give a "no_order" but I might want to fire this playlist directly so I gave a correct order.
Please note that I'm using the brackets because I'm using the variables capability of kalliope
- name: "play-asked-spotify-playlist" signals: - order: "start playlist {{query}}" neurons: - kalliopempd: mpd_action: "playlist" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "1" mpd_volume: "50" query: "{{query}}" - say: message: "Ok, starting the playlist {{query}}"
First, lets configure kalliope so it ask which radio I want to listen to:
- name: "play-asked-radio" signals: - order: "I want to listen to the radio" neurons: - say: message: "Which radio sir?" - neurotransmitter: from_answer_link: - synapse: "play-radio" answers: - "{{query}}" default: "didnt-understand"
Then, create the brain that will actually start the radio:
- name: "play-radio" signals: - order: "play-radio-no-order" neurons: - kalliopempd: mpd_action: "search" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "0" query: "{{query}}" - say: message: "Launching radio {{query}}"
Please note that I'm using the brackets because I'm using the variables capability of kalliope
Same as the favorite playlist:
- name: "play-asked-music" signals: - order: "search music {{query}}" neurons: - kalliopempd: mpd_action: "search" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "0" query: "{{query}}" - say: message: "Launching some music of {{query}}"
Please note that I'm using the brackets because I'm using the variables capability of kalliope
This is just to let me know if something went wrong and Kalliope didn't understand:
- name: "didnt-understand" signals: - order: "didnt-understand" neurons: - say: message: "I'm terribly sorry sir, but something went wrong…"
Don't forget to add your new brain file in the brain.yml via an include and your variable in a loaded file :)
The full brain file:
- name: "ask-and-play-music" signals: - order: "I want to listen to music" neurons: - say: message: "Of course, what do you want to listen to?" - neurotransmitter: from_answer_link: - synapse: "play-favorite-spotify-playlist" answers: - "My favorite spotify playlist" - synapse: "play-asked-spotify-playlist" answers: - "spotify playlist {{query}}" - synapse: "play-fashion-music" answers: - "I'll try some fashion music" - synapse: "play-asked-radio" answers: - "I want to listen to the radio" - synapse: "play-asked-music" answers: - "search for {{query}}" default: "didnt-understand" - name: "play-favorite-spotify-playlist" signals: - order: "start my favorite spotify playlist" neurons: - kalliopempd: mpd_action: "playlist" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "1" mpd_volume: "50" query: "{{favorite_playlist_name}}" - say: message: "Ok, starting your favorite playlist" - name: "play-asked-spotify-playlist" signals: - order: "start playlist {{query}}" neurons: - kalliopempd: mpd_action: "playlist" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "1" mpd_volume: "50" query: "{{query}}" - say: message: "Ok, starting the playlist {{query}}" - name: "play-asked-radio" signals: - order: "I want to listen to the radio" neurons: - say: message: "Which radio sir?" - neurotransmitter: from_answer_link: - synapse: "play-radio" answers: - "{{query}}" default: "didnt-understand" - name: "play-radio" signals: - order: "play-radio-no-order" neurons: - kalliopempd: mpd_action: "search" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "0" query: "{{query}}" - say: message: "Launching radio {{query}}" - name: "play-asked-music" signals: - order: "search music {{query}}" neurons: - kalliopempd: mpd_action: "search" mpd_url: "{{mpd_url}}" mpd_port: "{{mpd_port}}" mpd_password: "{{mpd_password}}" mpd_random: "0" query: "{{query}}" - say: message: "Launching some music of {{query}}" - name: "didnt-understand" signals: - order: "didnt-understand" neurons: - say: message: "I'm terribly sorry sir, but something went wrong…"