aash29 / pyspeech

Automatically exported from code.google.com/p/pyspeech
0 stars 0 forks source link

Speech.input() doesn't work when imported, and then re-imported into a new file. #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make a Python file (start.py), and in it, import speech.
2. Type in, "var = speech.input()" on a new line.
3. Make a NEW Python file, and type "import start".

What is the expected output? What do you see instead?
The speech should be captured and entered into a string, and though the
program IS trying to record sound, it's not capturing anything!

What version of the product are you using? On what operating system?
Windows XP Home Edition, Python 2.5... latest pyspeech / SAPI5 versions, I
believe.

Original issue reported on code.google.com by nathan...@xyteran.com on 20 Feb 2009 at 2:34

GoogleCodeExporter commented 9 years ago
Reproduced on WinXP Py2.5 speech 0.5.2

Original comment by gundl...@gmail.com on 2 Mar 2009 at 1:19

GoogleCodeExporter commented 9 years ago
The partial diagnosis of the bug: Python is unhappy when you do "real work" 
during
module import (stuff beyond defining classes and functions.).  I've seen this 
with
the paramiko ssh package: if module a.py tries to connect to a remote client, 
and
b.py imports a, then the ssh will hang.

I'm not sure what "real work" entails -- starting threads? using COM objects? 
opening
raw sockets? -- so I don't know the true root cause of the problem.

The workaround is to have start.py define a method "main()", in which it does 
its
"real work"; then have the other python script do

import start
start.main()

Let me know if this does not work.

Original comment by gundl...@gmail.com on 2 Mar 2009 at 1:46

GoogleCodeExporter commented 9 years ago
Thank you for your reply;

I'm very new to Python (I've always been the web application guy) so how do I 
define
a main() method?

Thanks. :)

Original comment by nathan...@xyteran.com on 2 Mar 2009 at 11:33

GoogleCodeExporter commented 9 years ago
Pardon me!  You've been a regular commenter here so I assumed you were quite 
deep
into the guts of Python :)

You define a function (I called it a method above erroneously) called 'foo' 
like this:

def foo():
  your stuff here

So, start.py would look something like:

import speech
# defining functions is fine
def callback(phrase, listener):
  # do something

def main():
  # actually running speech functions is not fine, so put its use in a function
  # to be called later.  I named mine main(), as lots of people tend to do.
  listener = speech.listenfor(['howdy', 'partner'], callback)
  import time
  time.sleep(60) # sixty seconds to handle 'howdy' and 'partner' over and over

and other.py (perhaps 'main.py' or __init__.py) looks like:

import start
start.main() # run the stuff that you *wanted* to run via plain import

Good luck!
Michael

Original comment by gundl...@gmail.com on 3 Mar 2009 at 1:26

GoogleCodeExporter commented 9 years ago
Oh, just a function? I know how to do that, haha. :P Thanks!

Original comment by nathan...@xyteran.com on 3 Mar 2009 at 2:15