I always want to lower the threshold for programming and CG production, but Maya also wants to move with voice recognition, so I'm doing a lot of research.
This article hasn't gotten to the point of working with Maya.
It's just a test of the Microsoft Speech API that comes standard with Windows.
Windows10 Python 2.7.12 pywin32==220
python -m virtualenv venv
venv\Scripts\activate.bat
python venv \ Lib \ site-packages \ win32com \ client \ makepy.py
When the following program is executed, it will wait for voice input with the message "Ready", and the character string will be output to the standard output in response to the voices "One", "Two", "Three", "Four", and "Hello".
main.py
#!/usr/bin/env python
# coding=utf-8
from __future__ import absolute_import, division, print_function
from win32com.client import constants
import win32com.client
import pythoncom
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
u"""Callback class called when a phrase is recognized
Register words in advance.
"""
def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
newResult = win32com.client.Dispatch(Result)
print(u"You said: {0}".format(newResult.PhraseInfo.GetText()))
class SpeechRecognition(object):
def __init__(self, wordsToAdd):
u"""Various initialization"""
self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
self.context = self.listener.CreateRecoContext()
self.grammar = self.context.CreateGrammar()
self.grammar.DictationSetState(0)
self.wordsRule = self.grammar.Rules.Add(
"wordsRule",
constants.SRATopLevel + constants.SRADynamic, 0)
self.wordsRule.Clear()
for word in wordsToAdd:
self.wordsRule.InitialState.AddWordTransition(None, word)
self.grammar.Rules.Commit()
self.grammar.CmdSetRuleState("wordsRule", 1)
self.grammar.Rules.Commit()
self.eventHandler = ContextEvents(self.context)
self.say(u"Junbikanryo")
def say(self, phrase):
u"""Let me talk"""
self.speaker.Speak(phrase)
if __name__ == '__main__':
wordsToAdd = ["One", "Two", "Three", "Four", u"Hello"]
speechReco = SpeechRecognition(wordsToAdd)
while True:
pythoncom.PumpWaitingMessages()
I'm sorry regardless of Maya.
[Play COM with Python + pywin32 to talk. ](Https://mimumimu.net/blog/2011/07/02/python-pywin32-%E3%81%A7-com-%E5%8F%A9%E3%81%84%E3%81%A6% E3% 81% 97% E3% 82% 83% E3% 81% B9% E3% 82% 89% E3% 81% 9B% E3% 82% 8B% E3% 80% 82 /) Python: win32com.client.getevents(“SAPI.SpSharedRecoContext”) returns None
Recommended Posts