来自语音的几个语音命令

时间:2014-03-17 08:37:58

标签: c#

我做错了什么?

所以我说"说得更低"我希望音量降低,反之亦然。

int amp = 80;

if (speech.Contains("speak"))
{
    if (speech.Contains("louder"))
    {
        MARVIN.Volume = amp - 10;
        amp = MARVIN.Volume;
        MARVIN.Speak("Volume is lower");
    }
    else if (speech.Contains(" louder"))
    {
        MARVIN.Volume = amp + 10;
        amp = MARVIN.Volume;
        MARVIN.Speak("Volume is louder");
    }
    else
    {
        MARVIN.Speak("Volume value is not defined sir");
    }
}

2 个答案:

答案 0 :(得分:2)

您的意思是lower吗?

if (speech.Contains("lower"))
{
    MARVIN.Volume = amp - 10;
    amp = MARVIN.Volume;
    MARVIN.Speak("Volume is lower");
}

你说'所以我说'低说''但如果你检查louder

答案 1 :(得分:0)

我会拆分字符串以便取出关键字。

int amp = 80;

string[] commands = speech.Split(' ');    

if (commands[0] == "speak")
{
    switch (commands[1])
    {
        case "lower":
        {
            MARVIN.Volume = amp - 10;
            amp = MARVIN.Volume;
            MARVIN.Speak("Volume is lower");

            break;
        }
        case "louder":
        {
            MARVIN.Volume = amp + 10;
            amp = MARVIN.Volume;
            MARVIN.Speak("Volume is louder");

            break;
        }
    }
}