使用 C#.net 说话软件?

发布于 2024-12-12 05:22:43 字数 42 浏览 1 评论 0原文

如何创建 C# 代码,让我的计算机能够根据系统提供的文本说出英语单词?

How to create C# code that would allow my computer to speak english words that would be based on text provided by the system?

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

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

发布评论

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

评论(2

随梦而飞# 2024-12-19 05:22:43

文本转语音功能内置于 .Net Framework 4 中,无需引用任何外部 .dll,使用 System.Speech.Synthesis.SpeechSynthesizer 类。在 XP 上听起来不太好,但在 Vista 和 7 上更好。使用起来也很简单:

using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
    synth.Speak("hello");
}

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");
}
生生漫 2024-12-19 05:22:43

你可以尝试使用我的这段代码。

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

您可以在 MSDN 中阅读有关 SpeechLib 的更多信息。

另一件事是,您还应该在您的项目中包含 Microsoft 语音库 5.0 作为参考。 :)

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. :)

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