From 0a118357ad3e4c6c9b0464b71aa6d56be1925ecd Mon Sep 17 00:00:00 2001 From: Tkael Date: Tue, 4 Jul 2023 18:21:04 -0700 Subject: [PATCH] More gracefully handle audio file not found exceptions. --- SpeechService/SpeechService.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SpeechService/SpeechService.cs b/SpeechService/SpeechService.cs index 0b810a0a18..94be048944 100644 --- a/SpeechService/SpeechService.cs +++ b/SpeechService/SpeechService.cs @@ -328,9 +328,9 @@ public void Speak(string speech, string defaultVoice, int echoDelay, int distort try { // Play the audio, waiting for the audio to complete unless we're in async mode - if (async) + if ( async ) { - Task.Run(() => PlayAudio(fileName, volumeOverride)); + Task.Run( () => PlayAudio( fileName, volumeOverride ) ); } else { @@ -345,10 +345,11 @@ public void Speak(string speech, string defaultVoice, int echoDelay, int distort } } } - catch (Exception e) + catch ( Exception e ) { - Logging.Warn(e.Message, e); + Logging.Warn( e.Message, e ); } + continue; } @@ -648,9 +649,16 @@ public void PlayAudio ( string fileName, decimal? volumeOverride, bool useLegacy { audioSource = CodecFactory.Instance.GetCodec( fileName ); } + catch ( FileNotFoundException fnfe ) + { + Say( null, $"Audio file not found at {fileName}.", 0 ); + Logging.Warn( fnfe.Message, fnfe ); + throw; + } catch ( NotSupportedException e ) { - Logging.Debug( $"Skipping unsupported audio file {fileName}.", e ); + Say( null, "Audio file format not supported.", 0 ); + Logging.Warn( $"Skipping unsupported audio file {fileName}.", e ); throw; } if ( !( audioSource?.Length > 0 ) ) { return; }