# Audio Service

The `mycroft-core` distribution of Mycroft includes a *Playback Skill* which can be used to control playback after it has been started. This means that playback only needs to be started in the **Skill**. Controlling playback can then be done through the *Playback Skill*.

## How to set up the Audio Service

First, import the

`AudioService`

class.

```python
from mycroft.skills.audioservice import AudioService
```

Then in the `initialize()` method of your **Skill**, instantiate an `AudioService` object:

```python
    def initialize(self):
        self.audio_service = AudioService(self.bus)

        #Other initialize code
        [...]
```

## Starting playback

Once the `AudioService` instance is created, you can start playback by simply calling the `play()` method with a track URI:

```python
        self.audio_service.play('file:///path/to/my/track.mp3')
```

or with a list of tracks

```python
        self.audio_service.play(['file:///path/to/my/track.mp3', 'http://tracks-online.com/my/track.mp3'])
```

see the [AudioServicePlugins](https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/plugins/audioservice#audiobackend) for information about configuring supported uris.

The play method has an optional second argument to further process the user's **Utterance**. Currently this can only be used to select backend (where you want to send the audio) but in the future it will be able to handle requests like

> Hey Mycroft, play Hello Nasty by the Beastie Boys at half volume. We don't want to wake the neighbours

To use this feature the **Utterance** received from the intent service must be passed

```python
    def play_playlist_handler(self, message):
        self.audioservice.play(PLAYLIST, message.data['utterance'])
```

## More technical information

## The backends

The default backend is still mpg123 for mp3 files which is very limited but is the most generally available or multiple platforms.

Included in this release there's also

* `VLC` (a very general purpose media player)
* `mopidy` (a common audio server in the Raspberry Pi community)
* `chromecast` (experimental)

These haven't been extensively tested on the Mark 1 yet.

## PulseAudio features

The audio service hooks into the PulseAudio controls and can mute playback of sound streams beyond Mycroft's control. This is currently deactivated by default but can be enabled by changing the `mycroft.conf` configuration found in `mycroft/configuration/mycroft.conf`

```javascript
  "play_wav_cmdline": "paplay %1 --stream-name=mycroft-voice",
  "Audio": {
    "pulseaudio": "mute"
  }
```

## AudioService Technical Documentation

More information on AudioService methods can be found in the [Mycroft Technical Documentation](https://mycroft-core.readthedocs.io/en/master/source/mycroft.html#audioservice-class).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/services/audio-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
