如何使用 Microsoft SAPI 将文本转语音保存为 wav?

发布于 2024-07-23 14:26:05 字数 34 浏览 2 评论 0原文

我需要将文本转换为语音,然后将其另存为 wav 文件。

I need to turn a text into speech and then save it as wav file.

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

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

发布评论

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

评论(3

恋竹姑娘 2024-07-30 14:26:05

这是几分钟的游戏,所以买者自负。 对我来说效果很好。 我确实注意到 SpFileStream (它不实现 IDisposable,因此 try/finally)更喜欢绝对路径而不是相对路径。 C#。

   SpFileStream fs = null;
    try
    {
        SpVoice voice = new SpVoice();
        fs = new SpFileStream();
        fs.Open(@"c:\hello.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
        voice.AudioOutputStream = fs;
        voice.Speak("Hello world.", SpeechVoiceSpeakFlags.SVSFDefault);
    }
    finally
    {
        if (fs != null)
        {
            fs.Close();
        }
    }

This is from a few moments' play, so caveat emptor. Worked well for me. I did notice that SpFileStream (which doesn't implement IDisposable, thus the try/finally) prefers absolute paths to relative. C#.

   SpFileStream fs = null;
    try
    {
        SpVoice voice = new SpVoice();
        fs = new SpFileStream();
        fs.Open(@"c:\hello.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
        voice.AudioOutputStream = fs;
        voice.Speak("Hello world.", SpeechVoiceSpeakFlags.SVSFDefault);
    }
    finally
    {
        if (fs != null)
        {
            fs.Close();
        }
    }
瘫痪情歌 2024-07-30 14:26:05

正如我发现的如何更改输出格式,我们编写了如下代码:

SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(6, AudioBitsPerSample.Sixteen, AudioChannel.Mono);

//Same code comes here 

ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav",info);

这非常简单且易于理解。

酷网

And as I've found for how to change output format, we code something like this :

SpeechAudioFormatInfo info = new SpeechAudioFormatInfo(6, AudioBitsPerSample.Sixteen, AudioChannel.Mono);

//Same code comes here 

ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav",info);

That's pretty easy and comprehensible.

Cool .net

捎一片雪花 2024-07-30 14:26:05

以下 C# 代码使用 .Net 框架中的 System.Speech 命名空间。
使用命名空间之前需要先引用它,因为 Visual Studio 不会自动引用它。

        SpeechSynthesizer ss = new SpeechSynthesizer();
        ss.Volume = 100;
        ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
        ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav");
        ss.Speak("Hello World");

我希望这是相关且有帮助的。

The following C# code uses the System.Speech namespace in the .Net framework.
It is necessary to reference the namespace before using it, because it is not automatically referenced by Visual Studio.

        SpeechSynthesizer ss = new SpeechSynthesizer();
        ss.Volume = 100;
        ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
        ss.SetOutputToWaveFile(@"C:\MyAudioFile.wav");
        ss.Speak("Hello World");

I hope this is relevant and helpful.

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