我正在用 C# 编写一个语音识别程序,并且我编译了几行代码,当我说“电池电量”时,它们会说出当前的电池电量。
if (e.Result.Text.ToLower() == "battery level")
{
System.Management.ManagementClass wmi = new System.Management.ManagementClass("Win32_Battery");
var allBatteries = wmi.GetInstances();
String estimatedChargeRemaining = String.Empty;
foreach (var battery in allBatteries)
{
estimatedChargeRemaining = Convert.ToString(battery["EstimatedChargeRemaining"]);
}
JARVIS.Speak("The Power Level Is At: " + estimatedChargeRemaining + "% sir");
return;
}
其中,我想创建另一个 if
语句来提醒我电池电量是否低于 25%。如何才能做到这一点?我猜它会像“if estimatedChargeRemaining < 25 then JARVIS.Speak("Warning, Battery level has dropped below 25%")
但我不太确定。