首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microsoft.Speech.Synthesis不适用于文本到语音,但是System.Speech.Synthesis works.Why?

Microsoft.Speech.Synthesis不适用于文本到语音,但是System.Speech.Synthesis works.Why?
EN

Stack Overflow用户
提问于 2013-07-10 18:09:34
回答 3查看 7.4K关注 0票数 3

我只是尝试使用Microsoft.Speech.dll;运行简单的microsoft文本到语音示例。

代码语言:javascript
复制
using System;
using Microsoft.Speech.Synthesis;

namespace TTS
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Testing TTS!");

            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Output information about all of the installed voices.
                Console.WriteLine("Installed voices -");
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    VoiceInfo info = voice.VoiceInfo;
                    Console.WriteLine(" Voice Name: " + info.Name);
                }

                // Select the US English voice.
                synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)");

                // Build a prompt.
                PromptBuilder builder = new PromptBuilder();
                builder.AppendText("That is a big pizza!");

                // Speak the prompt.
                synth.Speak(builder);
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

虽然我有正确的声音,它没有发出任何声音的。没有文本到语音(TTS)语音。

当我使用微软的System.Speech.dll,然后,我可以听到声音。所以没有声音问题。

代码语言:javascript
复制
using System;
using System.Speech.Synthesis;

namespace TTS
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Testing TTS!");

            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Output information about all of the installed voices.
                Console.WriteLine("Installed voices -");
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    VoiceInfo info = voice.VoiceInfo;
                    Console.WriteLine(" Voice Name: " + info.Name);
                }

                // Build a prompt.
                PromptBuilder builder = new PromptBuilder();
                builder.AppendText("That is a big pizza!");

                // Speak the prompt.
                synth.Speak(builder);
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

不久

为什么我不能听到任何声音或做文本语音(TTS)与微软语音平台使用Microsoft.Speech?我应该做些额外的配置吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-07-12 20:45:32

因为你用的是两个不同的TTS引擎。Microsoft.Speech使用服务器TTS语音;System.Speech使用桌面TTS语音。请参阅讨论这里

默认情况下,Windows及以上版本的桌面TTS声音已注册,但没有服务器TTS语音。当您安装服务器语音平台运行时 (我认为您必须这样做,以便首先加载Microsoft.Speech.dll )时,您应该可以选择安装一些服务器TTS语音。

票数 4
EN

Stack Overflow用户

发布于 2013-11-07 05:03:27

在上,选择Add,然后选择System.Speech旁边的复选框

在您的程序中,也要使用system.speech。

对我来说很好。

票数 0
EN

Stack Overflow用户

发布于 2019-02-01 15:11:25

为了回答你的问题,你问:

为什么我不能听到任何声音或做文本语音(TTS)与微软语音平台使用Microsoft.Speech?

您在代码中遗漏了一件重要的事情。您无法听到声音,因为缺少了下面一行:

代码语言:javascript
复制
synth.SetOutputToDefaultAudioDevice();

这样你就能听到声音了。我也有同样的问题。我修改了您的代码,插入了上面的代码示例:

代码语言:javascript
复制
using System;

using System.Speech.Synthesis;
using Microsoft.Speech.Synthesis;
namespace ConsoleApplication1
{
 class Program
   {

    static void Main(string[] args)
    {
     Console.WriteLine("Testing TTS!");

     // Initialize a new instance of the SpeechSynthesizer.
     using (SpeechSynthesizer synth = new SpeechSynthesizer())
     {
        // Configure the synthesizer to send output to the default audio device.
        synth.SetOutputToDefaultAudioDevice();

        // Output information about all of the installed voices.
        Console.WriteLine("Installed voices -");
        foreach (InstalledVoice voice in synth.GetInstalledVoices())
        {
           VoiceInfo info = voice.VoiceInfo;
           Console.WriteLine(" Voice Name: " + info.Name);
        }

        // Select the US English voice.
        synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-GB, Hazel)");

        // Speak.
        synth.Speak("That is a big pizza!");
     }

     Console.Write("Press any key to continue . . . ");
     Console.ReadKey(true);
  }
 }
}

注意,在使用SetOutputToDefaultAudioDevice时,不必使用System.Speech.dll。下面是有关该方法的文档的链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17577866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档