JLing
JLing是一個可以工作在Linux的自定義中文語音對話機器人
(csdn :https://blog.csdn.net/weixin_40490238)
(github: https://github.com/Kingzhoudk/JLing)
需要使用JLing的離線語音喚醒功能,就需要編譯出適合自己用的_snowboydetect.so
版本:Ubuntu18.03
1、打開文件夾SupportFiles,對snowboy-master.zip進行解壓
2、安裝需要的環境,對snowboy進行編譯
- 安裝swig(3.0.10或者更高的版本)
sudo apt-get install swig
- 然後安裝atlas矩陣計算庫:(必須安裝,否則編譯報錯)
sudo apt-get install libatlas-base-dev
3、打開snowboy的文件夾
cd /snowboy/swig/Python3
make
4、將得到的_snowboydetect.so放入JLing/Snowboy文件夾內
5、生成自己的喚醒詞:https://snowboy.kitt.ai/hotword/34901
- 然後將自己的**.pmdl文件放入JLing/Snowboy文件夾內
運行
python3 demo.py JLing.pmdl
若運行成功,有喚醒提示
硬件:Raspberry Pi 系統:Debian
詳見我之前寫的博客:https://blog.csdn.net/weixin_40490238/article/details/88848335
Snowboy demo的編寫
先上代碼:
import snowboydecoder
import sys
import signal
sys.path.append("..")
from Log import Logger
class Snowboy_JLing:
def __init__(self, model, sensitivity):
self.interrupted = False
self.model = model
self.sensitivity = sensitivity
self.detector = snowboydecoder.HotwordDetector(self.model, sensitivity=self.sensitivity)
def __del__(self):
self.detector.terminate()
def signal_handler(self):
snowboydecoder.play_audio_file()
self.interrupted = True
def interrupt_callback(self):
return self.interrupted
def start(self):
print('Listening... Press Ctrl+C to exit')
self.detector.start(detected_callback=self.signal_handler,
interrupt_check=self.interrupt_callback,
sleep_time=0.03)
self.interrupted = False
- 啓動語音檢測器。對於每一個“sleep_time”秒,它檢查音頻緩衝區觸發關鍵字。如果檢測到,則在`detected_callback '中調用相應的函數,它可以是一個單函數(單模型)或一個回調函數列表(多個)
- 它還調用每個循環“interrupt_check”——如果返回True,則從循環中斷開並返回。
- :param detected_callback:函數或函數列表。項目的數量必須與“decoder_model”中的模型數量匹配。
- :param interrupt_check:如果主循環需要停止,則返回True的函數。
- :param float sleep_time:每個循環每秒等待的時間。
在運行時,創建Snowboy_JLing類
# model爲喚醒詞的文件名,比如:“JLing.pmdl”;
# sensitivity爲靈敏度參數,0<sensitivity<1
JLing=Snowboy_JLing(model,sensitivity)
JLing.start()
每次擊中響應,都會播放ding的一聲