2016-07-28 31 views
3

私はpythonを使って音声認識をしようとしています。それに加えて、私は各単語の始めと終わりの時を知る必要があります。Python - 音声認識の時間オフセット

私はむしろこれに対処できる無料のライブラリを使用したいと思います。私はSphinxがこれを行うことができると聞いてきましたが、(たとえとにかくPythonのために)何かの例が見つかりませんでした。

私は何か助けや提案をいただきありがとうございます。このような

答えて

0

何か:

from os import environ, path 

from pocketsphinx.pocketsphinx import * 
from sphinxbase.sphinxbase import * 

MODELDIR = "../../../model" 
DATADIR = "../../../test/data" 

config = Decoder.default_config() 
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us')) 
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin')) 
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict')) 
config.set_string('-logfn', '/dev/null') 
decoder = Decoder(config) 

stream = open(path.join(DATADIR, 'goforward.raw'), 'rb') 

in_speech_bf = False 
decoder.start_utt() 
while True: 
    buf = stream.read(1024) 
    if buf: 
     decoder.process_raw(buf, False, False) 
     if decoder.get_in_speech() != in_speech_bf: 
      in_speech_bf = decoder.get_in_speech() 
      if not in_speech_bf: 
       decoder.end_utt() 
       print ('Result:', decoder.hyp().hypstr) 
       print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()]) 
       decoder.start_utt() 
    else: 
     break 
decoder.end_utt() 

より多くの例here