Advertisement
Guest User

Untitled

a guest
May 24th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1.  
  2.     def run(self):
  3.         # Thanks to the question and answers:
  4.         # http://stackoverflow.com/questions/4417546/constantly-print-subprocess-output-while-process-is-running
  5.         def execute(cmd):
  6.             process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
  7.             bar()
  8.             stdout_lines = iter(process.stdout.readline, "")
  9.             for stdout_line in stdout_lines:
  10.                 yield stdout_line
  11.  
  12.             process.stdout.close()
  13.             return_code = process.wait()
  14.             if return_code != 0:
  15.                 raise subprocess.CalledProcessError(return_code, cmd)
  16.  
  17.         pattern = re.compile('^(?!INFO)(.+)')  # lines starting with 9 digits
  18.  
  19.         cmd = ['pocketsphinx_continuous', '-inmic', 'yes', '-lm',
  20.                '/usr/share/pocketsphinx/model/en-us/en-us.lm.bin', '-mdef',
  21.                '/usr/share/pocketsphinx/model/en-us/en-us/mdef', '-dict',
  22.                '/usr/share/pocketsphinx/model/en-us/cmudict-en-us.dict']
  23.  
  24.         for stdout_line in execute(cmd):
  25.             # Print out the line to give the same experience as
  26.             # running pocketsphinx_continuous.
  27.             # print(out)  # newline included by the line itself
  28.             if self._listening:
  29.                 print(stdout_line)
  30.                 stdout_line_match = pattern.match(stdout_line)
  31.                 if stdout_line_match:
  32.                     phrase = stdout_line_match.group(1).strip()
  33.                     if phrase:
  34.                         self.phrase_queue.put(phrase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement