speechmatics / speechmatics-js-sdk

Javascript and Typescript SDK for Speechmatics
MIT License
39 stars 4 forks source link

Language identification errors don't bubble up to the caller #18

Closed nickgerig closed 8 months ago

nickgerig commented 8 months ago

Describe the bug Using batch.transcribe() When a batch transcribe job is rejected because of Language identification could not identify any language with sufficient confidence, an error is thrown but it does not bubble up to caller

The following node warning is logged:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "[object Array]".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Steps to reproduce Get an audio file with insufficient audio for auto-detect to return a language Call batch.transcibe with the following:

require('dotenv').config();
require('speechmatics');

const fs = require('fs');
const path = require('path');

const SM = new Speechmatics(process.env.API_KEY);

SM.batch
  .transcribe({
    input: new Blob([fs.readFileSync('auto-lang-undetectable.wav')]),

    transcription_config: {
      language: 'auto',
    },
  })
  .then((res) => {
    console.log('result:', res);
  })
  .catch((err) => {
    console.log('error:', err);
  });

Expected behavior The caller of the batch.transcribe method should be able to catch the error in their catch block.

Additional context SDK version 3.1.1 Node.js v18.18.0

Doesn't affect invalid audio files so is probably related to the code that polls for the job response