2016-08-05 24 views
2

是否有可能使用相同的解碼器在Pocketsphinx(Python)中的多個wav文件?我有下面的代碼片斷,這是非常標準的,除了我在同一個文件上調用兩次解碼器。然而,輸出不一樣。我也嘗試在不同的文件上使用解碼器兩次,輸出不同,這取決於我稱之爲文件的順序 - 第一個文件解碼正確,但第二個文件解碼不正確。此外,只有在第一個文件有輸出時纔會發生這種情況 - 如果第一個文件沒有任何文字,則第二個文件解碼正常。這使我相信在解碼一個文件後,解碼器會以某種方式被修改。我對此有糾正嗎?有什麼方法可以重置解碼器,或者一般情況下它可以用於多個文件?似乎應該在這裏給出例子:https://github.com/cmusphinx/pocketsphinx/blob/master/swig/python/test/decoder_test.py你可以在Pocketsphinx中使用相同的解碼器來處理多個文件嗎?

config = ps.Decoder.default_config()  
config.set_string('-hmm', os.path.join(MODELDIR, 'en-US/acoustic-model')) 
config.set_string('-lm', os.path.join(MODELDIR, 'en-US/language-model.lm.bin')) 
config.set_string('-dict', os.path.join(MODELDIR, 'en-US/pronounciation-dictionary.dict')) 
config.set_string('-logfn', 'pocketsphinxlog') 
decoder = ps.Decoder(config) 

wavname16_1 = os.path.join(DATADIR, 'arctic_a0001.wav') 
# Decode streaming data. 
decoder.start_utt() 
stream = open(wavname16_1, 'rb') 
while True: 
    buf = stream.read(1024) 
    if buf: 
     decoder.process_raw(buf, False, False) 
    else: 
     break 
decoder.end_utt() 
stream.close() 
words = [(seg.word, seg.prob) for seg in decoder.seg()] 
print words 

wavname16_2 = os.path.join(DATADIR, 'arctic_a0002.wav') 
decoder.start_utt() 
stream = open(wavname16_2, 'rb') 
while True: 
    buf = stream.read(1024) 
    if buf: 
     decoder.process_raw(buf, False, False) 
    else: 
     break 
decoder.end_utt() 
stream.close() 
words = [(seg.word, seg.prob) for seg in decoder.seg()] 
print "arctic2: " + words 

編輯 - 一些進一步的信息:

如果arctic_a0001.wav是http://festvox.org/cmu_arctic/cmu_arctic/cmu_us_bdl_arctic/wav/arctic_a0001.wav,arctic_a0002.wav是http://festvox.org/cmu_arctic/cmu_arctic/cmu_us_bdl_arctic/wav/arctic_a0002.wav,和字典是單線:

of AH V 

那麼電流輸出:

arctic1: [('<s>', 1), ('of', 1), ('of', -12001), ('<sil>', 0), ('of', -16211), ('<sil>', -1205), ('of', -13991), ('of', 0), ('<sil>', 0), ('of', -31232), ('</s>', 0)] 
arctic2: [('<s>', -3), ('[SPEECH]', -725), ('<sil>', -1), ('[SPEECH]', -6), ('<sil>', -20), ('of', -6162), ('[SPEECH]', -397), ('</s>', 0)] 

但是如果我們切換它們,t他的輸出變成

arctic2: [('<s>', 0), ('of', 0), ('<sil>', 0), ('of', -29945), ('<sil>', -20), ('of', -26004), ('of', 0), ('of', 0), ('<sil>', 0), ('of', -84868), ('of', -35690), ('</s>', 0)] 
arctic1: [('<s>', -3), ('of', -14886), ('of', -30237), ('<sil>', 0), ('of', -22103), ('of', 1), ('<sil>', 0), ('of', -30795), ('of', -65040), ('</s>', 0)] 

因此,北極1和北極2的輸出取決於順序。此外,如果我們使用arctic1兩次,輸出是

[('<s>', 1), ('of', 1), ('of', -12001), ('<sil>', 0), ('of', -16211), ('<sil>', -1205), ('of', -13991), ('of', 0), ('<sil>', 0), ('of', -31232), ('</s>', 0)] 
[('<s>', 1), ('of', -24424), ('of', -24554), ('<sil>', 2), ('[SPEECH]', -37257), ('of', -37008), ('<sil>', -461), ('of', -20422), ('of', 0), ('<sil>', 0), ('of', -3570), ('[SPEECH]', -42), ('</s>', 0)] 

也許這是一個問題,我沒有使用start_stream()?我不知道我該如何使用它。即使我用decoder.start_stream()(直接decoder.start_utt()之前),輸出會有所不同 - 它成爲

[('<s>', 1), ('of', 1), ('of', -12001), ('<sil>', 0), ('of', -16211), ('<sil>', -1205), ('of', -13991), ('of', 0), ('<sil>', 0), ('of', -31232), ('</s>', 0)] 
[('<s>', -2), ('of', -33113), ('of', -29715), ('<sil>', 1), ('[SPEECH]', -37258), ('of', -37009), ('<sil>', -461), ('of', -20422), ('of', 0), ('<sil>', 0), ('of', -3570), ('[SPEECH]', -42), ('</s>', 0)] 

如果你想整個日誌,這裏(http://pastebin.com/2dNeyS1x)是之前的日誌arctic1 arctic2,這裏(http://pastebin.com/Nkvj2G0g)是arctic1之前的日誌,而這裏是start_stream(http://pastebin.com/HWq6j7X2)連續兩次arctic1的日誌,這裏是沒有start_stream的連續兩次arctic1的日誌(http://pastebin.com/MsadW4nh) 。

回答

0

是否可以在Pocketsphinx(Python)中對多個wav文件使用相同的解碼器?

我有下面的代碼片段,這是非常標準的,只是我在同一個文件中調用解碼器的兩倍。然而,輸出不一樣。

您需要撥打decoder.start_stream()第二個文件才能重置解碼器時序。

我也試過在不同的文件上使用解碼器兩次,輸出是不同的,這取決於我稱之爲文件的順序 - 第一個文件解碼正確,但第二個文件解碼不正確。此外,只有在第一個文件有輸出時纔會發生這種情況 - 如果第一個文件沒有任何文字,則第二個文件解碼正常。

那麼,可能會有不同的事情會影響結果。沒有例子很難說。你最好提供樣本文件和有問題的輸出來得到關於這個問題的答案。

+0

嗨,我將無法對此做出迴應,直到星期一,因爲我的文件正在工作,但我只是想感謝您的回覆如此之快! – user6003782

+0

我編輯了父帖子以包含示例文件和輸出!需要幫助請叫我。 – user6003782

+0

我在日誌中看不到任何錯誤。結果可能會稍有不同,因爲解碼器保持內部狀態(CMN值),您可以在日誌中看到它。第三次迭代應該與第二次相同。 –

相關問題