The first step about the import module, I tried several methods to find in the Win7 system as if there is no speech recognition function, I used the win10 and need to re-download a package
In this way, the Win32com.client module can be used
Import Win32com.client
# 1. Create a Broadcaster Object
# Speaker = Win32com.client.Dispatch ("SAPI. SpVoice ")
# 2. Through this broadcaster object, directly, play the corresponding voice string can be
# Speaker. Speak ("My name is: Wang Yunlong")
Class Caculator:
def __check_num_zsq (func):
def inner (self, N):
If not isinstance (n,int):
Raise TypeError ("There is a problem with the current type of data, it should be a shaping data")
return func (self, n)
return inner
def __say (Self,word):
# 1. Create a Broadcaster Object
Speaker = Win32com.client.Dispatch ("SAPI. SpVoice ")
# 2. Through this broadcaster object, directly, play the corresponding voice string can be
Speaker. Speak (Word)
def __create_say_zsq (Word = ""):
def __say_zsq (func):
def inner (self, N):
Self.__say (Word + str (n))
return func (self, n)
return inner
Return __SAY_ZSQ
@__check_num_zsq
@__create_say_zsq ()
def __init__ (Self,num):
Self.__result = num
@__check_num_zsq
@__create_say_zsq ("plus")
def Jia (self,n):
Self.__result + = n
return self
@__check_num_zsq
@__create_say_zsq ("Minus")
Def Jian (self,n):
Self.__result-= n
return self
@__check_num_zsq
@__create_say_zsq ("multiply")
def Chen (self,n):
Self.__result *= N
return self
Def show (self):
Self.__say ("The result of the calculation is:%d"%self.__result)
Print ("The result of the calculation is:%d"%self.__result)
return self
def clear (self):
Self.__result = 0
return self
@property
def result (self):
Return Self.__result
C1 = Caculator (10)
# Chain programming thinking with return self can do it
C1.jia (6). Jian (4). Chen (5). Show (). Clear (). Jia (555). Jian (). Show ()
C1.result
Python Speech recognition (calculator)