listen.mjs: prints all events as JSON objects. transcripts.mjs: prints transcript text only. Both use Node 21+ built-in WebSocket — no libraries required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
20 lines
548 B
JavaScript
20 lines
548 B
JavaScript
// Connect to the STT server and print transcript text only.
|
|
// Usage: node transcripts.mjs
|
|
|
|
const PORT = process.env.STT_PORT ?? '11501'
|
|
const ws = new WebSocket(`ws://localhost:${PORT}`)
|
|
|
|
ws.addEventListener('open', () => {
|
|
process.stderr.write(`connected to ws://localhost:${PORT}\n`)
|
|
})
|
|
|
|
ws.addEventListener('message', ({ data }) => {
|
|
const event = JSON.parse(data)
|
|
if (event.event === 'transcript') {
|
|
console.log(event.text)
|
|
}
|
|
})
|
|
|
|
ws.addEventListener('close', () => process.exit(0))
|
|
ws.addEventListener('error', () => process.exit(1))
|