watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 669 forks source link

Errors using maxAlternatives with recognizeUsingWebSocket on SpeechToTextV1 #1160

Closed jkelvie closed 9 months ago

jkelvie commented 2 years ago

Overview

In the last week, when calling recognizeUsingWebSocket on the SpeechToTextV1 API, we suddenly we get the error: "No active exception to reraise"

This happens when maxAlternatives is set to anything higher than 1.

This error does NOT occur with the non-WebSocket recognition calls.

Expected behavior The SDK should return several alternatives.

Actual behavior We get an exception - passed as an event of type error on the SpeechToTextV1.RecognizeStream.

The exception has only the message: "No active exception to reraise"

This is obviously not a very helpful error message.

How to reproduce We are using the 7.0.0 version of the ibm-watson Node.js SDK. This also, though, occurs with the previous version (6.2.2).

Complete sample code to replicate is below. If it is run with maxAlternatives set to 1 instead, the ASR will work.

const IamAuthenticator = require('ibm-watson/auth').IamAuthenticator
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1')

require('dotenv').config()

// const model = 'en-US_Multimedia'
const speechToText = new SpeechToTextV1({
  authenticator: new IamAuthenticator({
    apikey: process.env.WATSON_STT_KEY
  }),
  serviceUrl: process.env.WATSON_STT_URL
})

const recognizeParams = {
  backgroundAudioSuppression: 0.5,
  contentType: 'audio/l16;rate=16000;channels=1;',
  endOfPhraseSilenceTime: 1.0,
  interimResults: true,
  lowLatency: false,
  maxAlternatives: 3, // recently started getting errors on 5/5/2022 with this
  model: 'en-US_Multimedia',
  objectMode: true,
  speechDetectorSensitivity: 0.2
}

const recognizeStream = speechToText.recognizeUsingWebSocket(recognizeParams)

// Pipe in the audio from our audio object
require('fs').createReadStream('test/data/AudioWithSilence-16000.raw').pipe(recognizeStream)

recognizeStream.on('data', (event) => {
  // Ignore results that come in after the recognize stream is destroyed
  if (!recognizeStream) {
    return
  }

  console.info('Results returned: ' + JSON.stringify(event, null, 2))
})

recognizeStream.on('error', (event) => {
  /** @type {any} */
  const eventAny = event
  console.error('recognizeStream error: ' + eventAny.raw.data)
  if (recognizeStream) recognizeStream.stop()
})

recognizeStream.on('close', () => {
  console.info('recognizeStream stopped')
})

recognizeStream.on('end', () => {
  console.info('recognizedStream ended')
})

Screenshots If applicable, add screenshots to help explain your problem.

SDK Version 7.0.0 - also tested with 6.2.2

Additional information: Node.js 16.9.1

Additional context This is a critical error - this is harming the quality of our ASR, as well as leading to errors in our production systems.

A zipped version of the raw audio file we tested with is attached: AudioWithSilence-16000.zip

apaparazzi0329 commented 9 months ago

I have been unable to replicate this issue on the latest version of the sdk and will consider it resolved. If this issue persists please feel welcome to reopen this issue and I will address it promptly