Audio service #433

Merged
merged 52 commits into from Aug 1, 2017

Conversation

Projects
None yet
7 participants
Member

forslund commented Dec 25, 2016

In late November @penrods led a discussion about how an audio service in Mycroft could work. This is a simple implementation of what was discussed. This is a quick implementation of the system as I understood it and I think this can be used to continue the discussion. Ideas and suggestions on improvements are very welcome.

The PR adds support for commands like

"Hey Mycroft, play the news in the livingroom"

Backends

The current system includes support for the following "backends"

  • Mpg123, very limited implementation
  • VLC
  • Mopidy

"backends" currently in the works:

  • Chromecast
  • Kodi

Backends are quite easy to add and an existing baseclass can be extended to add new ones.

AudioService

Skill creators will use an audio service interface to communicate with the audio service / playback control. the AudioService interface uses the standard message bus.

from mycroft.skills.audioservice import AudioService
[...]
  as = AudioService()
[...]
  as.play(file_or_uri) # handles both lists and single uris

See the npr_news skill for basic usage.

The AudioService currently only support play and track_info requests but this will probably be expanded for increased usefulness.

Playback control skill

Features:

  • backend/location selection from utterance ("...in kitchen" etc.)
  • lowering volume while Mycroft speaks
  • playback control (Pausing/Resuming, skipping, Stopping)

The backend/location selection is currently done using basic string parsing and should probably be done using adapt instead.

This skill removes much of the basic functions that needs to be implemented for an audio playback skill and the skill creator can focus on the trickier parts.

Currently most of the audio logic is implemented in the playback control skill and should maybe be moved but this was a good starting point.

Configuration

A Configuration the audio services:

{
  "Audio": {
    "backends": {
      "local": {
        "type": "mpg123",
        "active": true
      },
      "kitchen": {
        "type": "mopidy",
        "url": "http://localhost:6680",
        "active": true
      },
      "livingroom": {
        "type": "mopidy",
        "url": "http://192.168.10.232:6680",
        "active": false
      },
      "vlc": {
        "type": "vlc",
        "active": true
      }
    },
    "default-backend": "local"
  }
}

If you try it I suggest you install vlc and pyvlc and use the vlc backend since mpg123 only has basic functionallity.

I've tested this mainly with the mopidy skill and the npr_news skill.

Todo

  • more backends, Kodi and chromecast is a minimum
  • possibly separate the backends from the playback control skill
  • populate the AudioService interface with more functions so skill creators can do more interesting things with the audio (A music quiz-skill should be able to skip ahead in the playlist when a correct answer is provided)
  • More configuration options
  • Maybe some way to send credentials from a skill to the backend to access some music services
  • Better utterance parsing when starting playback, along with more keywords (like half volume)
Member

forslund commented Mar 29, 2017

Major refactoring done after discussion with @ethanaward. The audio backends now runs separately from the skills. The loading of backends is now done using a method similar to how the skills work and should be easy to extend to include thirdparty backends.

@JarbasAI JarbasAI referenced this pull request Apr 10, 2017

Open

display backend #650

Member

forslund commented Apr 11, 2017

Skills using the audio service interface
NPR news:
https://github.com/forslund/skill-npr-news/tree/audio-service
Ethan's demo skill:
https://github.com/forslund/demo_skill/tree/audio_service/
play all using vlc to enque all tracks and play using vlc for example

most important, the playback control skill:
https://github.com/forslund/playback_control_skill

The playback control skills implement the common commands for skills using the audio service. like skipping tracks, pausing and resuming. The idea is that the skill creator only needs to implement the finding of audio files and the command that starts playback. (The other commands are of course available to the skill creator if they wish to use them)

@augustnmonteiro augustnmonteiro self-requested a review Apr 26, 2017

Coverage Status

Coverage decreased (-4.6%) to 30.071% when pulling c981119 on forslund:audio-service into 52af555 on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.6%) to 31.641% when pulling 104621e on forslund:audio-service into d68b1dd on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.6%) to 31.622% when pulling 306bbf5 on forslund:audio-service into 60867fc on MycroftAI:dev.

Member

forslund commented May 25, 2017

Finally rebased, phew

mycroft/audio/main.py
+ logger.info('no default found')
+ logger.info('Default:' + str(default))
+
+ ws.on('MycroftAudioServicePlay', _play)
@augustnmonteiro

augustnmonteiro May 25, 2017

Member

please change to mycroft.audio.service.play like the others mycroft events

Coverage Status

Coverage decreased (-4.6%) to 31.622% when pulling 5df592e on forslund:audio-service into 60867fc on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.7%) to 33.946% when pulling aa884e5 on forslund:audio-service into a5592d8 on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.7%) to 33.787% when pulling 7834bf6 on forslund:audio-service into 5bb7d25 on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.6%) to 33.882% when pulling 4a68ab7 on forslund:audio-service into 5bb7d25 on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.6%) to 33.882% when pulling 2e75056 on forslund:audio-service into 5bb7d25 on MycroftAI:dev.

Coverage Status

Coverage decreased (-4.6%) to 33.882% when pulling 939c678 on forslund:audio-service into 5bb7d25 on MycroftAI:dev.

Coverage Status

Coverage increased (+0.5%) to 39.003% when pulling a49d1ea on forslund:audio-service into 8e17fe3 on MycroftAI:dev.

Coverage Status

Coverage increased (+0.5%) to 38.937% when pulling d7da37d on forslund:audio-service into fc3ede1 on MycroftAI:dev.

Member

augustnmonteiro commented Jun 30, 2017

Let's rebase and wait finish the new release to merge it

Coverage Status

Coverage increased (+0.003%) to 40.103% when pulling b7a1754 on forslund:audio-service into 0108a26 on MycroftAI:dev.

Owner

penrods commented Jul 4, 2017

Let's get this merged after the next (July 6th) release.

Coverage Status

Coverage increased (+0.3%) to 39.849% when pulling cbbd72e on forslund:audio-service into 7bab1d1 on MycroftAI:dev.

Coverage Status

Coverage increased (+0.4%) to 39.83% when pulling a7d81ad on forslund:audio-service into 63d90ce on MycroftAI:dev.

Member

augustnmonteiro commented Jul 13, 2017

@forslund can we merge this one?

Member

forslund commented Jul 14, 2017

Fixed the conflict it should be good to merge now.

Coverage Status

Coverage increased (+0.06%) to 41.727% when pulling 0fa0ee5 on forslund:audio-service into a5d349a on MycroftAI:dev.

Coverage Status

Coverage increased (+0.2%) to 41.488% when pulling d272bd6 on forslund:audio-service into 2a59593 on MycroftAI:dev.

forslund added some commits Dec 2, 2016

Initial commit of audio service
Three backends have been added, mopidy, vlc and mpg123. Depending on uri type an apporpriate service is selected when media playback is requested. (for example mopidy service can handle spotify://... and local://...)

A playback Control skill can pause, resume, stop change track, etc any started media. So for example if the NPR news skill used this after starting playing the news the user can say "Hey Mycroft, pause" and the playback will pause. The playback control also handles stuff like lowering the volume of the playback if mycroft is asked another question.

Currently the different backend runs under the playbeck control, this was made most for convenience and the services should be moved in the future.

Usage:
The user needs to import the audioservice interface
`from mycroft.skills.audioservice import AudioService`

and initialize an instance in the skill `initialize` method

`self.audio_service = AudioService(self.emitter)`

Then playing an uri is as simple as

`self.audio_service.play(uri)`

TODO:
* Configuration (Alias for the different backends, service specific config, active services, etc.)
* Manual selection of backend (This is prepared in the audioservice interface biut not implemented)
* More feature complete audio service interface (playback control, get trackname etc)
* Separate audio services from the playback control
* Probably lots more
Add backend selection
The user can now specify which backend to use to play media. default the keywords are the name of the backend (vlc, mpg123, mopidy) but can be set with the config.

Example:
audio.mopidy.name = "livingroom"

A possible user interaction might be

- "Hey mycroft, play the news in the livingroom"

The detection is very basic and not very elegant but works as a proof of concept.
Make all audio backend build on the base class
Abstract base class is now a bit more lenient
Add chromecast service
Chromecast can be manually added with a backend entry with type set to "chromecast" or the service can autodetect all chromecast and register them with their names by setting the Audio configuration parameter autodetect-chromecast set to true.

Currently this implementation is very basic and is using the default media controller. This limits the usable uri's to http(s), adding support for local files and hopefully more services will be added later.
Populate AudioService class with more methods
Pause, resume, next and previous added to the interface.
The play method was updated to add 'file://' to uri's lacking uri type.
Rename messages.
As requested by Augusto Monteiro
Update control logic for mpg123 process
Removes the cases where the process keeps playing in the background
when a new track is started.
Fix bug in track_info_method
* import Message to allow audio service to reply info
* Add default message to audio service class
Add support for muting pulse audio streams
when the audio configuration option "pulseaudio" is set to mute running
audio streams will be muted while mycroft is speaking and while mycroft
is listening.

Coverage Status

Coverage increased (+0.04%) to 41.367% when pulling 9c49f97 on forslund:audio-service into edbd8ed on MycroftAI:dev.

Owner

penrods commented Aug 1, 2017

So why isn't this merged yet! Reviewed by Augusto, merge away!

Coverage Status

Coverage increased (+0.06%) to 41.385% when pulling df18f42 on forslund:audio-service into edbd8ed on MycroftAI:dev.

@forslund forslund merged commit e1a1751 into MycroftAI:dev Aug 1, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.02%) to 41.385%
Details
Member

augustnmonteiro commented Aug 1, 2017

@penrods I reviewed before the last release and didn't merged to that release and forgot to merge after the release is done, Sorry @forslund

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment