Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable support for pulseaudio ducking #2282

Merged
merged 3 commits into from Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 0 additions & 75 deletions mycroft/audio/audioservice.py
Expand Up @@ -25,10 +25,6 @@

from .services import RemoteAudioBackend

try:
import pulsectl
except ImportError:
pulsectl = None

MAINMODULE = '__init__'
sys.path.append(abspath(dirname(__file__)))
Expand Down Expand Up @@ -147,13 +143,7 @@ def __init__(self, bus):
self.current = None
self.play_start_time = 0
self.volume_is_low = False
self.pulse = None
self.pulse_quiet = None
self.pulse_restore = None

self.muted_sinks = []
# Setup control of pulse audio
self.setup_pulseaudio_handlers(self.config.get('pulseaudio'))
bus.once('open', self.load_services_callback)

def load_services_callback(self):
Expand Down Expand Up @@ -282,52 +272,6 @@ def _lower_volume(self, message=None):
LOG.debug('lowering volume')
self.current.lower_volume()
self.volume_is_low = True
try:
if self.pulse_quiet:
self.pulse_quiet()
except Exception as exc:
LOG.error(exc)

def pulse_mute(self):
"""
Mute all pulse audio input sinks except for the one named
'mycroft-voice'.
"""
for sink in self.pulse.sink_input_list():
if sink.name != 'mycroft-voice':
self.pulse.sink_input_mute(sink.index, 1)
self.muted_sinks.append(sink.index)

def pulse_unmute(self):
"""
Unmute all pulse audio input sinks.
"""
for sink in self.pulse.sink_input_list():
if sink.index in self.muted_sinks:
self.pulse.sink_input_mute(sink.index, 0)
self.muted_sinks = []

def pulse_lower_volume(self):
"""
Lower volume of all pulse audio input sinks except the one named
'mycroft-voice'.
"""
for sink in self.pulse.sink_input_list():
if sink.name != 'mycroft-voice':
volume = sink.volume
volume.value_flat *= 0.3
self.pulse.volume_set(sink, volume)

def pulse_restore_volume(self):
"""
Restore volume of all pulse audio input sinks except the one named
'mycroft-voice'.
"""
for sink in self.pulse.sink_input_list():
if sink.name != 'mycroft-voice':
volume = sink.volume
volume.value_flat /= 0.3
self.pulse.volume_set(sink, volume)

def _restore_volume(self, message):
"""
Expand All @@ -342,8 +286,6 @@ def _restore_volume(self, message):
time.sleep(2)
if not self.volume_is_low:
self.current.restore_volume()
if self.pulse_restore:
self.pulse_restore()

def play(self, tracks, prefered_service, repeat=False):
"""
Expand Down Expand Up @@ -465,23 +407,6 @@ def _seek_backward(self, message):
if self.current:
self.current.seek_backward(seconds)

def setup_pulseaudio_handlers(self, pulse_choice=None):
"""
Select functions for handling lower volume/restore of
pulse audio input sinks.

Args:
pulse_choice: method selection, can be eithe 'mute' or 'lower'
"""
if pulsectl and pulse_choice:
self.pulse = pulsectl.Pulse('Mycroft-audio-service')
if pulse_choice == 'mute':
self.pulse_quiet = self.pulse_mute
self.pulse_restore = self.pulse_unmute
elif pulse_choice == 'lower':
self.pulse_quiet = self.pulse_lower_volume
self.pulse_restore = self.pulse_restore_volume

def shutdown(self):
for s in self.service:
try:
Expand Down
1 change: 1 addition & 0 deletions mycroft/configuration/mycroft.conf
Expand Up @@ -277,6 +277,7 @@
// Override: REMOTE
"tts": {
// Engine. Options: "mimic", "google", "marytts", "fatts", "espeak", "spdsay", "responsive_voice"
"pulse_duck": false,
"module": "mimic",
"mimic": {
"voice": "ap"
Expand Down