Files
Arbitrate-FrontendH5/node_modules/.cache/babel-loader/9db0c3dfd256db82612bac6796dec9fb283344c4519d8bb70eb9fec0710714da.json
T

1 line
23 KiB
JSON
Raw Normal View History

2024-01-18 10:46:33 +08:00
{"ast":null,"code":"import \"core-js/modules/web.url-search-params.delete.js\";\nimport \"core-js/modules/web.url-search-params.has.js\";\nimport \"core-js/modules/web.url-search-params.size.js\";\nimport \"core-js/modules/web.dom-exception.stack.js\";\nimport \"core-js/modules/es.array.push.js\";\nimport \"core-js/modules/es.typed-array.to-reversed.js\";\nimport \"core-js/modules/es.typed-array.to-sorted.js\";\nimport \"core-js/modules/es.typed-array.with.js\";\nimport { SpeechRecognizer } from './speechrecognizer.js';\nconst audioWorkletCode = `\nclass MyProcessor extends AudioWorkletProcessor {\n constructor(options) {\n super(options);\n this.audioData = [];\n this.nextUpdateFrame = 40;\n }\n\n get intervalInFrames() {\n return 40 / 1000 * sampleRate;\n }\n\n process(inputs) {\n // 去处理音频数据\n // eslint-disable-next-line no-undef\n const output = ${to16kHz}(inputs[0][0], sampleRate);\n const audioData = ${to16BitPCM}(output);\n const data = [...new Int8Array(audioData.buffer)];\n this.audioData = this.audioData.concat(data);\n this.nextUpdateFrame -= inputs[0][0].length;\n if (this.nextUpdateFrame < 0) {\n this.nextUpdateFrame += this.intervalInFrames;\n this.port.postMessage({\n audioData: new Int8Array(this.audioData)\n });\n this.audioData = [];\n }\n return true;\n }\n}\n\nregisterProcessor('my-processor', MyProcessor);\n`;\nconst audioWorkletBlobURL = window.URL.createObjectURL(new Blob([audioWorkletCode], {\n type: 'text/javascript'\n}));\nexport default class ASR {\n constructor(options) {\n this.audioTrack = options.audioTrack;\n this.audioContext = new (window.AudioContext || window.webkitAudioContext)();\n this.speechRecognizer = null;\n this.isCanSendData = false;\n this.audioData = [];\n this.secretkey = options.secretKey;\n this.params = {\n secretid: options.secretId,\n appid: options.appId,\n engine_model_type: options.engine_model_type || '16k_zh',\n voice_format: options.voice_format || 1,\n // hotword_id: options.hotword_id,\n needvad: options.needvad\n // filter_dirty: options.filter_dirty,\n // filter_modal: options.filter_modal,\n // filter_punc: options.filter_punc,\n // convert_num_mode: options.convert_num_mode,\n // word_info: options.word_info,\n // token: options.token,\n };\n\n this.OnRecognitionStart = function () {};\n this.OnSentenceBegin = function () {};\n this.OnRecognitionResultChange = function () {};\n this.OnSentenceEnd = function () {};\n this.OnRecognitionComplete = function () {};\n this.OnError = function () {};\n this.OnChange = function () {};\n }\n signCallback(signStr) {\n const secretKey = this.secretkey;\n const hash = window.CryptoJSTest.HmacSHA1(signStr, secretKey);\n const bytes = Uint8ArrayToString(toUint8Array(hash));\n return window.btoa(bytes);\n }\n start() {\n if (!this.speechRecognizer) {\n const params = {\n // 用户参数\n signCallback: this.signCallback.bind(this),\n ...this.params\n };\n this.speechRecognizer = new SpeechRecognizer(params);\n }\n\n // 开始识别\n this.speechRecognizer.OnRecognitionStart = res => {\n this.isCanSendData = true;\n this.OnRecognitionStart(res);\n };\n // 一句话开始\n this.speechRecognizer.OnSentenceBegin = res => {\n this.OnSentenceBegin(res);\n this.OnChange(res);\n };\n // 识别变化时\n this.speechRecognizer.OnRecognitionResultChange = res => {\n this.OnRecognitionResultChange(res);\n this.OnChange(res);\n };\n // 一句话结束\n this.speechRecognizer.OnSentenceEnd = res => {\n this.OnSentenceEnd(res);\n this.OnChange(res);\n };\n // 识别结束\n this.speechRecognizer.OnRecognitionComplete = res => {\n this.OnRecognitionComplete(res);\n };\n // 识别错误\n this.speechRecognizer.OnError = res => {\n this.isCanSendData = false;\n this.OnError(res);\n