UNPKG

@bottlenose/rxtranscribe

Version:

👂 Realtime speech-to-text (S2T) transcription with RxJS

56 lines (52 loc) • 2.03 kB
(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, client = new _speech.default.v1p1beta1.SpeechClient(), 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 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)(chunks => Buffer.concat(chunks)), (0, _operators.map)(chunk => client.recognize({ config, audio: { content: chunk.toString('base64') } })), (0, _operators.concatMap)(r => r), (0, _operators.takeUntil)(stop$)); }; }; var _default = toGCP; _exports.default = _default; }); //# sourceMappingURL=toGCP.js.map