I am trying to extract the start and end timestamps of each segment using pocketsphinx. The code below works for extracting the word token. How can I access the timestamps?
I've tried looking at the documentation here http://cmusphinx.sourceforge.net/doc/pocketsphinx/index.html but could not find the method
#!/usr/bin/env python
import os
import sphinxbase as sb
import pocketsphinx as ps
MODELDIR = 'deps/pocketsphinx/model'
DATADIR = 'deps/pocketsphinx/test/data'
# Create a decoder with certain model
config = ps.Decoder.default_config()
config.set_string('-hmm', os.path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-lm', os.path.join(MODELDIR, 'en-us/en-us.lm.bin'))
config.set_string('-dict', os.path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
decoder = ps.Decoder(config)
# Decode streaming data.
decoder.start_utt()
stream = open(os.path.join(DATADIR, 'goforward.raw'), 'rb')
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
decoder.end_utt()
stream.close()
print('Best hypothesis segments:', [seg.word for seg in decoder.seg()])
You can explore segment in ipython
print('Best hypothesis segments:', [(seg.word, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
Frame size is 1/100 second.