【问题标题】:Python detect keywordsPython检测关键字
【发布时间】:2016-02-06 21:38:25
【问题描述】:

我正在做和应用程序做休闲:

1:如果麦克风检测到一些噪音,它会开始录制音频,直到没有检测到噪音。之后,音频被录制到 wav 文件中。

2:我要检测上面的一些字。只需要检测 5 到 10 个单词。

到目前为止,我的代码只完成了第一部分(检测噪音和录制音频)。现在,我有一个包含以下字词的列表:help, please, yes, no, could, you, after, tomorrow。我需要一种离线方式来检测我的声音是否包含这些词。这可能吗?我怎样才能做到这一点?我正在使用 linux,无法将我的操作系统更改为 windows 或使用虚拟机。

我正在考虑使用声音的频谱图,创建一个火车数据库并使用一些分类器进行预测。例如,this 是一个单词的频谱图。这是一个很好的技术吗?

谢谢。

【问题讨论】:

  • 您没有显示任何代码,也没有展示任何搜索工作。实际上,您的问题读起来像是对软件推荐的隐晦要求,这在此处是题外话;如果不是,那肯定是太宽泛了。我承认之前的近距离投票“过于广泛”。如果您可以edit您的问题来避免这两个问题,那么您也更有可能收到真正有用的答案。有关 Stack Overflow 的更多信息,请查看help center

标签: python audio offline voice-recognition


【解决方案1】:

您可以从 python 中使用 pocketsphinx,使用 pip install pocketsphinx 安装。代码如下所示:

import sys, os
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *


modeldir = "../../../model"
datadir = "../../../test/data"

# 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', 'command.list')


# Open file to read the data
stream = open(os.path.join(datadir, "goforward.raw"), "rb")

# Alternatively you can read from microphone
# import pyaudio
# 
# 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)
    if buf:
         decoder.process_raw(buf, False, False)
    else:
         break
    if decoder.hyp() != None:
        print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
        print ("Detected keyword, restarting search")
        decoder.end_utt()
        decoder.start_utt()

关键字列表应如下所示:

  forward /1e-1/
  down /1e-1/
  other phrase /1e-20/

数字是检测的阈值

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 2012-01-24
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
  • 2013-08-17
  • 2011-10-19
相关资源
最近更新 更多