我想在Python中为Raspberry Pi创建一个语音识别脚本,需要一个异步/连续语音识别库。异步意味着我需要无休止地运行识别,直到语音与单词数组匹配而没有来自键盘的任何输入,然后将语音显示到终端并重新开始识别。我已经看过PocketSphinx,但经过几个小时的谷歌搜索,我没有找到任何关于异步识别的东西。
你知道任何有能力的图书馆吗?
答案 0 :(得分:8)
您可以在Raspberry Pi上使用Pocketsphinx。你需要下载最新版本5prealpha。
它可以收听多个关键短语。代码应该是这样的:
import sys, os
from pocketsphinx import *
import pyaudio
modeldir = "../../../model"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us'))
config.set_string('-dict', os.path.join(modeldir, 'en-us/cmudict-en-us.dict'))
config.set_string('-kws', 'keyphrase.list')
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
# Process audio chunk by chunk. On keyword detected perform action and restart search
decoder = Decoder(config)
decoder.start_utt()
while True:
buf = stream.read(1024)
decoder.process_raw(buf, False, False)
if decoder.hyp() != None:
print "Detected keyword", decoder.hyp(), "restarting search"
decoder.end_utt()
decoder.start_utt()
keypharse.list
文件应如下所示,每行一个带阈值的短语
open the door /1e-40/
close the door /1e-40/
how are you /1e-30/
必须针对每个关键短语调整阈值,以平衡误报和误检。
答案 1 :(得分:2)
好吧,你可以将Jasper的name更改为其他内容。也许,即使是空字符串。