How to create C# code that would allow my computer to speak english words that would be based on text provided by the system?
2 Answers
Text-to-speech is built into the .Net Framework 4 without needing to reference any external .dlls, using the System.Speech.Synthesis.SpeechSynthesizer class. It doesn't sound that great on XP, but better on Vista and 7. It's simple to use too:
using (SpeechSynthesizer synth = new SpeechSynthesizer()) { synth.Speak("hello"); } Comments
you can try to use this code of mine.
public static class Melodie { private static SpeechLib.SpVoice WomenAgent = new SpeechLib.SpVoice(); public static void AnnounceRestrictionOfAccount() { WomenAgent.Speak("You're account has been block by the system security", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault); } public static void SayGoodBye() { WomenAgent.Speak("Goodbye!"); } public static void WelcomeUser(User userToBeWelcomed) { string Salutation = ConstructWelcomeSpeech(userToBeWelcomed); WomenAgent.Speak(Salutation); } private static string ConstructWelcomeSpeech(User user) { string salutation = "Welcome "; if (user.Gender == "Male") { salutation += " Mr. "; } else if (user.Gender == "Female") { if (user.CivilStatus != null) { if (user.CivilStatus == "Single") salutation += " Ms. "; else salutation += " Mrs. "; } } salutation += user.FirstName + " " + user.LastName; return salutation; } public static void AnnounceMessage(string message) { WomenAgent.Speak(message); } } and you can read more about SpeechLib in MSDN.
another thing you should also include Microsoft speech lib 5.0 as a reference in you're project. :)