在何处放置经过训练的语音模型

时间:2019-06-22 03:26:44

标签: python-3.x speech-recognition pocketsphinx

我已经使用sphinxtrain训练了Pocketsphinx。我面临的问题是我不知道如何在代码中使用经过训练的模型。

我的第一个想法是只是替换Pocketsphinx库中的当前模型或以某种方式包括经过训练的模型。

我进行了很多搜索,但发现的大部分内容都基于使用tensorflow进行训练或使用Google的识别软件,但与如何使用经过训练的模型无关。

这是代码工作原理的基本示例:

import speech_recognition as sr


r = sr.Recognizer()
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source)
    audio = r.listen(source)



output = r.recognize_sphinx(audio)
print(output)

1 个答案:

答案 0 :(得分:1)

我通过使用Pocketsphinx的Jackson

解决了这个问题
LiveSpeech()

在此示例中,if语句

的输出应类似于以下内容
import os
from pocketsphinx import LiveSpeech, get_model_path
model_path = get_model_path()

speech = LiveSpeech(
    verbose=False,
    sampling_rate=16000,
    buffer_size=2048,
    no_search=False,
    full_utt=False,
    hmm=os.path.join(model_path, 'en-us'),
    lm=os.path.join(model_path, 'en-us.lm.bin'),
    dic=os.path.join(model_path, 'cmudict-en-us.dict')
)

for phrase in speech:
    output = phrase.hypothesis()

    if output == 'hello':
        print("recognized")
        print(output)
    else:
        print("not recognized")
        print(output)

并在else语句中这样

recognized
hello