Add function to acknowledge success non-verbally

pull/2096/head
Chris Rogers 2019-04-14 10:11:52 -04:00
parent 61e4aeb55f
commit 2a6f113151
4 changed files with 56 additions and 3 deletions

View File

@ -44,7 +44,8 @@
// File locations of sounds to play for system events
"sounds": {
"start_listening": "snd/start_listening.wav",
"end_listening": "snd/end_listening.wav"
"end_listening": "snd/end_listening.wav",
"acknowledge": "snd/acknowledge.mp3"
},
// Mechanism used to play WAV audio files

Binary file not shown.

View File

@ -44,7 +44,9 @@ from mycroft.skills.settings import SkillSettings
from mycroft.skills.skill_data import (load_vocabulary, load_regex, to_alnum,
munge_regex, munge_intent_parser,
read_vocab_file)
from mycroft.util import camel_case_split, resolve_resource_file
from mycroft.util import (camel_case_split,
resolve_resource_file,
play_audio_file)
from mycroft.util.log import LOG
MainModule = '__init__'
@ -1648,6 +1650,26 @@ class MycroftSkill:
for e in list(self.scheduled_repeats):
self.cancel_scheduled_event(e)
def acknowledge(self):
""" 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.
"""
file = resolve_resource_file(
self.config_core.get('sounds').get('acknowledge'))
if not file:
LOG.warning("Could not find 'acknowledge' audio file!")
return
process = play_audio_file(file)
if process:
process.wait()
else:
LOG.warning("Unable to play 'acknowledge' audio file!")
#######################################################################
# FallbackSkill base class

View File

@ -18,7 +18,7 @@ import socket
import subprocess
import pyaudio
from os.path import join, expanduser
from os.path import join, expanduser, splitext
from threading import Thread
from time import sleep
@ -93,6 +93,36 @@ def resolve_resource_file(res_name):
return None # Resource cannot be resolved
def play_audio_file(uri: str):
""" Play an audio file.
This wraps the other play_* functions, choosing the correct one based on
the file extension. The function will return directly and play the file
in the background.
Arguments:
uri: uri to play
Returns: subprocess.Popen object. None if the format is not supported or
an error occurs playing the file.
"""
extension_to_function = {
'.wav': play_wav,
'.mp3': play_mp3,
'.ogg': play_ogg
}
_, extension = splitext(uri)
play_function = extension_to_function.get(extension.lower())
if play_function:
return play_function(uri)
else:
LOG.error("Could not find a function capable of playing {uri}."
" Supported formats are {keys}."
.format(uri=uri, keys=list(extension_to_function.keys())))
return None
def play_wav(uri):
""" Play a wav-file.