Python中的Raspberry Pi异步/连续语音识别



我想用Python为Raspberry Pi创建一个语音识别脚本,需要一个异步/连续语音识别库。异步意味着我需要无休止地运行识别,直到说出的单词与一组单词匹配,而无需键盘输入,然后向终端显示说出的单词并重新启动识别。我已经看过PocketSphinx,但在谷歌上搜索了几个小时后,我没有发现任何关于异步识别的信息。

你知道有哪个图书馆能做到这一点吗?

您可以在树莓派上使用Pocketsphinx。您需要下载最新版本5realpha。

它可以监听多个关键短语。代码应该是这样的:

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/

必须针对每个关键短语调整阈值,以在错误警报和错误检测之间取得平衡。

好吧,你可以把Jasper的名字改成其他名字。也许,哪怕是一根空绳子。

最新更新