You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dtmf-detection-stream

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dtmf-detection-stream

This is a simple node.js DTMF detection stream.

1.18.0
latest
Source
npmnpm
Version published
Weekly downloads
45
15.38%
Maintainers
1
Weekly downloads
 
Created
Source

dtmf-detection-stream

This is a simple node.js DTMF detection stream.

Installation

npm i dtmf-detection-stream

Sample usage

const { ToneStream } = require('tone-stream')
const Speaker = require('speaker')
const DtmfDetectionStream = require('dtmf-detection-stream')

const format = {
  sampleRate: 8000,
  bitDepth: 16,
  channels: 1,
}

const ts = new ToneStream(format)
ts.add([800, 's']) // silence
ts.add([800, 'DTMF:1'])
ts.add([800, 's']) // silence
ts.add([800, 'DTMF:2'])
ts.add([800, 's']) // silence
ts.add([800, 'DTMF:3'])
ts.add([800, 's']) // silence

const dds = new DtmfDetectionStream({format})

dds.on('dtmf', data => {
  console.log('Got dtmf:', data)
})

dds.on('speech', data => {
  console.log('Got speech:', data)
  process.exit(0)     
})

ts.on('data', data => {
  dds.write(data)
})

const speaker = new Speaker(format)
ts.pipe(speaker)

Output:

$ node mytest.js 
Got dtmf: { digit: '1', timestamp: 0.207 }
Got dtmf: { digit: '2', timestamp: 0.4025 }
Got dtmf: { digit: '3', timestamp: 0.6095 }
Got speech: { transcript: '123', timestamp: 0.6095 }

Events

The DtmfDetectionStream emits two kinds of events:

  • 'dtmf': single digit as soon as it is detected (notified upon signal extintion).
  • 'speech': aggregated digits after 500 milliseconds with no more digits being detected. So it will be like someone is using DTMF to talk (this will permit to treat dtmf-detection-stream as a speech-recog-stream and use it with mrcp_server and ws_speech_server).

More Examples

See here.

FAQs

Package last updated on 06 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts