在pocketsphinx中的段时间戳

时间:2016-06-22 16:22:29

标签: speech-recognition cmusphinx

我正在尝试使用pocketsphinx提取每个段的开始和结束时间戳。下面的代码用于提取单词令牌。如何访问时间戳?

我已经尝试查看此处的文档http://cmusphinx.sourceforge.net/doc/pocketsphinx/index.html,但找不到方法

#!/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()])

1 个答案:

答案 0 :(得分:3)

您可以在ipython中探索细分

 print('Best hypothesis segments:', [(seg.word, seg.start_frame, seg.end_frame) for seg in decoder.seg()])

帧大小为1/100秒。