我创建了一个简单的 C# 控制台计算器,我想添加语音识别来识别人声。
示例:如果我想添加两个数字,我会通过我的声音告诉程序添加两个数字,然后它会进行计算。但我不知道该怎么做。这是代码
class Program
{
static void Main(string[] args)
{
int num1;
int num2;
string operators;
float ans;
Console.Write(" first integer: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("enter a operator (+, -, /, *): ");
operand = Console.ReadLine();
Console.Write("enter the second integer: ");
num2 = Convert.ToInt32(Console.ReadLine());
switch (operators)
{
case "-":
answer = num1 - num2;
break;
case "+":
answer = num1 + num2;
break;
case "/":
answer = num1 / num2;
break;
case "*":
answer = num1 * num2;
break;
default:
answer = 0;
break;
}
Console.WriteLine(num1.ToString() + " " + operators
+ " " + num2.ToString() + " = " + ans.ToString());
Console.ReadLine();
}
}