Python Speech recognition (calculator)

Source: Internet
Author: User
Tags sapi

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.