-2

I can't figure out how to make it so that if I ask my C# voice application, "Call Mark" It will ask for a confirmation and only call him if I say "Yes".

case "Call Mark:
    speak.SpeakAsync("Are you sure");

        break;

I would guess that I would have to use a Bool, but I don't know how without making it so that I have to say "yes" before you say "call Mark." Another way that I tried just made it so that when I said "yes" it would call him.

  • 2
    Just have the `speak.SpeakAsync` return a bool. Then check that value before you actually make the call. – Matt Rowland Mar 23 '17 at 21:37
  • Unrelated to the question at hand, but I'd have doubts about hardcoding all possible commands into a switch statement... apart from testing anyway. – Broots Waymb Mar 23 '17 at 21:48
  • @DangerZone How would you do it otherwise? – Scott Gibbard Mar 24 '17 at 20:19
  • @ScottGibbard - I really can't tell you, because I don't know enough about your code or even app, but think about a cell phone with voice recognition where someone can call any contact by name... You couldn't possibly add a case for every single name/nickname the user could possibly say. – Broots Waymb Mar 24 '17 at 20:25

2 Answers2

1

Your best bet is to have the .SpeakAsync() method return a bool. Then you would check the result before actually making the call.

case "Call Mark":
    bool confirmationResult = speak.SpeakAsync("Are you sure");
    if (confirmationResult)
        MakeCall();
    break;
Matt Rowland
  • 4,575
  • 4
  • 25
  • 34
  • That worked except that `speak.SpeakAsync("Are you sure");` got an error that says "Cannot implicitly convert type 'System.Speech.Synthesis.Prompt' to 'bool.'" – Scott Gibbard Mar 24 '17 at 21:37
  • If the `SpeakAsync()` method is from a third party library you will have to leverage this idea from what the library offers. – Matt Rowland Mar 24 '17 at 23:26
0

I'll express my answer using the high-level algorithm, for clarity.

  1. Wait to receive "Call Mark"
  2. Speak "Are you sure?"
  3. If the answer is "yes", then call Mark.

In code:

if (speech = "CALL MARK) {
    var string input = Api.DetectSpeech(Source.Microphone);
    if (input = "YES") {
        Phone.DialNumber(Contacts.Mark);
    }
}
recursive
  • 83,943
  • 34
  • 151
  • 241
  • @ScottGibbard: Sure thing. Please see the added code. – recursive Mar 23 '17 at 23:55
  • I have encountered two problems. 1.) There is no "DetectSpeech." 2.) It says "Cannot implicitly convert type 'string' to 'bool.' Can you please tell me how to fix them? Otherwise, thanks! – Scott Gibbard Mar 26 '17 at 21:22
  • Hm. Sorry. It looks like I was looking at the wrong documentation. I don't have any info on this api. – recursive Mar 26 '17 at 21:24