UNPKG

sofya.transcription

Version:

a JavaScript library that provides a robust and flexible solution for real-time audio transcription. It is designed to transcribe audio streams and can be easily integrated into web applications.

152 lines (116 loc) 733 kB
/* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["SofyaTrancription"] = factory(); else root["SofyaTrancription"] = factory(); })(this, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./node_modules/@ricky0123/vad-web/dist/asset-path.js": /*!************************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/asset-path.js ***! \************************************************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.assetPath = void 0;\n// nextjs@14 bundler may attempt to execute this during SSR and crash\nconst isWeb = typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\nconst currentScript = isWeb\n ? window.document.currentScript\n : null;\nlet basePath = \"/\";\nif (currentScript) {\n basePath = currentScript.src\n .replace(/#.*$/, \"\")\n .replace(/\\?.*$/, \"\")\n .replace(/\\/[^\\/]+$/, \"/\");\n}\nconst assetPath = (file) => {\n return basePath + file;\n};\nexports.assetPath = assetPath;\n//# sourceMappingURL=asset-path.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/asset-path.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/default-model-fetcher.js": /*!***********************************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/default-model-fetcher.js ***! \***********************************************************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.defaultModelFetcher = void 0;\nconst defaultModelFetcher = (path) => {\n return fetch(path).then((model) => model.arrayBuffer());\n};\nexports.defaultModelFetcher = defaultModelFetcher;\n//# sourceMappingURL=default-model-fetcher.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/default-model-fetcher.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/frame-processor.js": /*!*****************************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/frame-processor.js ***! \*****************************************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; eval("\n/*\nSome of this code, together with the default options found in index.ts,\nwere taken (or took inspiration) from https://github.com/snakers4/silero-vad\n*/\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.FrameProcessor = exports.validateOptions = exports.defaultFrameProcessorOptions = void 0;\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./node_modules/@ricky0123/vad-web/dist/logging.js\");\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./node_modules/@ricky0123/vad-web/dist/messages.js\");\nconst RECOMMENDED_FRAME_SAMPLES = [512, 1024, 1536];\nexports.defaultFrameProcessorOptions = {\n positiveSpeechThreshold: 0.5,\n negativeSpeechThreshold: 0.5 - 0.15,\n preSpeechPadFrames: 1,\n redemptionFrames: 8,\n frameSamples: 1536,\n minSpeechFrames: 3,\n submitUserSpeechOnPause: false,\n};\nfunction validateOptions(options) {\n if (!RECOMMENDED_FRAME_SAMPLES.includes(options.frameSamples)) {\n logging_1.log.warn(\"You are using an unusual frame size\");\n }\n if (options.positiveSpeechThreshold < 0 ||\n options.positiveSpeechThreshold > 1) {\n logging_1.log.error(\"positiveSpeechThreshold should be a number between 0 and 1\");\n }\n if (options.negativeSpeechThreshold < 0 ||\n options.negativeSpeechThreshold > options.positiveSpeechThreshold) {\n logging_1.log.error(\"negativeSpeechThreshold should be between 0 and positiveSpeechThreshold\");\n }\n if (options.preSpeechPadFrames < 0) {\n logging_1.log.error(\"preSpeechPadFrames should be positive\");\n }\n if (options.redemptionFrames < 0) {\n logging_1.log.error(\"redemptionFrames should be positive\");\n }\n}\nexports.validateOptions = validateOptions;\nconst concatArrays = (arrays) => {\n const sizes = arrays.reduce((out, next) => {\n out.push(out.at(-1) + next.length);\n return out;\n }, [0]);\n const outArray = new Float32Array(sizes.at(-1));\n arrays.forEach((arr, index) => {\n const place = sizes[index];\n outArray.set(arr, place);\n });\n return outArray;\n};\nclass FrameProcessor {\n constructor(modelProcessFunc, modelResetFunc, options) {\n this.modelProcessFunc = modelProcessFunc;\n this.modelResetFunc = modelResetFunc;\n this.options = options;\n this.speaking = false;\n this.redemptionCounter = 0;\n this.active = false;\n this.reset = () => {\n this.speaking = false;\n this.audioBuffer = [];\n this.modelResetFunc();\n this.redemptionCounter = 0;\n };\n this.pause = () => {\n this.active = false;\n if (this.options.submitUserSpeechOnPause) {\n return this.endSegment();\n }\n else {\n this.reset();\n return {};\n }\n };\n this.resume = () => {\n this.active = true;\n };\n this.endSegment = () => {\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speaking = this.speaking;\n this.reset();\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speaking) {\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { msg: messages_1.Message.SpeechEnd, audio };\n }\n else {\n return { msg: messages_1.Message.VADMisfire };\n }\n }\n return {};\n };\n this.process = async (frame) => {\n if (!this.active) {\n return {};\n }\n const probs = await this.modelProcessFunc(frame);\n this.audioBuffer.push({\n frame,\n isSpeech: probs.isSpeech >= this.options.positiveSpeechThreshold,\n });\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n this.redemptionCounter) {\n this.redemptionCounter = 0;\n }\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n !this.speaking) {\n this.speaking = true;\n return { probs, msg: messages_1.Message.SpeechStart, frame };\n }\n if (probs.isSpeech < this.options.negativeSpeechThreshold &&\n this.speaking &&\n ++this.redemptionCounter >= this.options.redemptionFrames) {\n this.redemptionCounter = 0;\n this.speaking = false;\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { probs, msg: messages_1.Message.SpeechEnd, audio, frame };\n }\n else {\n return { probs, msg: messages_1.Message.VADMisfire, frame };\n }\n }\n if (!this.speaking) {\n while (this.audioBuffer.length > this.options.preSpeechPadFrames) {\n this.audioBuffer.shift();\n }\n }\n return { probs, frame };\n };\n this.audioBuffer = [];\n this.reset();\n }\n}\nexports.FrameProcessor = FrameProcessor;\n//# sourceMappingURL=frame-processor.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/frame-processor.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/index.js": /*!*******************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/index.js ***! \*******************************************************/ /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.NonRealTimeVAD = exports.Message = exports.FrameProcessor = exports.defaultRealTimeVADOptions = exports.MicVAD = exports.AudioNodeVAD = exports.utils = exports.defaultNonRealTimeVADOptions = void 0;\nconst ort = __importStar(__webpack_require__(/*! onnxruntime-web */ \"./node_modules/onnxruntime-web/dist/ort.min.js\"));\nconst asset_path_1 = __webpack_require__(/*! ./asset-path */ \"./node_modules/@ricky0123/vad-web/dist/asset-path.js\");\nconst default_model_fetcher_1 = __webpack_require__(/*! ./default-model-fetcher */ \"./node_modules/@ricky0123/vad-web/dist/default-model-fetcher.js\");\nconst frame_processor_1 = __webpack_require__(/*! ./frame-processor */ \"./node_modules/@ricky0123/vad-web/dist/frame-processor.js\");\nObject.defineProperty(exports, \"FrameProcessor\", ({ enumerable: true, get: function () { return frame_processor_1.FrameProcessor; } }));\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./node_modules/@ricky0123/vad-web/dist/messages.js\");\nObject.defineProperty(exports, \"Message\", ({ enumerable: true, get: function () { return messages_1.Message; } }));\nconst non_real_time_vad_1 = __webpack_require__(/*! ./non-real-time-vad */ \"./node_modules/@ricky0123/vad-web/dist/non-real-time-vad.js\");\nconst utils_1 = __webpack_require__(/*! ./utils */ \"./node_modules/@ricky0123/vad-web/dist/utils.js\");\nexports.defaultNonRealTimeVADOptions = {\n modelURL: (0, asset_path_1.assetPath)(\"silero_vad.onnx\"),\n modelFetcher: default_model_fetcher_1.defaultModelFetcher,\n};\nclass NonRealTimeVAD extends non_real_time_vad_1.PlatformAgnosticNonRealTimeVAD {\n static async new(options = {}) {\n const { modelURL, modelFetcher } = {\n ...exports.defaultNonRealTimeVADOptions,\n ...options,\n };\n return await this._new(() => modelFetcher(modelURL), ort, options);\n }\n}\nexports.NonRealTimeVAD = NonRealTimeVAD;\nexports.utils = {\n audioFileToArray: utils_1.audioFileToArray,\n minFramesForTargetMS: utils_1.minFramesForTargetMS,\n arrayBufferToBase64: utils_1.arrayBufferToBase64,\n encodeWAV: utils_1.encodeWAV,\n};\nvar real_time_vad_1 = __webpack_require__(/*! ./real-time-vad */ \"./node_modules/@ricky0123/vad-web/dist/real-time-vad.js\");\nObject.defineProperty(exports, \"AudioNodeVAD\", ({ enumerable: true, get: function () { return real_time_vad_1.AudioNodeVAD; } }));\nObject.defineProperty(exports, \"MicVAD\", ({ enumerable: true, get: function () { return real_time_vad_1.MicVAD; } }));\nObject.defineProperty(exports, \"defaultRealTimeVADOptions\", ({ enumerable: true, get: function () { return real_time_vad_1.defaultRealTimeVADOptions; } }));\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/index.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/logging.js": /*!*********************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/logging.js ***! \*********************************************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.log = exports.LOG_PREFIX = void 0;\nexports.LOG_PREFIX = \"[VAD]\";\nconst levels = [\"error\", \"debug\", \"warn\"];\nfunction getLog(level) {\n return (...args) => {\n console[level](exports.LOG_PREFIX, ...args);\n };\n}\nconst _log = levels.reduce((acc, level) => {\n acc[level] = getLog(level);\n return acc;\n}, {});\nexports.log = _log;\n//# sourceMappingURL=logging.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/logging.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/messages.js": /*!**********************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/messages.js ***! \**********************************************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Message = void 0;\nvar Message;\n(function (Message) {\n Message[\"AudioFrame\"] = \"AUDIO_FRAME\";\n Message[\"SpeechStart\"] = \"SPEECH_START\";\n Message[\"VADMisfire\"] = \"VAD_MISFIRE\";\n Message[\"SpeechEnd\"] = \"SPEECH_END\";\n Message[\"SpeechStop\"] = \"SPEECH_STOP\";\n})(Message || (exports.Message = Message = {}));\n//# sourceMappingURL=messages.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/messages.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/models.js": /*!********************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/models.js ***! \********************************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; eval("\nvar _a;\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Silero = void 0;\n// @ts-ignore\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./node_modules/@ricky0123/vad-web/dist/logging.js\");\nclass Silero {\n constructor(ort, modelFetcher) {\n this.ort = ort;\n this.modelFetcher = modelFetcher;\n this.init = async () => {\n logging_1.log.debug(\"initializing vad\");\n const modelArrayBuffer = await this.modelFetcher();\n this._session = await this.ort.InferenceSession.create(modelArrayBuffer);\n this._sr = new this.ort.Tensor(\"int64\", [16000n]);\n this.reset_state();\n logging_1.log.debug(\"vad is initialized\");\n };\n this.reset_state = () => {\n const zeroes = Array(2 * 64).fill(0);\n this._h = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n this._c = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n };\n this.process = async (audioFrame) => {\n const t = new this.ort.Tensor(\"float32\", audioFrame, [1, audioFrame.length]);\n const inputs = {\n input: t,\n h: this._h,\n c: this._c,\n sr: this._sr,\n };\n const out = await this._session.run(inputs);\n this._h = out.hn;\n this._c = out.cn;\n const [isSpeech] = out.output.data;\n const notSpeech = 1 - isSpeech;\n return { notSpeech, isSpeech };\n };\n }\n}\nexports.Silero = Silero;\n_a = Silero;\nSilero.new = async (ort, modelFetcher) => {\n const model = new _a(ort, modelFetcher);\n await model.init();\n return model;\n};\n//# sourceMappingURL=models.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/models.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/non-real-time-vad.js": /*!*******************************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/non-real-time-vad.js ***! \*******************************************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.PlatformAgnosticNonRealTimeVAD = exports.defaultNonRealTimeVADOptions = void 0;\nconst frame_processor_1 = __webpack_require__(/*! ./frame-processor */ \"./node_modules/@ricky0123/vad-web/dist/frame-processor.js\");\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./node_modules/@ricky0123/vad-web/dist/messages.js\");\nconst models_1 = __webpack_require__(/*! ./models */ \"./node_modules/@ricky0123/vad-web/dist/models.js\");\nconst resampler_1 = __webpack_require__(/*! ./resampler */ \"./node_modules/@ricky0123/vad-web/dist/resampler.js\");\nexports.defaultNonRealTimeVADOptions = {\n ...frame_processor_1.defaultFrameProcessorOptions,\n ortConfig: undefined,\n};\nclass PlatformAgnosticNonRealTimeVAD {\n static async _new(modelFetcher, ort, options = {}) {\n const fullOptions = {\n ...exports.defaultNonRealTimeVADOptions,\n ...options,\n };\n if (fullOptions.ortConfig !== undefined) {\n fullOptions.ortConfig(ort);\n }\n const vad = new this(modelFetcher, ort, fullOptions);\n await vad.init();\n return vad;\n }\n constructor(modelFetcher, ort, options) {\n this.modelFetcher = modelFetcher;\n this.ort = ort;\n this.options = options;\n this.init = async () => {\n const model = await models_1.Silero.new(this.ort, this.modelFetcher);\n this.frameProcessor = new frame_processor_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: this.options.frameSamples,\n positiveSpeechThreshold: this.options.positiveSpeechThreshold,\n negativeSpeechThreshold: this.options.negativeSpeechThreshold,\n redemptionFrames: this.options.redemptionFrames,\n preSpeechPadFrames: this.options.preSpeechPadFrames,\n minSpeechFrames: this.options.minSpeechFrames,\n submitUserSpeechOnPause: this.options.submitUserSpeechOnPause,\n });\n this.frameProcessor.resume();\n };\n this.run = async function* (inputAudio, sampleRate) {\n const resamplerOptions = {\n nativeSampleRate: sampleRate,\n targetSampleRate: 16000,\n targetFrameSize: this.options.frameSamples,\n };\n const resampler = new resampler_1.Resampler(resamplerOptions);\n let start = 0;\n let end = 0;\n let frameIndex = 0;\n for await (const frame of resampler.stream(inputAudio)) {\n const { msg, audio } = await this.frameProcessor.process(frame);\n switch (msg) {\n case messages_1.Message.SpeechStart:\n start = (frameIndex * this.options.frameSamples) / 16;\n break;\n case messages_1.Message.SpeechEnd:\n end = ((frameIndex + 1) * this.options.frameSamples) / 16;\n yield { audio, start, end };\n break;\n default:\n break;\n }\n frameIndex++;\n }\n const { msg, audio } = this.frameProcessor.endSegment();\n if (msg == messages_1.Message.SpeechEnd) {\n yield {\n audio,\n start,\n end: (frameIndex * this.options.frameSamples) / 16,\n };\n }\n };\n (0, frame_processor_1.validateOptions)(options);\n }\n}\nexports.PlatformAgnosticNonRealTimeVAD = PlatformAgnosticNonRealTimeVAD;\n//# sourceMappingURL=non-real-time-vad.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/non-real-time-vad.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/real-time-vad.js": /*!***************************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/real-time-vad.js ***! \***************************************************************/ /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.AudioNodeVAD = exports.MicVAD = exports.defaultRealTimeVADOptions = exports.ort = void 0;\nconst ortInstance = __importStar(__webpack_require__(/*! onnxruntime-web */ \"./node_modules/onnxruntime-web/dist/ort.min.js\"));\nconst asset_path_1 = __webpack_require__(/*! ./asset-path */ \"./node_modules/@ricky0123/vad-web/dist/asset-path.js\");\nconst default_model_fetcher_1 = __webpack_require__(/*! ./default-model-fetcher */ \"./node_modules/@ricky0123/vad-web/dist/default-model-fetcher.js\");\nconst frame_processor_1 = __webpack_require__(/*! ./frame-processor */ \"./node_modules/@ricky0123/vad-web/dist/frame-processor.js\");\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./node_modules/@ricky0123/vad-web/dist/logging.js\");\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./node_modules/@ricky0123/vad-web/dist/messages.js\");\nconst models_1 = __webpack_require__(/*! ./models */ \"./node_modules/@ricky0123/vad-web/dist/models.js\");\nexports.ort = ortInstance;\nexports.defaultRealTimeVADOptions = {\n ...frame_processor_1.defaultFrameProcessorOptions,\n onFrameProcessed: (probabilities) => { },\n onVADMisfire: () => {\n logging_1.log.debug(\"VAD misfire\");\n },\n onSpeechStart: () => {\n logging_1.log.debug(\"Detected speech start\");\n },\n onSpeechEnd: () => {\n logging_1.log.debug(\"Detected speech end\");\n },\n workletURL: (0, asset_path_1.assetPath)(\"vad.worklet.bundle.min.js\"),\n modelURL: (0, asset_path_1.assetPath)(\"silero_vad.onnx\"),\n modelFetcher: default_model_fetcher_1.defaultModelFetcher,\n stream: undefined,\n ortConfig: undefined,\n workletOptions: {\n processorOptions: {\n frameSamples: frame_processor_1.defaultFrameProcessorOptions.frameSamples,\n },\n },\n};\nclass MicVAD {\n static async new(options = {}) {\n const fullOptions = {\n ...exports.defaultRealTimeVADOptions,\n ...options,\n };\n (0, frame_processor_1.validateOptions)(fullOptions);\n let stream;\n if (fullOptions.stream === undefined)\n stream = await navigator.mediaDevices.getUserMedia({\n audio: {\n ...fullOptions.additionalAudioConstraints,\n channelCount: 1,\n echoCancellation: true,\n autoGainControl: true,\n noiseSuppression: true,\n },\n });\n else\n stream = fullOptions.stream;\n const audioContext = new AudioContext();\n const sourceNode = new MediaStreamAudioSourceNode(audioContext, {\n mediaStream: stream,\n });\n const audioNodeVAD = await AudioNodeVAD.new(audioContext, fullOptions);\n audioNodeVAD.receive(sourceNode);\n return new MicVAD(fullOptions, audioContext, stream, audioNodeVAD, sourceNode);\n }\n constructor(options, audioContext, stream, audioNodeVAD, sourceNode, listening = false) {\n this.options = options;\n this.audioContext = audioContext;\n this.stream = stream;\n this.audioNodeVAD = audioNodeVAD;\n this.sourceNode = sourceNode;\n this.listening = listening;\n this.pause = () => {\n this.audioNodeVAD.pause();\n this.listening = false;\n };\n this.start = () => {\n this.audioNodeVAD.start();\n this.listening = true;\n };\n this.destroy = () => {\n if (this.listening) {\n this.pause();\n }\n if (this.options.stream === undefined) {\n this.stream.getTracks().forEach((track) => track.stop());\n }\n this.sourceNode.disconnect();\n this.audioNodeVAD.destroy();\n this.audioContext.close();\n };\n }\n}\nexports.MicVAD = MicVAD;\nclass AudioNodeVAD {\n static async new(ctx, options = {}) {\n const fullOptions = {\n ...exports.defaultRealTimeVADOptions,\n ...options,\n };\n (0, frame_processor_1.validateOptions)(fullOptions);\n if (fullOptions.ortConfig !== undefined) {\n fullOptions.ortConfig(exports.ort);\n }\n try {\n await ctx.audioWorklet.addModule(fullOptions.workletURL);\n }\n catch (e) {\n console.error(`Encountered an error while loading worklet. Please make sure the worklet vad.bundle.min.js included with @ricky0123/vad-web is available at the specified path:\n ${fullOptions.workletURL}\n If need be, you can customize the worklet file location using the \\`workletURL\\` option.`);\n throw e;\n }\n const vadNode = new AudioWorkletNode(ctx, \"vad-helper-worklet\", fullOptions.workletOptions);\n let model;\n try {\n model = await models_1.Silero.new(exports.ort, () => fullOptions.modelFetcher(fullOptions.modelURL));\n }\n catch (e) {\n console.error(`Encountered an error while loading model file. Please make sure silero_vad.onnx, included with @ricky0123/vad-web, is available at the specified path:\n ${fullOptions.modelURL}\n If need be, you can customize the model file location using the \\`modelURL\\` option.`);\n throw e;\n }\n const frameProcessor = new frame_processor_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: fullOptions.frameSamples,\n positiveSpeechThreshold: fullOptions.positiveSpeechThreshold,\n negativeSpeechThreshold: fullOptions.negativeSpeechThreshold,\n redemptionFrames: fullOptions.redemptionFrames,\n preSpeechPadFrames: fullOptions.preSpeechPadFrames,\n minSpeechFrames: fullOptions.minSpeechFrames,\n submitUserSpeechOnPause: fullOptions.submitUserSpeechOnPause,\n });\n const audioNodeVAD = new AudioNodeVAD(ctx, fullOptions, frameProcessor, vadNode);\n vadNode.port.onmessage = async (ev) => {\n switch (ev.data?.message) {\n case messages_1.Message.AudioFrame:\n let buffer = ev.data.data;\n if (!(buffer instanceof ArrayBuffer)) {\n buffer = new ArrayBuffer(ev.data.data.byteLength);\n new Uint8Array(buffer).set(new Uint8Array(ev.data.data));\n }\n const frame = new Float32Array(buffer);\n await audioNodeVAD.processFrame(frame);\n break;\n default:\n break;\n }\n };\n return audioNodeVAD;\n }\n constructor(ctx, options, frameProcessor, entryNode) {\n this.ctx = ctx;\n this.options = options;\n this.frameProcessor = frameProcessor;\n this.entryNode = entryNode;\n this.pause = () => {\n const ev = this.frameProcessor.pause();\n this.handleFrameProcessorEvent(ev);\n };\n this.start = () => {\n this.frameProcessor.resume();\n };\n this.receive = (node) => {\n node.connect(this.entryNode);\n };\n this.processFrame = async (frame) => {\n const ev = await this.frameProcessor.process(frame);\n this.handleFrameProcessorEvent(ev);\n };\n this.handleFrameProcessorEvent = (ev) => {\n if (ev.probs !== undefined) {\n this.options.onFrameProcessed(ev.probs, ev.frame);\n }\n switch (ev.msg) {\n case messages_1.Message.SpeechStart:\n this.options.onSpeechStart();\n break;\n case messages_1.Message.VADMisfire:\n this.options.onVADMisfire();\n break;\n case messages_1.Message.SpeechEnd:\n this.options.onSpeechEnd(ev.audio);\n break;\n default:\n break;\n }\n };\n this.destroy = () => {\n this.entryNode.port.postMessage({\n message: messages_1.Message.SpeechStop,\n });\n this.entryNode.disconnect();\n };\n }\n}\nexports.AudioNodeVAD = AudioNodeVAD;\n//# sourceMappingURL=real-time-vad.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/real-time-vad.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/resampler.js": /*!***********************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/resampler.js ***! \***********************************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Resampler = void 0;\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./node_modules/@ricky0123/vad-web/dist/logging.js\");\nclass Resampler {\n constructor(options) {\n this.options = options;\n this.process = (audioFrame) => {\n const outputFrames = [];\n for (const sample of audioFrame) {\n this.inputBuffer.push(sample);\n while (this.hasEnoughDataForFrame()) {\n const outputFrame = this.generateOutputFrame();\n outputFrames.push(outputFrame);\n }\n }\n return outputFrames;\n };\n this.stream = async function* (audioInput) {\n for (const sample of audioInput) {\n this.inputBuffer.push(sample);\n while (this.hasEnoughDataForFrame()) {\n const outputFrame = this.generateOutputFrame();\n yield outputFrame;\n }\n }\n };\n if (options.nativeSampleRate < 16000) {\n logging_1.log.error(\"nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate\");\n }\n this.inputBuffer = [];\n }\n hasEnoughDataForFrame() {\n return ((this.inputBuffer.length * this.options.targetSampleRate) /\n this.options.nativeSampleRate >=\n this.options.targetFrameSize);\n }\n generateOutputFrame() {\n const outputFrame = new Float32Array(this.options.targetFrameSize);\n let outputIndex = 0;\n let inputIndex = 0;\n while (outputIndex < this.options.targetFrameSize) {\n let sum = 0;\n let num = 0;\n while (inputIndex <\n Math.min(this.inputBuffer.length, ((outputIndex + 1) * this.options.nativeSampleRate) /\n this.options.targetSampleRate)) {\n const value = this.inputBuffer[inputIndex];\n if (value !== undefined) {\n sum += value;\n num++;\n }\n inputIndex++;\n }\n outputFrame[outputIndex] = sum / num;\n outputIndex++;\n }\n this.inputBuffer = this.inputBuffer.slice(inputIndex);\n return outputFrame;\n }\n}\nexports.Resampler = Resampler;\n//# sourceMappingURL=resampler.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/resampler.js?"); /***/ }), /***/ "./node_modules/@ricky0123/vad-web/dist/utils.js": /*!*******************************************************!*\ !*** ./node_modules/@ricky0123/vad-web/dist/utils.js ***! \*******************************************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.audioFileToArray = exports.encodeWAV = exports.arrayBufferToBase64 = exports.minFramesForTargetMS = void 0;\nfunction minFramesForTargetMS(targetDuration, frameSamples, sr = 16000) {\n return Math.ceil((targetDuration * sr) / 1000 / frameSamples);\n}\nexports.minFramesForTargetMS = minFramesForTargetMS;\nfunction arrayBufferToBase64(buffer) {\n const bytes = new Uint8Array(buffer);\n const len = bytes.byteLength;\n const binary = new Array(len);\n for (var i = 0; i < len; i++) {\n const byte = bytes[i];\n if (byte === undefined) {\n break;\n }\n binary[i] = String.fromCharCode(byte);\n }\n return btoa(binary.join(\"\"));\n}\nexports.arrayBufferToBase64 = arrayBufferToBase64;\n/*\nThis rest of this was mostly copied from https://github.com/linto-ai/WebVoiceSDK\n*/\nfunction encodeWAV(samples, format = 3, sampleRate = 16000, numChannels = 1, bitDepth = 32) {\n var bytesPerSample = bitDepth / 8;\n var blockAlign = numChannels * bytesPerSample;\n var buffer = new ArrayBuffer(44 + samples.length * bytesPerSample);\n var view = new DataView(buffer);\n /* RIFF identifier */\n writeString(view, 0, \"RIFF\");\n /* RIFF chunk length */\n view.setUint32(4, 36 + samples.length * bytesPerSample, true);\n /* RIFF type */\n writeString(view, 8, \"WAVE\");\n /* format chunk identifier */\n writeString(view, 12, \"fmt \");\n /* format chunk length */\n view.setUint32(16, 16, true);\n /* sample format (raw) */\n view.setUint16(20, format, true);\n /* channel count */\n view.setUint16(22, numChannels, true);\n /* sample rate */\n view.setUint32(24, sampleRate, true);\n /* byte rate (sample rate * block align) */\n view.setUint32(28, sampleRate * blockAlign, true);\n /* block align (channel count * bytes per sample) */\n view.setUint16(32, blockAlign, true);\n /* bits per sample */\n view.setUint16(34, bitDepth, true);\n /* data chunk identifier */\n writeString(view, 36, \"data\");\n /* data chunk length */\n view.setUint32(40, samples.length * bytesPerSample, true);\n if (format === 1) {\n // Raw PCM\n floatTo16BitPCM(view, 44, samples);\n }\n else {\n writeFloat32(view, 44, samples);\n }\n return buffer;\n}\nexports.encodeWAV = encodeWAV;\nfunction interleave(inputL, inputR) {\n var length = inputL.length + inputR.length;\n var result = new Float32Array(length);\n var index = 0;\n var inputIndex = 0;\n while (index < length) {\n result[index++] = inputL[inputIndex];\n result[index++] = inputR[inputIndex];\n inputIndex++;\n }\n return result;\n}\nfunction writeFloat32(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 4) {\n output.setFloat32(offset, input[i], true);\n }\n}\nfunction floatTo16BitPCM(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 2) {\n var s = Math.max(-1, Math.min(1, input[i]));\n output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);\n }\n}\nfunction writeString(view, offset, string) {\n for (var i = 0; i < string.length; i++) {\n view.setUint8(offset + i, string.charCodeAt(i));\n }\n}\nasync function audioFileToArray(audioFileData) {\n const ctx = new OfflineAudioContext(1, 1, 44100);\n const reader = new FileReader();\n let audioBuffer = null;\n await new Promise((res) => {\n reader.addEventListener(\"loadend\", (ev) => {\n const audioData = reader.result;\n ctx.decodeAudioData(audioData, (buffer) => {\n audioBuffer = buffer;\n ctx\n .startRendering()\n .then((renderedBuffer) => {\n console.log(\"Rendering completed successfully\");\n res();\n })\n .catch((err) => {\n console.error(`Rendering failed: ${err}`);\n });\n }, (e) => {\n console.log(`Error with decoding audio data: ${e}`);\n });\n });\n reader.readAsArrayBuffer(audioFileData);\n });\n if (audioBuffer === null) {\n throw Error(\"some shit\");\n }\n let _audioBuffer = audioBuffer;\n let out = new Float32Array(_audioBuffer.length);\n for (let i = 0; i < _audioBuffer.length; i++) {\n for (let j = 0; j < _audioBuffer.numberOfChannels; j++) {\n // @ts-ignore\n out[i] += _audioBuffer.getChannelData(j)[i];\n }\n }\n return { audio: out, sampleRate: _audioBuffer.sampleRate };\n}\nexports.audioFileToArray = audioFileToArray;\n//# sourceMappingURL=utils.js.map\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/@ricky0123/vad-web/dist/utils.js?"); /***/ }), /***/ "./node_modules/eventemitter3/index.js": /*!*********************************************!*\ !*** ./node_modules/eventemitter3/index.js ***! \*********************************************/ /***/ ((module) => { "use strict"; eval("\n\nvar has = Object.prototype.hasOwnProperty\n , prefix = '~';\n\n/**\n * Constructor to create a storage for our `EE` objects.\n * An `Events` instance is a plain object whose properties are event names.\n *\n * @constructor\n * @private\n */\nfunction Events() {}\n\n//\n// We try to not inherit from `Object.prototype`. In some engines creating an\n// instance in this way is faster than calling `Object.create(null)` directly.\n// If `Object.create(null)` is not supported we prefix the event names with a\n// character to make sure that the built-in object properties are not\n// overridden or used as an attack vector.\n//\nif (Object.create) {\n Events.prototype = Object.create(null);\n\n //\n // This hack is needed because the `__proto__` property is still inherited in\n // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.\n //\n if (!new Events().__proto__) prefix = false;\n}\n\n/**\n * Representation of a single event listener.\n *\n * @param {Function} fn The listener function.\n * @param {*} context The context to invoke the listener with.\n * @param {Boolean} [once=false] Specify if the listener is a one-time listener.\n * @constructor\n * @private\n */\nfunction EE(fn, context, once) {\n this.fn = fn;\n this.context = context;\n this.once = once || false;\n}\n\n/**\n * Add a listener for a given event.\n *\n * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.\n * @param {(String|Symbol)} event The event name.\n * @param {Function} fn The listener function.\n * @param {*} context The context to invoke the listener with.\n * @param {Boolean} once Specify if the listener is a one-time listener.\n * @returns {EventEmitter}\n * @private\n */\nfunction addListener(emitter, event, fn, context, once) {\n if (typeof fn !== 'function') {\n throw new TypeError('The listener must be a function');\n }\n\n var listener = new EE(fn, context || emitter, once)\n , evt = prefix ? prefix + event : event;\n\n if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;\n else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);\n else emitter._events[evt] = [emitter._events[evt], listener];\n\n return emitter;\n}\n\n/**\n * Clear event by name.\n *\n * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.\n * @param {(String|Symbol)} evt The Event name.\n * @private\n */\nfunction clearEvent(emitter, evt) {\n if (--emitter._eventsCount === 0) emitter._events = new Events();\n else delete emitter._events[evt];\n}\n\n/**\n * Minimal `EventEmitter` interface that is molded against the Node.js\n * `EventEmitter` interface.\n *\n * @constructor\n * @public\n */\nfunction EventEmitter() {\n this._events = new Events();\n this._eventsCount = 0;\n}\n\n/**\n * Return an array listing the events for which the emitter has registered\n * listeners.\n *\n * @returns {Array}\n * @public\n */\nEventEmitter.prototype.eventNames = function eventNames() {\n var names = []\n , events\n , name;\n\n if (this._eventsCount === 0) return names;\n\n for (name in (events = this._events)) {\n if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);\n }\n\n if (Object.getOwnPropertySymbols) {\n return names.concat(Object.getOwnPropertySymbols(events));\n }\n\n return names;\n};\n\n/**\n * Return the listeners registered for a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @returns {Array} The registered listeners.\n * @public\n */\nEventEmitter.prototype.listeners = function listeners(event) {\n var evt = prefix ? prefix + event : event\n , handlers = this._events[evt];\n\n if (!handlers) return [];\n if (handlers.fn) return [handlers.fn];\n\n for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {\n ee[i] = handlers[i].fn;\n }\n\n return ee;\n};\n\n/**\n * Return the number of listeners listening to a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @returns {Number} The number of listeners.\n * @public\n */\nEventEmitter.prototype.listenerCount = function listenerCount(event) {\n var evt = prefix ? prefix + event : event\n , listeners = this._events[evt];\n\n if (!listeners) return 0;\n if (listeners.fn) return 1;\n return listeners.length;\n};\n\n/**\n * Calls each of the listeners registered for a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @returns {Boolean} `true` if the event had listeners, else `false`.\n * @public\n */\nEventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {\n var evt = prefix ? prefix + event : event;\n\n if (!this._events[evt]) return false;\n\n var listeners = this._events[evt]\n , len = arguments.length\n , args\n , i;\n\n if (listeners.fn) {\n if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);\n\n switch (len) {\n case 1: return listeners.fn.call(listeners.context), true;\n case 2: return listeners.fn.call(listeners.context, a1), true;\n case 3: return listeners.fn.call(listeners.context, a1, a2), true;\n case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;\n case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;\n case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;\n }\n\n for (i = 1, args = new Array(len -1); i < len; i++) {\n args[i - 1] = arguments[i];\n }\n\n listeners.fn.apply(listeners.context, args);\n } else {\n var length = listeners.length\n , j;\n\n for (i = 0; i < length; i++) {\n if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);\n\n switch (len) {\n case 1: listeners[i].fn.call(listeners[i].context); break;\n case 2: listeners[i].fn.call(listeners[i].context, a1); break;\n case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;\n case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;\n default:\n if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {\n args[j - 1] = arguments[j];\n }\n\n listeners[i].fn.apply(listeners[i].context, args);\n }\n }\n }\n\n return true;\n};\n\n/**\n * Add a listener for a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @param {Function} fn The listener function.\n * @param {*} [context=this] The context to invoke the listener with.\n * @returns {EventEmitter} `this`.\n * @public\n */\nEventEmitter.prototype.on = function on(event, fn, context) {\n return addListener(this, event, fn, context, false);\n};\n\n/**\n * Add a one-time listener for a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @param {Function} fn The listener function.\n * @param {*} [context=this] The context to invoke the listener with.\n * @returns {EventEmitter} `this`.\n * @public\n */\nEventEmitter.prototype.once = function once(event, fn, context) {\n return addListener(this, event, fn, context, true);\n};\n\n/**\n * Remove the listeners of a given event.\n *\n * @param {(String|Symbol)} event The event name.\n * @param {Function} fn Only remove the listeners that match this function.\n * @param {*} context Only remove the listeners that have this context.\n * @param {Boolean} once Only remove one-time listeners.\n * @returns {EventEmitter} `this`.\n * @public\n */\nEventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {\n var evt = prefix ? prefix + event : event;\n\n if (!this._events[evt]) return this;\n if (!fn) {\n clearEvent(this, evt);\n return this;\n }\n\n var listeners = this._events[evt];\n\n if (listeners.fn) {\n if (\n listeners.fn === fn &&\n (!once || listeners.once) &&\n (!context || listeners.context === context)\n ) {\n clearEvent(this, evt);\n }\n } else {\n for (var i = 0, events = [], length = listeners.length; i < length; i++) {\n if (\n listeners[i].fn !== fn ||\n (once && !listeners[i].once) ||\n (context && listeners[i].context !== context)\n ) {\n events.push(listeners[i]);\n }\n }\n\n //\n // Reset the array, or remove it completely if we have no more listeners.\n //\n if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;\n else clearEvent(this, evt);\n }\n\n return this;\n};\n\n/**\n * Remove all listeners, or those of the specified event.\n *\n * @param {(String|Symbol)} [event] The event name.\n * @returns {EventEmitter} `this`.\n * @public\n */\nEventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {\n var evt;\n\n if (event) {\n evt = prefix ? prefix + event : event;\n if (this._events[evt]) clearEvent(this, evt);\n } else {\n this._events = new Events();\n this._eventsCount = 0;\n }\n\n return this;\n};\n\n//\n// Alias methods names because people roll like that.\n//\nEventEmitter.prototype.off = EventEmitter.prototype.removeListener;\nEventEmitter.prototype.addListener = EventEmitter.prototype.on;\n\n//\n// Expose the prefix.\n//\nEventEmitter.prefixed = prefix;\n\n//\n// Allow `EventEmitter` to be imported as module namespace.\n//\nEventEmitter.EventEmitter = EventEmitter;\n\n//\n// Expose the module.\n//\nif (true) {\n module.exports = EventEmitter;\n}\n\n\n//# sourceURL=webpack://SofyaTrancription/./node_modules/eventemitter3/index.js?"); /**