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

2024-04-26 06:40:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: 脚本信息终端图书馆googlepi语音单词
2条回答

你可以在覆盆子派上使用袖珍斯芬克斯。您需要下载最新版本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文件应该如下所示,每行一个短语,带有threshold

^{pr2}$

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

好吧,你可以把贾斯帕的name换成别的。甚至是一根空弦。在

相关问题 更多 >

    热门问题