(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "rxjs", "rxjs/operators", "@google-cloud/speech"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("rxjs"), require("rxjs/operators"), require("@google-cloud/speech"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.rxjs, global.operators, global.speech);
    global.toGCP = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _rxjs, _operators, _speech) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  _speech = _interopRequireDefault(_speech);

  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

  const toGCP = function toGCP({
    googleCreds = process.env.GOOGLE_APPLICATION_CREDENTIALS,
    stop$ = (0, _rxjs.of)(),
    sampleRate = 16000,
    bufferThreshold = 3,
    model = 'video'
  }) {
    return fileChunk$ => {
      if (!googleCreds) return (0, _rxjs.throwError)(new Error('Google Application Credentials must be set'));
      const clientv1p1beta1 = new _speech.default.v1p1beta1.SpeechClient();
      const config = {
        encoding: 'LINEAR16',
        sampleRateHertz: sampleRate,
        languageCode: 'en-US',
        enableWordConfidence: true,
        enableWordTimeOffsets: true,
        enableSpeakerDiarization: true,
        enableAutomaticPunctuation: true,
        model
      };
      return fileChunk$.pipe((0, _operators.bufferCount)(bufferThreshold), (0, _operators.map)(fileChunk => clientv1p1beta1.recognize({
        config,
        audio: {
          content: Buffer.concat(fileChunk).toString('base64')
        }
      })), (0, _operators.concatMap)(r => r), (0, _operators.map)(([res]) => res.results.map(result => result.alternatives[0].transcript).join('\n')), (0, _operators.takeUntil)(stop$));
    };
  };

  var _default = toGCP;
  _exports.default = _default;
});
//# sourceMappingURL=toGCP.js.map