Skip to content

Commit

Permalink
Merge pull request #3 from sudo-carson/patch-1
Browse files Browse the repository at this point in the history
Make example in README runnable
  • Loading branch information
mathquis authored Feb 10, 2021
2 parents 7141ba3 + 9288fed commit af7f440
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ npm i @mathquis/node-personal-wakeword

```javascript
const WakewordDetector = require('@mathquis/node-personal-wakeword')
const Recorder = require('mic')
const mic = require('mic')
const Stream = require('stream')

async function main() {
// Create a new wakeword detection engine
const detector = new WakewordDetector({
let detector = new WakewordDetector({
/*
sampleRate: 16000,
bitLength: 16,
Expand Down Expand Up @@ -113,23 +113,25 @@ async function main() {
// *****

// Create an audio stream from an audio recorder (arecord, sox, etc.)
const recorder = new Recorder({
let recorder = mic({
channels : detector.channels, // Defaults to 1
rate : detector.sampleRate, // Defaults to 16000
bitwidth : detector.bitLength // Defaults to 16
})
let stream = recorder.getAudioStream()

// Pipe to wakeword detector
recorder.pipe(detector)
stream.pipe(detector)

recorder.start()

// Destroy the recorder and detector after 10s
setTimeout(() => {
recorder.unpipe(detector)
stream.unpipe(detector)

recorder.removeAllListeners()
recorder.destroy()
stream.removeAllListeners()
stream.destroy()
stream = null
recorder = null

detector.removeAllListeners()
Expand All @@ -139,4 +141,4 @@ async function main() {
}

main()
```
```

0 comments on commit af7f440

Please sign in to comment.