windows 使用c++调用和使用Windows语音识别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4609761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using c++ to call and use Windows Speech Recognition
提问by Divs
I am making an application that involves the use of windows speech recognition. I am thinking of using c++ to do this since i have some experience with this language. The way i want to use the speech recognition is so that it works internally. If i upload an audio file into my program, i want speech recognition to write this audio up as a text file, but all this should be done internally. Please provide some help with this and if i have not explained my question properly please let me know and i will try to explain again.
我正在制作一个涉及使用 Windows 语音识别的应用程序。我正在考虑使用 C++ 来做到这一点,因为我对这种语言有一些经验。我想使用语音识别的方式是让它在内部工作。如果我将音频文件上传到我的程序中,我希望语音识别将此音频写成文本文件,但这一切都应该在内部完成。请对此提供一些帮助,如果我没有正确解释我的问题,请告诉我,我会尝试再次解释。
Thanks in advance, Divs
提前致谢, Divs
回答by Calvin1602
(Old question, but no accepted answer, and appears quite high in google)
(老问题,但没有被接受的答案,在谷歌中显得相当高)
If you really want to do this in C++, you have to download the SAPI SDK, which does not come standard with Windows : http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530&displaylang=en, select SpeechSDK51.exe
如果你真的想在 C++ 中做到这一点,你必须下载 SAPI SDK,它不是 Windows 的标准:http: //www.microsoft.com/downloads/en/details.aspx?FamilyID=5e86ec97-40a7- 453f-b0ee-6583171b4530&displaylang=en,选择 SpeechSDK51.exe
The best documentation you can find on SAPI is not on the web, it's in the SDK itself, in the Docs/ folder. The .chm explains everything really well. Hereis an additional link to get you started.
您可以在 SAPI 上找到的最佳文档不在网络上,而是在 SDK 本身的 Docs/ 文件夹中。.chm 很好地解释了一切。这是一个额外的链接,可以帮助您入门。
However, it C++ is not a requirement for you, I strongly recommend you do it in C#. It's really much simpler (no COM components, no separate SDK, more doc on MSDN, more tutorials, ...) . See this CodeProject article; you'll have to remove all the GUI stuff, and all the speech synthesis stuff, and you'll see, speech recognition boild down to 10 lines of code. Quite impressive.
但是,C++ 不是您的必需品,我强烈建议您使用 C# 来完成。它真的简单得多(没有 COM 组件,没有单独的 SDK,MSDN 上的更多文档,更多教程,......)。请参阅此 CodeProject 文章;你必须删除所有的 GUI 和所有语音合成的东西,你会看到,语音识别归结为 10 行代码。相当令人印象深刻。
EDIT sample code, not compiled, not tested :
编辑示例代码,未编译,未测试:
using System.Speech;
using System.Speech.Recognition;
// in constructor or initialisation
SpeechRecognitionEngine recognizer = null;
recognizer = new SpeechRecognitionEngine();
recognizer.SetInputToDefaultAudioDevice();
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// The callback called when a sentence is recognized
private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e){
string text = e.Result.Text;
// Do whatever you want with 'text' now
}
ta dah, done
达达,完成
回答by Michael Levy
Windows provides speech recognition engines for both clients and servers. Both can be programmed with C++ or with .NET languages. The traditional API for programming in C++ is known as SAPI. The .NET framework namepsaces for client and server speech are System.Speech and Microsoft.Speech.
Windows 为客户端和服务器提供语音识别引擎。两者都可以使用 C++ 或 .NET 语言进行编程。用于 C++ 编程的传统 API 称为 SAPI。客户端和服务器语音的 .NET 框架命名空间是 System.Speech 和 Microsoft.Speech。
SAPI documentation - http://msdn.microsoft.com/en-us/library/ms723627(VS.85).aspx
SAPI 文档 - http://msdn.microsoft.com/en-us/library/ms723627(VS.85).aspx
The .NET namespace for client recognition is System.Speech - http://msdn.microsoft.com/en-us/library/system.speech.recognition.aspx. Windows Vista and 7 include the speech engine.
用于客户端识别的 .NET 命名空间是 System.Speech - http://msdn.microsoft.com/en-us/library/system.speech.recognition.aspx。Windows Vista 和 7 包括语音引擎。
The .NET namespace for server recognition is Microsoft.Speech and the complete SDK for the 10.2 version is available at http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4. The speech engine is a free download.
用于服务器识别的 .NET 命名空间是 Microsoft.Speech,10.2 版本的完整 SDK 可在http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21- 90a294a5c9a4。语音引擎可免费下载。
Lots of earlier questions have addressed this. See Prototype based on speech recognitionand SAPI and Windows 7 Problemfor examples.
许多早期的问题已经解决了这个问题。有关示例,请参阅基于语音识别和SAPI 的原型和 Windows 7 问题。