By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

ContextEvents and Tkinter

P: 1
I have one problem with the following code:

Expand|Select|Wrap|Line Numbers
  1. from win32com.client import constants
  2. import win32com.client
  3. import win32gui
  4. import pythoncom
  5. from Tkinter import *
  6.  
  7. class SpeechRecognition:
  8.         def __init__(self, wordsToAdd):
  9.         self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  10.         self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
  11.         self.context = self.listener.CreateRecoContext()
  12.         self.grammar = self.context.CreateGrammar()
  13.         self.grammar.DictationSetState(0)
  14.         self.wordsRule = self.grammar.Rules.Add("wordsRule",constants.SRATopLevel + constants.SRADynamic, 0)
  15.         self.wordsRule.Clear()
  16.         [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
  17.         self.grammar.Rules.Commit()
  18.         self.grammar.CmdSetRuleState("wordsRule", 1)
  19.         self.grammar.Rules.Commit()
  20.         self.eventHandler = ContextEvents(self.context)
  21.     def say(self, phrase):
  22.         self.speaker.Speak(phrase)
  23.  
  24. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  25.     def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  26.         newResult = win32com.client.Dispatch(Result)
  27.         globals()['fraza']=newResult.PhraseInfo.GetText()
  28.         print "You said: ",fraza
  29.         if fraza=='winamp':
  30.             speechReco.say("What")
  31.             graf.list1.delete(0,END)
  32.             graf.list1.insert(END,fraza)
  33.  
  34. class App:
  35.  
  36.     def __init__(self, master):
  37.         self.list1=Listbox(master,bg='pink',width='20',height='1',font=("Comic Sans MS",14))
  38.         self.list1.pack(anchor=W)
  39.         self.list1.insert(0,'Hey')
  40.  
  41.  
  42. if __name__=='__main__':
  43.     globals()['fraza']=1
  44.     wordsToAdd = ['winamp','play']
  45.     speechReco = SpeechRecognition(wordsToAdd)
  46.     root=Tk()
  47.     graf=App(root)
  48.     root.mainloop()
  49.  
Problem is with these 2 lines (41,42):
graf.list1.delete(0,END)
graf.list1.insert(END,fraza)
because program stops and is not responding any more when it come to this lines. If these two lines are not in class ContextEvents, the program works fine but i need them in there. Even if I call function with this two lines from ContextEvents the program freeze.

The program must delete text and insert text 'winamp' in Tkinter Label when i say winamp in microfone. Everything works fine but when i say 'winamp' program freeze. How can i solve this problem. Please help.
May 14 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.