Dev*_*Tec 2 python speech-recognition asynchronous raspberry-pi
我想在Python中为Raspberry Pi创建一个语音识别脚本,需要一个异步/连续语音识别库.异步意味着我需要无休止地运行识别,直到语音与单词数组匹配而没有来自键盘的任何输入,然后将语音显示到终端并重新开始识别.我已经看过PocketSphinx,但经过几个小时的谷歌搜索,我没有找到任何关于异步识别的东西.
你知道有能力的图书馆吗?
你可以在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()
Run Code Online (Sandbox Code Playgroud)
该keypharse.list文件应如下所示,每行一个带阈值的短语
open the door /1e-40/
close the door /1e-40/
how are you /1e-30/
Run Code Online (Sandbox Code Playgroud)
必须针对每个关键短语调整阈值,以在错误警报和误检测之间取得平衡.
| 归档时间: |
|
| 查看次数: |
2180 次 |
| 最近记录: |