Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting the error message, "Cannot implicitly convert type 'System.Speech.Synthesis.Prompt' to 'bool.'"

My code is:

C#
case "quit program"
           bool confirmationResult = speak.SpeakAsync("Are you sure");
           if (confirmationResult)
           {
                  speak.SpeakAsync("Okay");
                  this.close();


ALL OF THE CODE: https://codeshare.io/GbeLxj

What I have tried:

I have tried making the code:
C#
case "quit program"
           bool confirmationResult = Prompt speak.SpeakAsync("Are you sure");
           if (confirmationResult)
           {
                  speak.SpeakAsync("Okay");
                  this.close();

I just got more error messages.
Posted
Updated 24-Mar-17 20:48pm
Comments
CHill60 24-Mar-17 19:51pm    
Well SpeakAsync does not return a bool - it returns a Prompt Prompt Class (System.Speech.Synthesis)[^]
So change your program to receive the correct return value
[no name] 24-Mar-17 20:44pm    
SpeakAsync() merely speaks the text. This is totally unrelated to confirmationResult which is obviously some kind of user input. You need to look again at your algorithm.

1 solution

Look at the definition of the SpeechSynthesizer.SpeakAsync Method (String) (System.Speech.Synthesis)[^] and it returns a Prompt class instance - "the object that contains the content to speak". That does not convert to a bool, and does not in any way get an input from the user to confirm what he wants to do. So when you try to assign the returned object to your bool variable, the systems throws up it's hands and tells you "I can't do that, I don't known how to treat a Prompt as a Boolean value"

I think you need to go back a stage or two, and work out how your user is supposed to interact with your application - because you need to get a response there rather than assuming that the act of asking a question miraculously also fetches the answer...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900