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

1 line
10 KiB
JSON
Raw Normal View History

2024-01-18 10:46:33 +08:00
{"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