Files
Arbitrate-FrontendH5/node_modules/.cache/babel-loader/ae50462b44ba0f5a3c6f98df1896ee4edeafdbff99d4706e11e2f20ef4783b1b.json
T
2024-01-18 10:46:33 +08:00

1 line
10 KiB
JSON

{"ast":null,"code":"import WebRecorder from \"./webrecorder.js\";\nimport { SpeechRecognizer, guid } from \"./speechrecognizer.js\";\nexport default class WebAudioSpeechRecognizer {\n constructor(params, isLog) {\n this.params = params;\n this.recorder = null;\n this.speechRecognizer = null;\n this.isCanSendData = false;\n this.audioData = [];\n this.timer = null;\n this.isLog = isLog;\n this.requestId = null;\n }\n start() {\n this.isLog && console.log('start function is click');\n this.requestId = guid();\n this.recorder = new WebRecorder(this.requestId, this.isLog);\n this.recorder.OnReceivedData = data => {\n if (this.isCanSendData) {\n this.speechRecognizer && this.speechRecognizer.write(data);\n }\n };\n // 录音失败时\n this.recorder.OnError = err => {\n this.speechRecognizer && this.speechRecognizer.close();\n this.stop();\n this.OnError(err);\n };\n this.recorder.OnStop = res => {\n if (this.speechRecognizer) {\n this.speechRecognizer.stop();\n this.speechRecognizer = null;\n }\n this.OnRecorderStop(res);\n };\n this.recorder.start();\n if (!this.speechRecognizer) {\n this.speechRecognizer = new SpeechRecognizer(this.params, this.requestId, this.isLog);\n }\n // 开始识别\n this.speechRecognizer.OnRecognitionStart = res => {\n if (this.recorder) {\n // 录音正常\n this.OnRecognitionStart(res);\n this.isCanSendData = true;\n } else {\n this.speechRecognizer && this.speechRecognizer.close();\n }\n };\n // 一句话开始\n this.speechRecognizer.OnSentenceBegin = res => {\n this.OnSentenceBegin(res);\n };\n // 识别变化时\n this.speechRecognizer.OnRecognitionResultChange = res => {\n this.OnRecognitionResultChange(res);\n };\n // 一句话结束\n this.speechRecognizer.OnSentenceEnd = res => {\n this.OnSentenceEnd(res);\n };\n // 识别结束\n this.speechRecognizer.OnRecognitionComplete = res => {\n this.OnRecognitionComplete(res);\n this.isCanSendData = false;\n this.isNormalEndStop = true;\n };\n // 识别错误\n this.speechRecognizer.OnError = res => {\n if (this.speechRecognizer && !this.isNormalEndStop) {\n this.OnError(res);\n }\n this.speechRecognizer = null;\n this.recorder && this.recorder.stop();\n this.isCanSendData = false;\n };\n // 建立连接\n this.speechRecognizer.start();\n }\n stop() {\n this.isLog && console.log('stop function is click');\n if (this.recorder) {\n this.recorder.stop();\n }\n // if (this.speechRecognizer) {\n // this.speechRecognizer.stop();\n // }\n }\n\n destroyStream() {\n this.isLog && console.log('destroyStream function is click', this.recorder);\n if (this.recorder) {\n this.recorder.destroyStream();\n }\n }\n // 开始识别的时候\n OnRecognitionStart(res) {}\n // 一句话开始的时候\n OnSentenceBegin(res) {}\n // 识别结果发生变化的时候\n OnRecognitionResultChange() {}\n // 一句话结束的时候\n OnSentenceEnd() {}\n // 识别结束的时候\n OnRecognitionComplete() {}\n // 识别失败\n OnError() {}\n OnRecorderStop() {}\n}\n;","map":{"version":3,"names":["WebRecorder","SpeechRecognizer","guid","WebAudioSpeechRecognizer","constructor","params","isLog","recorder","speechRecognizer","isCanSendData","audioData","timer","requestId","start","console","log","OnReceivedData","data","write","OnError","err","close","stop","OnStop","res","OnRecorderStop","OnRecognitionStart","OnSentenceBegin","OnRecognitionResultChange","OnSentenceEnd","OnRecognitionComplete","isNormalEndStop","destroyStream"],"sources":["/Users/Guest/nouiroom/src/utils/webaudiospeechrecognizer.js"],"sourcesContent":["import WebRecorder from \"./webrecorder.js\";\nimport { SpeechRecognizer, guid } from \"./speechrecognizer.js\";\n\nexport default class WebAudioSpeechRecognizer {\n constructor(params, isLog) {\n this.params = params;\n this.recorder = null;\n this.speechRecognizer = null;\n this.isCanSendData = false;\n this.audioData = [];\n this.timer = null;\n this.isLog = isLog;\n this.requestId = null;\n }\n start() {\n this.isLog && console.log('start function is click');\n this.requestId = guid();\n this.recorder = new WebRecorder(this.requestId, this.isLog);\n this.recorder.OnReceivedData = (data) => {\n if (this.isCanSendData) {\n this.speechRecognizer && this.speechRecognizer.write(data);\n }\n };\n // 录音失败时\n this.recorder.OnError = (err) => {\n this.speechRecognizer && this.speechRecognizer.close();\n this.stop();\n this.OnError(err);\n }\n this.recorder.OnStop = (res) => {\n if (this.speechRecognizer) {\n this.speechRecognizer.stop();\n this.speechRecognizer = null;\n }\n this.OnRecorderStop(res);\n }\n this.recorder.start();\n if (!this.speechRecognizer) {\n this.speechRecognizer = new SpeechRecognizer(this.params, this.requestId, this.isLog);\n }\n // 开始识别\n this.speechRecognizer.OnRecognitionStart = (res) => {\n if (this.recorder) { // 录音正常\n this.OnRecognitionStart(res);\n this.isCanSendData = true;\n } else {\n this.speechRecognizer && this.speechRecognizer.close();\n }\n };\n // 一句话开始\n this.speechRecognizer.OnSentenceBegin = (res) => {\n this.OnSentenceBegin(res);\n };\n // 识别变化时\n this.speechRecognizer.OnRecognitionResultChange = (res) => {\n this.OnRecognitionResultChange(res);\n };\n // 一句话结束\n this.speechRecognizer.OnSentenceEnd = (res) => {\n this.OnSentenceEnd(res);\n };\n // 识别结束\n this.speechRecognizer.OnRecognitionComplete = (res) => {\n this.OnRecognitionComplete(res);\n this.isCanSendData = false;\n this.isNormalEndStop = true;\n };\n // 识别错误\n this.speechRecognizer.OnError = (res) => {\n if (this.speechRecognizer && !this.isNormalEndStop) {\n this.OnError(res);\n }\n this.speechRecognizer = null;\n this.recorder && this.recorder.stop();\n this.isCanSendData = false;\n };\n // 建立连接\n this.speechRecognizer.start();\n }\n stop() {\n this.isLog && console.log('stop function is click');\n if (this.recorder) {\n this.recorder.stop();\n }\n // if (this.speechRecognizer) {\n // this.speechRecognizer.stop();\n // }\n }\n destroyStream() {\n this.isLog && console.log('destroyStream function is click', this.recorder);\n if (this.recorder) {\n this.recorder.destroyStream();\n }\n }\n // 开始识别的时候\n OnRecognitionStart(res) {}\n // 一句话开始的时候\n OnSentenceBegin(res) {}\n // 识别结果发生变化的时候\n OnRecognitionResultChange() {}\n // 一句话结束的时候\n OnSentenceEnd() {}\n // 识别结束的时候\n OnRecognitionComplete() {}\n // 识别失败\n OnError() {}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