From 28223cab3047e3e2bc5c06c6cd577da9cc7f2293 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 16 Dec 2018 17:29:45 +0100 Subject: [PATCH] Only import sounddevice when needed --- platypush/plugins/sound.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/sound.py b/platypush/plugins/sound.py index c16100ed..928d8f50 100644 --- a/platypush/plugins/sound.py +++ b/platypush/plugins/sound.py @@ -10,8 +10,6 @@ import time from enum import Enum from threading import Thread, Event, RLock -import sounddevice as sd - from platypush.plugins import Plugin, action @@ -114,6 +112,8 @@ class SoundPlugin(Plugin): """ + import sounddevice as sd + devs = sd.query_devices() if category == 'input': devs = [d for d in devs if d.get('max_input_channels') > 0] @@ -141,6 +141,8 @@ class SoundPlugin(Plugin): :type bufsize: int """ + import sounddevice as sd + if self._get_playback_state() != PlaybackState.STOPPED: self.stop_playback() time.sleep(2) @@ -267,6 +269,8 @@ class SoundPlugin(Plugin): :type subtype: str """ + import sounddevice as sd + if self._get_recording_state() != RecordingState.STOPPED: self.stop_recording() time.sleep(2) @@ -375,6 +379,8 @@ class SoundPlugin(Plugin): :type dtype: str """ + import sounddevice as sd + if self._get_playback_state() != PlaybackState.STOPPED: self.stop_playback() time.sleep(2)