Skip to content

Commit

Permalink
Add method to disable speech plugin from python
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnBuckley committed Mar 30, 2022
1 parent 97afcae commit c3813c0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions FreePIE.Core.Plugins/SpeechPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class SpeechPlugin : Plugin
private SpeechRecognitionEngine recognitionEngine;
private Dictionary<string, RecognitionInfo> recognizerResults;

private bool recognitionActive = true;

public override object CreateGlobal()
{
Expand All @@ -34,6 +35,11 @@ public override void Stop()
}
}

public void EnableRecognition(bool enable)
{
recognitionActive = enable;
}

public void SelectVoice(string name)
{
EnsureSynthesizer();
Expand Down Expand Up @@ -87,10 +93,14 @@ private bool EnsureRecognizer()

recognitionEngine.SpeechRecognized += (s, e) =>
{
var info = recognizerResults[e.Result.Text];

if (e.Result.Confidence >= info.Confidence)
info.Result = true;
if (recognitionActive)
{
var info = recognizerResults[e.Result.Text];

if (e.Result.Confidence >= info.Confidence)
info.Result = true;
}

};

}
Expand Down Expand Up @@ -158,5 +168,10 @@ public void selectVoice(string name)
{
plugin.SelectVoice(name);
}

public void enableRecognition(bool enable)
{
plugin.EnableRecognition(enable);
}
}
}

0 comments on commit c3813c0

Please sign in to comment.