我整天都在工作,试图获得一个可以完成各种工作的 Python 程序。因为我得到了另一个人的大部分代码,所以我大部分时间都在解决错误,但是现在,我有一个我无法克服的错误。
下面是代码,下面是输出。
import speech
import datetime
import speakWebPage
import os
import Weather
import ReadMail
def getCurrentTime():
"""
Returns the properly formatted current time
"""
now = datetime.datetime.now();
hr = now.hour
greeting = ""
ampm = ""
if (hr < 12): #morning
hr = hr
greeting = "morning"
ampm = "am"
elif(hr>=12 and hr <1): #afternoon
hr = hr-12
greeting = "afternoon"
ampm = "noon"
elif(hr>12 and hr <19): #evening
hr = hr-12
greeting = "evening"
ampm = "pm"
else:
hr = hr -12
greeting = "night"
ampm = "pm"
return [str(hr) + 'O' + str(now.minute), ampm, ' in the ', greeting]
def morning_greetings():
speech.say ("Good Morning.")
speech.say(" It is "+''.join(getCurrentTime()))
speech.say(Weather.getCurrentWather())
check_mails()
def check_mails():
speech.say("Checking mails. Please wait ...")
count = ReadMail.getUnreadMailCount()
if (count <= 0):
speech.say("You have NO unread mails")
else:
speech.say("You have "+ str(count) + " unread mails")
def handleCallback(phrase, listner):
#speech.say('You said %s' % phrase)
if phrase == "jarvis" or phrase == "jaiss":
print (phrase)
speech.say("Yes Boss")
elif phrase == "are you up":
speech.say("definitely. at your service sir!")
elif phrase == "what is the current time":
speech.say(getCurrentTime())
elif phrase == "turn off":
print (phrase)
speech.say("Turning Off")
listner.stoplistening()
elif phrase == "how are you":
print (phrase)
speech.say("I am good. Thank you. How are you.")
elif phrase == "read news":
print (phrase)
feeds = speakWebPage.readFeeds()
speech.say(feeds)
elif phrase == "show my feeds":
print (phrase)
speech.say("Launching Google Reader")
os.system("C:\Users\kshwetabh\AppData\Local\Google\Chrome\Application\chrome.exe
reader.google.com")
elif phrase == "how is the weather outside":
speech.say("Getting current weather. Please wait...!")
print (phrase)
speech.say(Weather.getCurrentWather())
elif phrase == "get me the weather forecast":
speech.say("Getting weather forecast. Please wait...!")
print (phrase)
speech.say("This week's weather forecast:")
for item in Weather.getWeatherForecast():
speech.say(item)
elif phrase == "any new mails":
check_mails()
print (phrase)
elif phrase == "morning greetings":
morning_greetings()
else:
print (phrase)
speech.say("Could not understand, please repeat")
listner = speech.listenfor(['jarvis', 'jaiss', 'turn off',
'how are you', 'read news',
'stop' , 'show my feeds',
'what is the current time',
'are you up', 'how is the weather outside',
'get me the weather forecast',
'any new mails', '*', 'morning greetings'], handleCallback)
import time
while listner.islistening():
time.sleep(1)
#print "Waiting for Command"
输出(错误:
Traceback (most recent call last): File
"C:\Users\Alex\Desktop\JAVIS\JAISS-master\first.py", line 113, in
<module>
'any new mails', '*', 'morning greetings'], handleCallback) File "build/bdist.macosx-10.8-intel/egg/speech.py", line 206, in listenfor
return _startlistening(phraselist, callback) File "build/bdist.macosx-10.8-intel/egg/speech.py", line 222, in
_startlistening
context = _recognizer.CreateRecoContext() File "C:\Python27\lib\site-packages\win32com\gen_py\C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x4.py",
line 2640, in CreateRecoContext
ret = self._oleobj_.InvokeTypes(10, LCID, 1, (9, 0), (),) com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
0, -2147200904), None)