Deepak
Deepak

Reputation: 97

how to use installed voices in c# visual studio 2010

I want to use installed voices of male, female or etc in c# program. i m using speechsynthesizer ans speakAsync functions. Please help me.

Upvotes: 0

Views: 6125

Answers (3)

Alex Aza
Alex Aza

Reputation: 78487

If you need to get a list of male or female voices you can do something like this:

    private static void Main()
    {
        Speak(VoiceGender.Male);
        Speak(VoiceGender.Female);
    }

    private static void Speak(VoiceGender voiceGender)
    {
        using (var speechSynthesizer = new SpeechSynthesizer())
        {
            var genderVoices = speechSynthesizer.GetInstalledVoices().Where(arg => arg.VoiceInfo.Gender == voiceGender).ToList();
            var firstVoice = genderVoices.FirstOrDefault();
            if (firstVoice == null)
                return;
            speechSynthesizer.SelectVoice(firstVoice.VoiceInfo.Name);
            speechSynthesizer.Speak("How are you today?");
        }
    }

Upvotes: 0

Danpe
Danpe

Reputation: 19047

If you want you'r program to speak try using this:

public void Say(string say)
{
    SpeechSynthesizer talker = new SpeechSynthesizer();
    talker.Speak(say);
}

And call this function like this: Say("Hello World"!);

Make sure you include: using System.Speech.Synthesis;

Upvotes: 1

IAmTimCorey
IAmTimCorey

Reputation: 16757

Here is a simple article on how to implement speech in your application:

http://www.dotnetfunda.com/articles/article828-build-your-talking-application-.aspx

As a part of the article, it shows how to list all of the installed voices and it also shows you how to then use your selected voice in your application. Here is the example code this article gives:

List lst = new List();
foreach (InstalledVoice voice in spsynthesizer.GetInstalledVoices())
{

    lst.Items.Add(voice.VoiceInfo);
}

spsynthesizer.SelectVoice(lstVoice[0].Name);

This would put all of the installed voices into a List and it would use the first voice in the list as the selected voice.

Upvotes: 3

Related Questions