This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David
committed
Jun 20, 2018
1 parent
91256e3
commit b7a094e
Showing
14 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Speech.Recognition; | ||
using System.Speech.Synthesis; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using ExtPlaneNet; | ||
|
||
namespace X_Plane_Voice_Control.Commands | ||
{ | ||
class ApuControl : ControlTemplate | ||
{ | ||
private readonly string[] _apuOnStrings = { "start", "light up" }; | ||
private readonly string[] _apuOffString = { "stop", "shutdown" }; | ||
private readonly string[] _apuStatus = { "on", "off" }; | ||
|
||
public ApuControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var apuGrammar = new GrammarBuilder(); | ||
apuGrammar.Append("please", 0, 1); | ||
apuGrammar.Append(new Choices(_apuOnStrings.Concat(_apuOffString).ToArray()), 0, 1); | ||
apuGrammar.Append("APU"); | ||
apuGrammar.Append(new Choices(_apuStatus), 0, 1); | ||
apuGrammar.Append("please", 0, 1); | ||
Grammar = new Grammar(apuGrammar); | ||
RecognitionPattern = Constants.DeserializeRecognitionPattern(apuGrammar.DebugShowPhrases); | ||
} | ||
|
||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
XPlaneInterface.Subscribe<double>("laminar/B738/switches/apu_start"); | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var apuStatus = XPlaneInterface.GetDataRef<double>("laminar/B738/switches/apu_start"); | ||
if (_apuOnStrings.Any(phrase.Contains) || phrase.Contains(_apuStatus[0])) | ||
{ | ||
XPlaneInterface.SetDataRef(apuStatus.Name, 0); | ||
SpeechSynthesizer.SpeakAsync("APU is starting up"); | ||
} | ||
else if (_apuOffString.Any(phrase.Contains) || phrase.Contains(_apuStatus[1])) | ||
{ | ||
XPlaneInterface.SetDataRef(apuStatus.Name, 2); | ||
SpeechSynthesizer.SpeakAsync("APU is shutting down"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Speech.Recognition; | ||
using System.Speech.Synthesis; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using ExtPlaneNet; | ||
|
||
namespace X_Plane_Voice_Control.Commands | ||
{ | ||
class EngineFuelControl : ControlTemplate | ||
{ | ||
private readonly string[] _engineNumbersStrings = { "one", "two" }; | ||
|
||
public EngineFuelControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var engineGrammar = new GrammarBuilder(); | ||
engineGrammar.Append("please", 0, 1); | ||
engineGrammar.Append("introduce fuel"); | ||
engineGrammar.Append(new Choices("into", "to")); | ||
engineGrammar.Append("number", 0, 1); | ||
engineGrammar.Append("engine"); | ||
engineGrammar.Append(new Choices(_engineNumbersStrings)); | ||
engineGrammar.Append("please", 0, 1); | ||
Grammar = new Grammar(engineGrammar); | ||
|
||
RecognitionPattern = Constants.DeserializeRecognitionPattern(engineGrammar.DebugShowPhrases); | ||
} | ||
|
||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/mixture_ratio2"); | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/mixture_ratio1"); | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var valueOne = XPlaneInterface.GetDataRef<double>("laminar/B738/engine/mixture_ratio1"); | ||
var valueTwo = XPlaneInterface.GetDataRef<double>("laminar/B738/engine/mixture_ratio2"); | ||
if (phrase.Contains(_engineNumbersStrings[0])) | ||
{ | ||
XPlaneInterface.SetDataRef(valueOne.Name, 1); | ||
SpeechSynthesizer.SpeakAsync("Introducing fuel into engine number one"); | ||
} | ||
else if (phrase.Contains(_engineNumbersStrings[1])) | ||
{ | ||
XPlaneInterface.SetDataRef(valueTwo.Name, 1); | ||
SpeechSynthesizer.SpeakAsync("Introducing fuel into engine number two"); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Speech.Recognition; | ||
using System.Speech.Synthesis; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using ExtPlaneNet; | ||
|
||
namespace X_Plane_Voice_Control.Commands | ||
{ | ||
class EngineStartUpControl : ControlTemplate | ||
{ | ||
private readonly string[] _engineNumbersStrings = { "one", "two" }; | ||
private readonly string[] _engineStartStrings = { "start", "light up" }; | ||
private readonly string[] _engineShutdownStrings = { "kill", "shut down" }; | ||
|
||
public EngineStartUpControl(ExtPlaneInterface interface_, SpeechSynthesizer synthesizer) : base(interface_, synthesizer) | ||
{ | ||
var engineGrammar = new GrammarBuilder(); | ||
engineGrammar.Append("please", 0, 1); | ||
engineGrammar.Append(new Choices(_engineStartStrings.Concat(_engineShutdownStrings).ToArray())); | ||
engineGrammar.Append("the", 0, 1); | ||
engineGrammar.Append("engine"); | ||
engineGrammar.Append("number", 0, 1); | ||
engineGrammar.Append(new Choices(_engineNumbersStrings)); | ||
engineGrammar.Append("please", 0, 1); | ||
Grammar = new Grammar(engineGrammar); | ||
RecognitionPattern = Constants.DeserializeRecognitionPattern(engineGrammar.DebugShowPhrases); | ||
} | ||
|
||
public sealed override Grammar Grammar { get; } | ||
public override string RecognitionPattern { get; } | ||
|
||
public override void DataRefSubscribe() | ||
{ | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/starter1_pos"); | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/starter2_pos"); | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/mixture_ratio2"); | ||
XPlaneInterface.Subscribe<double>("laminar/B738/engine/mixture_ratio1"); | ||
} | ||
|
||
public override void OnTrigger(RecognitionResult rResult, string phrase) | ||
{ | ||
var valueOne = XPlaneInterface.GetDataRef<double>("laminar/B738/engine/starter1_pos"); | ||
var valueTwo = XPlaneInterface.GetDataRef<double>("laminar/B738/engine/starter2_pos"); | ||
if (phrase.Contains(_engineNumbersStrings[0])) | ||
{ | ||
if (_engineStartStrings.Any(phrase.Contains)) | ||
{ | ||
XPlaneInterface.SetDataRef(valueOne.Name, 0); | ||
SpeechSynthesizer.SpeakAsync("Starting engine number one"); | ||
} | ||
else if (_engineShutdownStrings.Any(phrase.Contains)) | ||
{ | ||
XPlaneInterface.SetDataRef("laminar/B738/engine/mixture_ratio1", 0); | ||
SpeechSynthesizer.SpeakAsync("Shutting down engine number one"); | ||
} | ||
} | ||
else if (phrase.Contains(_engineNumbersStrings[1])) | ||
{ | ||
if (_engineStartStrings.Any(phrase.Contains)) | ||
{ | ||
XPlaneInterface.SetDataRef(valueTwo.Name, 0); | ||
SpeechSynthesizer.SpeakAsync("Starting engine number two"); | ||
} | ||
else if (_engineShutdownStrings.Any(phrase.Contains)) | ||
{ | ||
XPlaneInterface.SetDataRef("laminar/B738/engine/mixture_ratio2", 0); | ||
SpeechSynthesizer.SpeakAsync("Shutting down engine number two"); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters