Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def run(self):
- # Thanks to the question and answers:
- # http://stackoverflow.com/questions/4417546/constantly-print-subprocess-output-while-process-is-running
- def execute(cmd):
- process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
- bar()
- stdout_lines = iter(process.stdout.readline, "")
- for stdout_line in stdout_lines:
- yield stdout_line
- process.stdout.close()
- return_code = process.wait()
- if return_code != 0:
- raise subprocess.CalledProcessError(return_code, cmd)
- pattern = re.compile('^(?!INFO)(.+)') # lines starting with 9 digits
- cmd = ['pocketsphinx_continuous', '-inmic', 'yes', '-lm',
- '/usr/share/pocketsphinx/model/en-us/en-us.lm.bin', '-mdef',
- '/usr/share/pocketsphinx/model/en-us/en-us/mdef', '-dict',
- '/usr/share/pocketsphinx/model/en-us/cmudict-en-us.dict']
- for stdout_line in execute(cmd):
- # Print out the line to give the same experience as
- # running pocketsphinx_continuous.
- # print(out) # newline included by the line itself
- if self._listening:
- print(stdout_line)
- stdout_line_match = pattern.match(stdout_line)
- if stdout_line_match:
- phrase = stdout_line_match.group(1).strip()
- if phrase:
- self.phrase_queue.put(phrase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement