Skip to content

Instantly share code, notes, and snippets.

@poohsen
Created January 7, 2023 15:35
Show Gist options
  • Save poohsen/faf2e6585efa7685b84cc3206a6de406 to your computer and use it in GitHub Desktop.
Save poohsen/faf2e6585efa7685b84cc3206a6de406 to your computer and use it in GitHub Desktop.
duck kodi volume on wakeword detection, unduck after TTS ran
#! /usr/bin/env python3
from mycroft_bus_client import MessageBusClient, Message
from kodijson import Kodi
from dotenv import load_dotenv
import os
load_dotenv()
kodi_username = os.getenv('KODI_USERNAME')
kodi_password = os.getenv('KODI_PASSWORD')
def get_current_volume():
return kodi.Application.GetProperties({'properties': ['volume']})['result']['volume']
def duck_music(message):
last_volume = get_current_volume()
kodi.Application.SetVolume({"volume": int(last_volume/2)})
print('Mycroft "{}"'.format(message.__dict__))
def unduck_music(message):
kodi.Application.SetVolume({"volume": last_volume})
print('Mycroft "{}"'.format(message.__dict__))
print('Setting up client to connect to a local mycroft instance')
client = MessageBusClient()
kodi = Kodi("http://192.168.2.31:8082/jsonrpc", kodi_username, kodi_password)
last_volume = get_current_volume()
if not last_volume:
last_volume = 75
print(f'Registering handlers ...' )
client.on('recognizer_loop:wakeword', duck_music)
client.on('recognizer_loop:audio_output_end', unduck_music)
client.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment