家庭助理需要称为热词的特殊短语才能激活(例如“OK Google”)。 EfficientWord-Net 是一种基于小样本学习的热词检测引擎,允许开发人员将自定义热词添加到他们的程序中,而无需额外付费。该库纯粹用 Python 编写,并使用 Google 的 TFLite 实现来实现更快的实时推理。它受到 FaceNet 的 Siamese 网络架构的启发,在直接从用户收集 3-4 个热词样本时表现最佳。
培训文件访问培训文件。
以下是链接:
研究论文访问研究论文。
该库适用于 Python 版本 3.6 至 3.9。
在运行库的 pip 安装命令之前,需要手动安装一些依赖项:
Mac OS M* 和 Raspberry Pi 用户可能必须编译这些依赖项。
tflite包无法在requirements.txt 中列出,因此当该包在系统中初始化时会自动安装。
仅推理情况不需要librosa包。但是,当调用generate_reference
时,它会自动安装。
运行以下 pip 命令:
pip install EfficientWord-Net
导入包:
import eff_word_net
安装软件包后,您可以运行库中内置的演示脚本(确保您有一个可用的麦克风)。
访问文档:https://ant-brain.github.io/EfficientWord-Net/
运行演示的命令:
python -m eff_word_net.engine
对于任何新的热词,图书馆需要有关该热词的信息。此信息是从名为{wakeword}_ref.json
的文件中获取的。例如,对于唤醒词“alexa”,库需要名为alexa_ref.json
的文件。
这些文件可以通过以下过程生成:
收集给定唤醒词的 4 到 10 个发音独特的发音。将它们放入不包含其他任何内容的单独文件夹中。
或者,使用以下命令为给定单词生成音频文件(使用 IBM 神经 TTS 演示 API)。为了我们的利益,请不要过度使用它:
python -m eff_word_net.ibm_generate
python -m eff_word_net.generate_reference
生成的唤醒词的路径名需要传递给 HotwordDetector 实例:
HotwordDetector (
hotword = "hello" ,
model = Resnet_50_Arc_loss (),
reference_file = "/full/path/name/of/hello_ref.json" ,
threshold = 0.9 , # min confidence required to consider a trigger
relaxation_time = 0.8 # default value, in seconds
)
模型变量可以接收 Resnet_50_Arc_loss 或 First_Iteration_Siamese 的实例。
relaxation_time 参数用于确定任意两个触发器之间的最短时间。 Relax_time 之前的任何潜在触发器都将被取消。该检测器采用滑动窗口方法运行,从而导致单个热词的多次触发。 relaxation_time参数可用于控制多个触发器;在大多数情况下,0.8 秒(默认)就足够了。
该库已经为一些唤醒词(例如Mycroft 、 Google 、 Firefox 、 Alexa 、 Mobile和Siri)提供了预定义的嵌入。它们的路径在库安装目录中很容易获得。
from eff_word_net import samples_loc
import os
from eff_word_net . streams import SimpleMicStream
from eff_word_net . engine import HotwordDetector
from eff_word_net . audio_processing import Resnet50_Arc_loss
from eff_word_net import samples_loc
base_model = Resnet50_Arc_loss ()
mycroft_hw = HotwordDetector (
hotword = "mycroft" ,
model = base_model ,
reference_file = os . path . join ( samples_loc , "mycroft_ref.json" ),
threshold = 0.7 ,
relaxation_time = 2
)
mic_stream = SimpleMicStream (
window_length_secs = 1.5 ,
sliding_window_secs = 0.75 ,
)
mic_stream . start_stream ()
print ( "Say Mycroft " )
while True :
frame = mic_stream . getFrame ()
result = mycroft_hw . scoreFrame ( frame )
if result == None :
#no voice activity
continue
if ( result [ "match" ]):
print ( "Wakeword uttered" , result [ "confidence" ])
该库提供了一种计算友好的方法来检测给定流中的多个热词,而不是单独运行每个唤醒词的scoreFrame()
import os
from eff_word_net . streams import SimpleMicStream
from eff_word_net import samples_loc
print ( samples_loc )
base_model = Resnet50_Arc_loss ()
mycroft_hw = HotwordDetector (
hotword = "mycroft" ,
model = base_model ,
reference_file = os . path . join ( samples_loc , "mycroft_ref.json" ),
threshold = 0.7 ,
relaxation_time = 2
)
alexa_hw = HotwordDetector (
hotword = "alexa" ,
model = base_model ,
reference_file = os . path . join ( samples_loc , "alexa_ref.json" ),
threshold = 0.7 ,
relaxation_time = 2 ,
#verbose=True
)
computer_hw = HotwordDetector (
hotword = "computer" ,
model = base_model ,
reference_file = os . path . join ( samples_loc , "computer_ref.json" ),
threshold = 0.7 ,
relaxation_time = 2 ,
#verbose=True
)
multi_hotword_detector = MultiHotwordDetector (
[ mycroft_hw , alexa_hw , computer_hw ],
model = base_model ,
continuous = True ,
)
mic_stream = SimpleMicStream ( window_length_secs = 1.5 , sliding_window_secs = 0.75 )
mic_stream . start_stream ()
print ( "Say " , " / " . join ([ x . hotword for x in multi_hotword_detector . detector_collection ]))
while True :
frame = mic_stream . getFrame ()
result = multi_hotword_detector . findBestMatch ( frame )
if ( None not in result ):
print ( result [ 0 ], f",Confidence { result [ 1 ]:0.4f } " )
从这里访问该库的文档:https://ant-brain.github.io/EfficientWord-Net/
以下是 README.md 文件的更正版本,改进了语法和格式:
与 Porcupine 相比,我们的热词检测器的性能明显较低。我们已经为引擎考虑了更好的神经网络架构,并希望能够超越 Porcupine。这是我们的本科项目,因此您的支持和鼓励将激励我们进一步开发引擎。如果您喜欢这个项目,请将其推荐给您的同行,给我们一个?在 GitHub 上,鼓掌?在媒体上。
更新:你们的星星鼓励我们创建一个更好的新模型。让我们让这个社区成长!
阿帕奇许可证 2.0