services/speech_to_text/v1.js
function payloadNonStreamCheck(msg) {
      var message = '';

      // The input comes in on msg.payload, and can either be an audio file or a string
      // representing a URL.
      if (!msg.payload instanceof Buffer || !typeof msg.payload === 'string') {
        message = 'Invalid property: msg.payload, can only be a URL or a Buffer.';
      } else if (!(msg.payload instanceof Buffer)) {
        // This check is repeated just before the call to the service, but
        // its also performed here as a double check.
        if (typeof msg.payload === 'string' && !payloadutils.urlCheck(msg.payload)) {
          message = 'Invalid URL.';
        }
      } else {
        var f = 'txt', ft = '';

        ft = fileType(msg.payload);
        if (ft) {
          f = ft.ext;
        }

        switch (f) {
        case 'wav':
        case 'flac':
        case 'ogg':
        case 'mp3':
        case 'mpeg':
          break;
        default:
          if (! ft.mime.toLowerCase().includes('audio')) {
            message = 'Audio format (' + f + ') not supported, must be encoded as WAV, MP3, FLAC or OGG.';
          }
        }
      }
      if (message) {
        return Promise.reject(message);
      }
      return Promise.resolve();
    }
function payloadNonStreamCheck(msg) {
      var message = '';

      // The input comes in on msg.payload, and can either be an audio file or a string
      // representing a URL.
      if (!msg.payload instanceof Buffer || !typeof msg.payload === 'string') {
        message = 'Invalid property: msg.payload, can only be a URL or a Buffer.';
      } else if (!(msg.payload instanceof Buffer)) {
        // This check is repeated just before the call to the service, but
        // its also performed here as a double check.
        if (typeof msg.payload === 'string' && !payloadutils.urlCheck(msg.payload)) {
          message = 'Invalid URL.';
        }
      } else {
        var f = 'txt', ft = '';

        ft = fileType(msg.payload);
        if (ft) {
          f = ft.ext;
        }

        switch (f) {
        case 'wav':
        case 'flac':
        case 'ogg':
        case 'mp3':
        case 'mpeg':
          break;
        default:
          if (! ft.mime.toLowerCase().includes('audio')) {
            message = 'Audio format (' + f + ') not supported, must be encoded as WAV, MP3, FLAC or OGG.';
          }
        }
      }
      if (message) {
        return Promise.reject(message);
      }
      return Promise.resolve();
    }
function payloadNonStreamCheck ( msg ) { var message = '' ; // The input comes in on msg.payload, and can either be an audio file or a string // representing a URL. if ( ! msg . payload instanceof Buffer || ! typeof msg . payload === 'string' ) { message = 'Invalid property: msg.payload, can only be a URL or a Buffer.' ; } else if ( ! ( msg . payload instanceof Buffer ) ) { // This check is repeated just before the call to the service, but // its also performed here as a double check. if ( typeof msg . payload === 'string' && ! payloadutils . urlCheck ( msg . payload ) ) { message = 'Invalid URL.' ; } } else { var f = 'txt' , ft = '' ; ft = fileType ( msg . payload ) ; if ( ft ) { f = ft . ext ; } switch ( f ) { case 'wav' : case 'flac' : case 'ogg' : case 'mp3' : case 'mpeg' : break ; default : if ( ! ft . mime . toLowerCase ( ) . includes ( 'audio' ) ) { message = 'Audio format (' + f + ') not supported, must be encoded as WAV, MP3, FLAC or OGG.' ; } } } if ( message ) { return Promise . reject ( message ) ; } return Promise . resolve ( ) ; }
Input is a standard msg.payload
Input is a standard msg . payload