使用 c++调用和使用 Windows 语音识别

发布于 2024-10-10 17:08:33 字数 1566 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清旖 2024-10-17 17:08:33

(老问题,但没有被接受的答案,并且在谷歌中显得相当高)

如果你真的想在 C++ 中执行此操作,你必须下载 SAPI SDK,它不是 Windows 的标准配置: http://www.microsoft.com/downloads/en /details.aspx?FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530&displaylang=en ,选择 SpeechSDK51.exe

您可以在 SAPI 上找到的最佳文档不在 Web 上,而是在 SDK 本身中,文档/文件夹。 .chm 很好地解释了一切。 此处是一个附加链接让您开始。

然而,C++ 对你来说不是必需的,我强烈建议你用 C# 来做。它确实简单得多(没有 COM 组件,没有单独的 SDK,MSDN 上有更多文档,更多教程,...)。请参阅这篇 CodeProject 文章;你必须删除所有 GUI 的东西,以及所有语音合成的东西,你会发现,语音识别归结为 10 行代码。相当令人印象深刻。

编辑示例代码,未编译,未测试:

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,完成

(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

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. Here is an additional link to get you started.

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.

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

Smile简单爱 2024-10-17 17:08:33

Windows 为客户端和服务器提供语音识别引擎。两者都可以使用 C++ 或 .NET 语言进行编程。用于 C++ 编程的传统 API 称为 SAPI。客户端和服务器语音的 .NET 框架命名空间是 System.Speech 和 Microsoft.Speech。

SAPI 文档 - http://msdn.microsoft.com/ en-us/library/ms723627(VS.85).aspx

用于客户端识别的 .NET 命名空间是 System.Speech - http://msdn.microsoft.com/en-us/library/system.speech.recognition.aspx。 Windows Vista 和 7 包含语音引擎。

用于服务器识别的 .NET 命名空间是 Microsoft.Speech,10.2 版本的完整 SDK 可在 http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4。语音引擎可免费下载。

许多早期的问题已经解决了这个问题。请参阅基于语音识别的原型SAPI 和 Windows 7 问题 例如。

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.

SAPI documentation - 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.

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.

Lots of earlier questions have addressed this. See Prototype based on speech recognition and SAPI and Windows 7 Problem for examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文