【问题标题】:How can I use SpeechSynthesizer in ASP.NET Core 2.0如何在 ASP.NET Core 2.0 中使用 SpeechSynthesizer
【发布时间】:2019-05-30 10:37:25
【问题描述】:

我正在尝试将文本保存到使用 ASP.NET Core 2.0 开发的 Web 应用中的音频文件中。

我正在尝试寻找对 System.Speech 的支持,但命名空间在 .NET Core 中似乎不可用。

谁能给我任何替代类库来将文本保存到音频文件 (MP3)。

我找到了一些 ScriptCs 代码示例,但它们对我不起作用。

有人有什么建议吗?

【问题讨论】:

    标签: asp.net-core text-to-speech speechsynthesizer


    【解决方案1】:

    不确定这是否适合您,但您可以将 ASP.NET Core 应用设置为面向 .NET Framework。

    编辑 yourapp.csproj 并更改:

    <TargetFramework>netcoreapp2.2</TargetFramework>
    

    <TargetFramework>net472</TargetFramework>
    

    现在您应该可以添加对 System.Speech 的引用并执行以下操作:

    System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();
    synth.SetOutputToDefaultAudioDevice();
    synth.Speak("Your awesome web site is starting!!");
    

    完成此任务的另一个很酷的方法是使用一些在线 API,例如 Azure 语音服务(文本到语音),它几乎独立于平台并提供大量配置选项 (https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech)。

    【讨论】:

    • 这不是答案,他说他的解决方案是 .net core 将其更改为 Framework 可能不是最好的解决方案。
    • @MattDrouillard 虽然这可能不是最好的解决方案,但它一个答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 2018-10-08
    • 2018-05-02
    • 2018-06-20
    相关资源
    最近更新 更多