'2018/02'에 해당되는 글 5건

  1. 2018.02.19 Raspberry Pi Zero W와 Respeaker 2 Mic Hat에서 Snowboy 이용하기
반응형

Snowboy는  인공지능 스피커에서 특정 발화에 대해서 명령어 대기 상태가 되는 Keyword Spotting 을 지원해주는 도구이다. 본 포스팅에서는 Raspberry Pi Zero W에 마이크 입력과 스피커 출력을 제공해주는 ReSpeaker 2-Mic Hat(http://wiki.seeed.cc/ReSpeaker_2_Mics_Pi_HAT)을 기반으로 snowboy를 이용해서 KWS(Key-Word Spotting)을 해보도록 하겠다.


1. RPI-Zero-W용 node.js 준비

http://alnova2.tistory.com/1188 에서와 같이 raspberry pi zero용 node.js 를 컴파일하여 Raspberry Pi Zero에 설치한다.


2. ReSpeaker 2-Mic Hat Driver 설치

https://github.com/respeaker/seeed-voicecard 에서 가이드 된 것처럼 드라이버를 설치한다.


git clone https://github.com/respeaker/seeed-voicecard

cd seeed-voicecard

sudo ./install.sh 

sudo reboot


aplay -l 및 arecord -l로 seed-2mic-voicecard 가 정상적으로 보이는지 확인한다. 그리고 seed-2mic-voicecard를 기본 오디오 카드로 설정한다.


vi /usr/share/alsa/alsa.conf 에서 default 를 찾아서 다음 부분을 변경해줌

변경 전 

 변경 후

 defaults.ctl.card 0

defaults.pcm.card 0

defaults.pcm.device 0

 defaults.ctl.card 1

defaults.pcm.card 1

defaults.pcm.device 1


2. node-record-lpcm-16 패키지 설치

 npm install node-record-lpcm-16 명령으로 node.js에서 마이크 입력을 처리하기 위한 패키지를 설치한다. 실제 마이크 입력을 위해서는 다음의 리눅스 패키지를 설치해야 한다. 


sudo apt-get install sox libsox-fmt-all


실제 동작하는지는 다음의 코드로 확인해 본다.

var record = require('node-record-lpcm17')

var fs = require('fs')

var file = fs.createWriteStream('test.wav', { encoding: 'binary' })

record.start({

  sampleRate : 16000,

  verbose : true

}).pipe(file)


녹음된 파일을 다음으로 플레이 해본다. aplay test.wav


3. snowboy 패키지 설치

snowboy는 raspberry pi zero w에서 npm install로 설치되지 않는다. 직접 빌드해야 하는데 다음과 같이 빌드할 수 있다.


1) 소스 다운로드

git clone https://github.com/Kitt-AI/snowboy.git


2) 필요 패키지 설치

sudo apt-get install libmagic-dev libatlas-base-dev


3) 빌드: 1)의  snowboy 폴더에서..

npm install

./node_modules/node-pre-gyp/bin/node-pre-gyp clean configure build


snowboy 폴더를 프로젝트의 node_module 폴더에 옮겨 놓으면 된다. 다음으로 테스트 가능하다.


const Detector = require('./node_modules/snowboy/').Detector;

const Models = require('./node_modules/snowboy/').Models;

const models = new Models();

const record=require('node-record-lpcm16');

mic=record.start({

        sampleRateHertz: 16000,

        threshold: 0,

        verbose: false,

        recordProgram: 'arecord',

        silence: '10.0',

});

models.add({

  file: './YourModelFile.pmdl',

  sensitivity: '0.5',

  hotwords : 'snowboy'

});

const detector = new Detector({

  resource: "./node_modules/snowboy/resources/common.res",

  models: models,

  audioGain: 2.0

});

detector.on('silence',()=>{

        console.log('silence');

});

detector.on('sound', (buffer)=>{

        console.log('sound');

});

detector.on('error', ()=>{

        console.log('Detector--Error');

});

detector.on('hotword',(index, hotword, buffer)=>{

        console.log('KWS > ', index, hotword);

});

mic.pipe(detector);


YourModelFile은 https://snowboy.kitt.ai 에서 개인적 사용을 위한 모델을 등록-다운로드 할 수 있다. (해커에게는 공짜.)


반응형
Posted by alias
,