-
Notifications
You must be signed in to change notification settings - Fork 13
/
listen.js
27 lines (21 loc) · 883 Bytes
/
listen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import stripAnsi from 'strip-ansi'
import { spawn } from 'child_process'
const whisperProcess = spawn('./whisper.cpp/stream', [
'-m', './whisper.cpp/models/ggml-base.en.bin',
'--step', '500',
'--length', '5000'
])
const blurbs = []
whisperProcess.stdout.on('data', (data) => {
const blurb = stripAnsi(data.toString()).trim()
// ignore things like [SILENCE] and [START SPEAKING] and (gentle music)
if (!blurb) return
if (blurb.startsWith('(') && blurb.endsWith(')')) return
if (blurb.startsWith('[') && blurb.endsWith(']')) return
// remove previous blurb if this blurb is a retroactive correction
const previousBlurb = blurbs.length && blurbs[blurbs.length - 1]
const currentBlurbIsACorrection = previousBlurb && blurb.startsWith(previousBlurb.slice(0, -10))
if (currentBlurbIsACorrection) blurbs.pop()
blurbs.push(blurb)
console.log({ blurbs })
})