2

我是 C# 的新手,我是 Speech.Recognition 的新手。我搜索了很长时间的教程,但没有找到那么多,我什至不确定我是否正确地包含了所有内容。

我下载了:

我在本地编程,我有 Windows XP、.net framework 3.5。

现在我只想从一些简单的代码行开始,比如说“hello world”或者说一两个词作为输入。

我尝试了以下操作,当然它不起作用:>错误:

“找不到类型或命名空间名称“SpeechSynthesizer”(是否缺少 Using-Direktive 或 Assemblyverweis?)”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;

namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SpeechSynthesizer foo = new SpeechSynthesizer();
            foo.Speak("Test");  
        }
    }
}

编辑:

你好,我试过你的代码,但是使用 SpeechLib;找不到:>

现在我写道:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;

namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }

但我收到一个错误:

numericUpDown1、SpVoice、SpeechVoiceSpeakFlags、textBox1 和超时

4

2 回答 2

3

项目 + 添加引用,.NET 选项卡,选择“System.Speech”。

一个项目模板预先选择了几个 .NET 程序集。但只有常见的,如 System.dll、System.Core.dll 等。您必须自己添加“不寻常”的。

于 2010-10-08T12:13:13.233 回答
0

你可以试试这个:

得到Interop.SpeechLib.dll

using SpeechLib;

private void ReadText(string readText)
        {
            int iCounter = 0;
            while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
            {
                SpVoice spVoice = new SpVoice();
                spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
                spVoice.WaitUntilDone(Timeout.Infinite);
                iCounter = iCounter + 1;
            }
        }
于 2010-10-08T11:43:37.757 回答