MayamaTakeshi / dtmf-detection-stream

A simple DTMF detections stream for node.js
0 stars 0 forks source link

Doesn't work if amount of data written is too small #10

Open MayamaTakeshi opened 2 months ago

MayamaTakeshi commented 2 months ago

This script:

const DtmfDetectionStream = require('./index.js')
const DtmfGenerationStream = require('dtmf-generation-stream')

const sampleRate = 8000

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

const params = {
  text: '0123456789',
}

const dgs = new DtmfGenerationStream({format, params})

const dds = new DtmfDetectionStream({format})

var intervalID = setInterval(() => {
  //console.log("interval")
  var bytes = (sampleRate / 8000) * 320
  var data = dgs.read(bytes)
  //console.log(data)
  if(data) {
    dds.write(data)
  } else {
    setTimeout(() => {
      console.log("done")
      process.exit(0)
    }, 1000)
  }
}, 20)

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

dds.on('speech', data => {
    console.log('Event speech:', data)
  clearInterval(intervalID)
})

will not detect any dtmf tones. To make it work it is necessary to increase bytes to a large value (like * 30).

MayamaTakeshi commented 2 months ago

What is not clear to me is how we don't see any problems when using it with ws_speech_server.