Skip to content

Commit

Permalink
More gracefully handle audio file not found exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkael committed Jul 5, 2023
1 parent 9a89812 commit 0a11835
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions SpeechService/SpeechService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 0a11835

Please sign in to comment.