Skip to content

Commit

Permalink
deprecate the sound utils module (#190)
Browse files Browse the repository at this point in the history
Co-authored-by: David Greaves <david@dgreaves.com>
  • Loading branch information
JarbasAl and lbt authored Oct 25, 2023
1 parent 51e845f commit 16267b9
Showing 1 changed file with 31 additions and 46 deletions.
77 changes: 31 additions & 46 deletions ovos_utils/sound/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import os
import subprocess
import time

from copy import deepcopy
from distutils.spawn import find_executable

from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.log import LOG
from ovos_utils.log import LOG, deprecated
from ovos_utils.signal import check_for_signal

try:
from ovos_config.config import read_mycroft_config
except ImportError:
LOG.warning("Config not provided and ovos_config not available")


def read_mycroft_config():
return dict()

Expand All @@ -33,74 +34,50 @@ def _get_pulse_environment(config):
return os.environ


def _play_default_sound_locally(sound_name):
audio_file = resolve_resource_file(
read_mycroft_config().get('sounds', {}).get(sound_name))
if not audio_file:
LOG.warning(f"Could not find '{sound_name}' audio file!")
return
process = play_audio(audio_file)
if not process:
LOG.warning(f"Unable to play '{sound_name}' audio file!")
return process


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_acknowledge_sound():
"""Acknowledge a successful request.
This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.
"""
audio_file = resolve_resource_file(
read_mycroft_config().get('sounds', {}).get('acknowledge'))

if not audio_file:
LOG.warning("Could not find 'acknowledge' audio file!")
return

process = play_audio(audio_file)
if not process:
LOG.warning("Unable to play 'acknowledge' audio file!")
return process
return _play_default_sound_locally('acknowledge')


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_listening_sound():
"""Audibly indicate speech recording started."""
audio_file = resolve_resource_file(
read_mycroft_config().get('sounds', {}).get('start_listening'))

if not audio_file:
LOG.warning("Could not find 'start_listening' audio file!")
return

process = play_audio(audio_file)
if not process:
LOG.warning("Unable to play 'start_listening' audio file!")
return process
return _play_default_sound_locally('start_listening')


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_end_listening_sound():
"""Audibly indicate speech recording is no longer happening."""
audio_file = resolve_resource_file(
read_mycroft_config().get('sounds', {}).get('end_listening'))

if not audio_file:
LOG.debug("Could not find 'end_listening' audio file!")
return

process = play_audio(audio_file)
if not process:
LOG.warning("Unable to play 'end_listening' audio file!")
return process
return _play_default_sound_locally('end_listening')


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_error_sound():
"""Audibly indicate a failed request.
This method plays a error sound to signal an error that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was NOT handled successfully.
"""
audio_file = resolve_resource_file(
read_mycroft_config().get('sounds', {}).get('error'))

if not audio_file:
LOG.warning("Could not find 'error' audio file!")
return

process = play_audio(audio_file)
if not process:
LOG.warning("Unable to play 'error' audio file!")
return process
return _play_default_sound_locally('error')


def _find_player(uri):
Expand Down Expand Up @@ -189,6 +166,7 @@ def play_audio(uri, play_cmd=None, environment=None):
return None


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_wav(uri, play_cmd=None, environment=None):
""" Play a wav-file.
Expand All @@ -209,6 +187,7 @@ def play_wav(uri, play_cmd=None, environment=None):
return None


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_mp3(uri, play_cmd=None, environment=None):
""" Play a mp3-file.
Expand All @@ -229,6 +208,7 @@ def play_mp3(uri, play_cmd=None, environment=None):
return None


@deprecated("please emit mycroft.audio.play_sound instead", "0.1.0")
def play_ogg(uri, play_cmd=None, environment=None):
""" Play a ogg-file.
Expand All @@ -249,6 +229,7 @@ def play_ogg(uri, play_cmd=None, environment=None):
return None


@deprecated("please use ovos-dinkum-listener in recording mode instead", "0.1.0")
def record(file_path, duration, rate, channels):
"""Simple function to record from the default mic.
Expand All @@ -270,6 +251,8 @@ def record(file_path, duration, rate, channels):
return subprocess.Popen(command)


@deprecated("file signals have been removed,"
" TODO add new bus message for this method", "0.1.0")
def is_speaking():
"""Determine if Text to Speech is occurring
Expand All @@ -279,6 +262,8 @@ def is_speaking():
return check_for_signal("isSpeaking", -1)


@deprecated("file signals have been removed,"
" use session_id and recognizer_loop:audio_output_end to track this", "0.1.0")
def wait_while_speaking():
"""Pause as long as Text to Speech is still happening
Expand Down

0 comments on commit 16267b9

Please sign in to comment.