Skip to content

Commit

Permalink
Merge branch 'hotfix/1837-speech-config' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkael committed Jun 22, 2020
2 parents 7f30854 + 2c8d64e commit 788104a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
28 changes: 22 additions & 6 deletions EDDI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Windows.Forms;
using System.Windows.Input;
using Utilities;
using ComboBox = System.Windows.Controls.ComboBox;

namespace Eddi
{
Expand Down Expand Up @@ -1008,27 +1009,42 @@ public static bool IsAdministrator()

private void ttsVoiceDropDownUpdated(object sender, SelectionChangedEventArgs e)
{
ttsUpdated();
if (sender is FrameworkElement frameworkElement && frameworkElement.IsLoaded)
{
ttsUpdated();
}
}

private void ttsEffectsLevelUpdated(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ttsUpdated();
if (sender is FrameworkElement frameworkElement && frameworkElement.IsLoaded)
{
ttsUpdated();
}
}

private void ttsDistortionLevelUpdated(object sender, RoutedEventArgs e)
{
ttsUpdated();
if (sender is FrameworkElement frameworkElement && frameworkElement.IsLoaded)
{
ttsUpdated();
}
}

private void ttsRateUpdated(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ttsUpdated();
if (sender is FrameworkElement frameworkElement && frameworkElement.IsLoaded)
{
ttsUpdated();
}
}

private void ttsVolumeUpdated(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ttsUpdated();
if (sender is FrameworkElement frameworkElement && frameworkElement.IsLoaded)
{
ttsUpdated();
}
}

private void ttsTestVoiceButtonClicked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1072,8 +1088,8 @@ private void ttsUpdated()
DisableSsml = disableSsmlCheckbox.IsChecked.Value,
EnableIcao = enableIcaoCheckbox.IsChecked.Value
};
SpeechService.Instance.Configuration = speechConfiguration;
speechConfiguration.ToFile();
SpeechService.Instance.ReloadConfiguration();
}

// Called from the VoiceAttack plugin if the "Configure EDDI" voice command has
Expand Down
5 changes: 0 additions & 5 deletions SpeechService/SpeechService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ protected virtual void Dispose(bool disposing)
}
}

public void ReloadConfiguration()
{
Configuration = SpeechServiceConfiguration.FromFile();
}

public void Say(Ship ship, string message, int priority = 3, string voice = null, bool radio = false, string eventType = null, bool invokedFromVA = false)
{
if (message == null)
Expand Down
24 changes: 10 additions & 14 deletions Utilities/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Utilities
{
Expand Down Expand Up @@ -102,7 +101,7 @@ private static bool TryRead(string fileName, int attempts, out string result)
/// </summary>
/// <param name="fileName"></param>
/// <param name="content"></param>
public static async void Write(string fileName, string content)
public static void Write(string fileName, string content)
{
if (fileName != null && content != null)
{
Expand All @@ -113,19 +112,16 @@ public static async void Write(string fileName, string content)
return;
}

await Task.Run(() =>
int attempts = writeAttempts;
while (attempts > 0 && TryWrite(fileName, attempts, content))
{
int attempts = writeAttempts;
while (attempts > 0 && TryWrite(fileName, attempts, content))
{
attempts--;
Thread.Sleep(writeIODelayMilliseconds);
}
if (attempts == 0)
{
throw new IOException("IO write failed for " + fileName + ", too many attempts.");
}
}).ConfigureAwait(false);
attempts--;
Thread.Sleep(writeIODelayMilliseconds);
}
if (attempts == 0)
{
throw new IOException("IO write failed for " + fileName + ", too many attempts.");
}
}
}

Expand Down

0 comments on commit 788104a

Please sign in to comment.