Skip to content

Commit

Permalink
speech recognition change don't need restart anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaei committed Dec 24, 2019
1 parent 9bb67c7 commit 17147f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
43 changes: 30 additions & 13 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public partial class Form1 : Form
private SpeechRecognition speechRecognition;
private readonly System.Windows.Forms.Timer timerGlobal = new System.Windows.Forms.Timer();
private readonly Dictionary<string, bool> libraryViews;
private importExported.ExportedCreatureList exportedCreatureList;
private ExportedCreatureList exportedCreatureList;
private MergingDuplicatesWindow mergingDuplicatesWindow;
private importExported.ExportedCreatureControl exportedCreatureControl;
private ExportedCreatureControl exportedCreatureControl;
private readonly ToolTip tt = new ToolTip();
private bool reactOnSelectionChange;
private CancellationTokenSource cancelTokenLibrarySelection;
Expand Down Expand Up @@ -392,15 +392,7 @@ private void Form1_Load(object sender, EventArgs e)
ocrControl1.Initialize();

// initialize speech recognition if enabled
if (Properties.Settings.Default.SpeechRecognition)
{
// var speechRecognitionAvailable = (AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName.Substring(0, 13) == "System.Speech")); // TODO doens't work as intended. Should only require System.Speech if available to allow running it on MONO

speechRecognition = new SpeechRecognition(creatureCollection.maxWildLevel, creatureCollection.considerWildLevelSteps ? creatureCollection.wildLevelStep : 1, Values.V.speciesWithAliasesList, lbListening);
speechRecognition.speechRecognized += TellTamingData;
speechRecognition.speechCommandRecognized += SpeechCommand;
}
else lbListening.Visible = false;
InitializeSpeechRecognition();

// default owner and tribe
creatureInfoInputExtractor.CreatureOwner = Properties.Settings.Default.DefaultOwnerName;
Expand Down Expand Up @@ -438,6 +430,28 @@ private void Form1_Load(object sender, EventArgs e)
timerGlobal.Start();
}

/// <summary>
/// If the according property is set, the speechrecognition is initialized. Else it's disposed.
/// </summary>
private void InitializeSpeechRecognition()
{
if (Properties.Settings.Default.SpeechRecognition)
{
// var speechRecognitionAvailable = (AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName.Substring(0, 13) == "System.Speech")); // TODO doens't work as intended. Should only require System.Speech if available to allow running it on MONO

speechRecognition = new SpeechRecognition(creatureCollection.maxWildLevel, creatureCollection.considerWildLevelSteps ? creatureCollection.wildLevelStep : 1, Values.V.speciesWithAliasesList, lbListening);
speechRecognition.speechRecognized += TellTamingData;
speechRecognition.speechCommandRecognized += SpeechCommand;
lbListening.Visible = true;
}
else
{
speechRecognition?.Dispose();
speechRecognition = null;
lbListening.Visible = false;
}
}

private void SetSpecies(Species species)
{
speciesSelector1.SetSpecies(species);
Expand Down Expand Up @@ -1980,6 +1994,8 @@ private void OpenSettingsDialog(int page = -1)
&& Properties.Settings.Default.AutoImportExportedCreatures;
filewatcherExports.SetWatchFolder(exportFolderDefault, enableExportWatcher);

InitializeSpeechRecognition();

SetCollectionChanged(true);
}
settingsLastTabPageIndex = settingsfrm.LastTabPageIndex;
Expand Down Expand Up @@ -2331,8 +2347,9 @@ private void chkbToggleOverlay_CheckedChanged(object sender, EventArgs e)
overlay.Visible = cbToggleOverlay.Checked;
overlay.enableOverlayTimer = cbToggleOverlay.Checked;

if (speechRecognition != null)
speechRecognition.Listen = cbToggleOverlay.Checked;
// disable speechrecognition if overlay is disabled. (no use if no data can be displayed)
if (speechRecognition != null && !cbToggleOverlay.Checked)
speechRecognition.Listen = false;
}

private void toolStripButtonCopy2Tester_Click(object sender, EventArgs e)
Expand Down
14 changes: 7 additions & 7 deletions ARKBreedingStats/settings/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17147f8

Please sign in to comment.