Microsoft.Speech.Synthesis不适用于文本到语音BUT System.Speech.Synthesis有效。为什么?

时间:2013-07-10 18:09:34

标签: speech-recognition text-to-speech sapi speech-synthesis

我只是尝试使用 Microsoft.Speech.dll;

为Text To Speech运行简单的微软示例
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)语音。

enter image description here

当我使用Microsoft System.Speech.dll 时,我可以听到声音。所以没有声音问题。

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

enter image description here

很快

  

为什么我听不到任何声音或用文字转语音(TTS)   Microsoft Speech Platform使用Microsoft.Speech?我应该做点什么吗   额外配置?

3 个答案:

答案 0 :(得分:4)

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

Windows Vista及更高版本默认注册桌面TTS语音,但没有服务器TTS语音。当您安装Server Speech Platform Runtime时,我认为您必须首先加载Microsoft.Speech.dll,您应该可以选择安装一些服务器TTS语音。

答案 1 :(得分:0)

在Visual Studio上选择“项目”,然后选择“添加引用”,然后选中“System.Speech”旁边的复选框

在你的程序中也使用system.speech。

对我来说很好。

答案 2 :(得分:0)

要回答您提出的问题,

  

为什么我无法使用Microsoft.Speech在Microsoft语音平台上听到任何声音或无法进行文本转语音(TTS)?

您缺少代码中的重要内容。您听不到声音,因为缺少以下行:

synth.SetOutputToDefaultAudioDevice();

这可以让您听到声音。我有同样的问题。我修改了您的代码并插入了上面的代码示例:

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

请注意,当您使用System.Speech.dll时,不需要SetOutputToDefaultAudioDevice。这是有关该方法的文档的link