如何在 C# Visual Studio 2010 中使用已安装的声音

发布于 2024-11-05 21:17:08 字数 61 浏览 3 评论 0原文

我想在 C# 程序中使用已安装的男性、女性等声音。我正在使用语音合成器和 talkAsync 函数。请帮我。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天气好吗我好吗 2024-11-12 21:17:08

这是一篇关于如何在应用程序中实现语音的简单文章:

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

作为本文的一部分,它展示了如何列出所有已安装的语音,并且还向您展示了如何然后在应用程序中使用您选择的声音。以下是本文提供的示例代码:

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

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

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

这会将所有已安装的语音放入列表中,并使用列表中的第一个语音作为选定的语音。

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.

她如夕阳 2024-11-12 21:17:08

如果你想让你的程序说话,尝试使用这个:

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

并像这样调用这个函数:Say("Hello World"!);

确保你包括:using System.Speech.Synthesis ;

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;

夜空下最亮的亮点 2024-11-12 21:17:08

如果您需要获取男性或女性声音的列表,您可以执行以下操作:

    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?");
        }
    }

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?");
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文