Guest User

Untitled

a guest
Oct 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import sys, os, pyaudio
  2. from pocketsphinx.pocketsphinx import *
  3. from sphinxbase.sphinxbase import *
  4.  
  5. modeldir = "../../../model"
  6.  
  7. # Create a decoder with certain model
  8. config = Decoder.default_config()
  9. config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us'))
  10. config.set_string('-dict', os.path.join(modeldir, 'en-us/cmudict-en-us.dict'))
  11. config.set_string('-kws', 'command.list')
  12.  
  13. p = pyaudio.PyAudio()
  14. stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True)
  15. stream.start_stream()
  16.  
  17. # Process audio chunk by chunk. On keyword detected perform action and restart search
  18. decoder = Decoder(config)
  19. decoder.start_utt()
  20. while True:
  21. buf = stream.read(1024)
  22.  
  23. decoder.process_raw(buf, False, False)
  24.  
  25. if decoder.hyp() != None:
  26. print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
  27. print ("Detected keyword, restarting search")
  28. #
  29. # Here you run the code you want based on keyword
  30. #
  31. decoder.end_utt()
  32. decoder.start_utt()
  33.  
  34. forward /1e-1/
  35. down /1e-1/
  36. other phrase /1e-20/
Add Comment
Please, Sign In to add comment