gpt4 book ai didi

python - 有没有办法在 pocketsphinx python 中返回整个字典条目(单词+音素)?

转载 作者:行者123 更新时间:2023-12-01 03:15:15 25 4
gpt4 key购买 nike

这是我的代码:

#!/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, 'hello_world.wav'), '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()])

我在 this stack overflow question 中找到的

音频文件 hello_world.wav 正确输出:“最佳假设片段:hello world”

这是我的问题。我正在查看位于/Library/Python/2.7/site-packages/speech_recognition/pocketsphinx-data/en-US 的发音词典.dict 文件,它似乎将英语单词映射到音素。

“hello”和“world”的条目是:

hello HH AH L OW 
world W ER L D

我想从字典中返回整行。所以,我想要的不仅仅是“你好”,而是“你好 HH AH L OW”。有办法做到这一点吗?

最佳答案

获得结果后,您可以查找该单词的发音:

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

关于python - 有没有办法在 pocketsphinx python 中返回整个字典条目(单词+音素)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42500907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com