Python语言中的Inproc语音识别引擎

2024-09-28 05:27:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用PySpeech来识别语音。我试图在没有Windows语音识别默认命令的情况下启动语音识别。在

从google上我发现语音.py发件人:

_recognizer = win32com.client.Dispatch("SAPI.SpSharedRecognizer")

收件人:

_recognizer = win32com.client.Dispatch("SAPI.SpInprocRecognizer")

不包括所有默认命令。当我测试识别器是否在监听时,它返回false。在这一点上,我只是想让pySpeech认识到我在说什么,然后把它说给我听。在

测试代码:

import speech

speech.say("say something") #<--- says "say something"
print speech.input() #<--- gets stuck here
print speech.islistening() #<----- prints False

在语音.py:

^{pr2}$

Tags: py命令clientwindows情况语音speechsomething
3条回答

当我面对同样的问题时,我发现了下面的post。在

基本上,你必须在语音.py公司名称:

  1. _recognizer = win32com.client.Dispatch("SAPI.SpSharedRecognizer")行改为_recognizer = win32com.client.Dispatch("SAPI.SpInProcRecognizer")
  2. 在前一行之后添加此行:_recognizer.AudioInputStream = win32com.client.Dispatch("SAPI.SpMMAudioIn")
  3. _ListenerBase = win32com.client.getevents("SAPI.SpSharedRecoContext")行改为_ListenerBase = win32com.client.getevents("SAPI.SpInProcRecoContext")

这个问题确实很老,但是这里有一个基于PySpeech(python2)的模块,它同时支持inprocegnizer和SharedRecognizer:winspeech。适用于Python2和3。在

好吧,正如我提到的,进程内识别器没有默认的输入源或识别引擎设置。为了让进程内识别器监听,您需要通过_recognizer.SetInputto set the input source)和{}(to set the recognition engine)来设置它们

您面临的挑战是分别获取默认的输入源和识别引擎。如果使用C++,这将是简单的;SPHelp.h中有一个辅助函数,它得到默认输入源:^ {CD3}},并且我发布了一个函数{{a3},它得到默认的识别引擎。在

但是我不知道如何将这些函数转换成Python;也许你知道。在

相关问题 更多 >

    热门问题