在哪里放置经过训练的语音模型
Where to place trained Speech model
我使用 sphinxtrain 训练了 pocketsphinx。我面临的问题是我不知道如何在我的代码中使用经过训练的模型。
我的第一个想法是只替换 pocketsphinx 库中的当前模型或以某种方式包含经过训练的模型。
我搜索了很多,但我发现的大部分内容都是基于使用 tensorflow 进行训练或谷歌的识别软件,但没有关于如何使用经过训练的模型。
下面是代码工作原理的基本示例:
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)
我使用 pocketsphinx 的 LiveSpeech()
解决了这个问题
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)
在此示例中,if 语句的输出应如下所示
recognized
hello
else 语句也是这样
not recognized
hi
我使用 sphinxtrain 训练了 pocketsphinx。我面临的问题是我不知道如何在我的代码中使用经过训练的模型。
我的第一个想法是只替换 pocketsphinx 库中的当前模型或以某种方式包含经过训练的模型。
我搜索了很多,但我发现的大部分内容都是基于使用 tensorflow 进行训练或谷歌的识别软件,但没有关于如何使用经过训练的模型。
下面是代码工作原理的基本示例:
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)
我使用 pocketsphinx 的 LiveSpeech()
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)
在此示例中,if 语句的输出应如下所示
recognized
hello
else 语句也是这样
not recognized
hi