react_hsbc_teller 2.0.54 → 2.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +39 -39
- package/README.en.md +36 -36
- package/README.md +323 -323
- package/config/webpack.config.js +119 -119
- package/config/webpack.dev.js +108 -108
- package/config/webpack.prod.js +104 -104
- package/lib/hsbc.js +1 -1
- package/lib/hsbc.js.LICENSE.txt +13 -16
- package/package.json +110 -110
- package/packages/api/api.js +818 -818
- package/packages/api/server.js +50 -50
- package/packages/common/index.esm.js +374 -374
- package/packages/demo/demo.js +306 -306
- package/packages/demo/index.js +3 -3
- package/packages/demo/pdf.js +94 -94
- package/packages/envconfig/envconfig.js +12 -12
- package/packages/index.js +2 -2
- package/packages/pages/components/step/step.jsx +32 -31
- package/packages/pages/foot/foot.jsx +235 -235
- package/packages/pages/foot/foot.less +85 -85
- package/packages/pages/header/header.jsx +15 -15
- package/packages/pages/header/header.less +51 -51
- package/packages/pages/index.jsx +52 -52
- package/packages/pages/multiModule/components/copy/agree.jsx +115 -115
- package/packages/pages/multiModule/components/copy/agree.less +105 -105
- package/packages/pages/multiModule/components/copy/copyTwo.jsx +682 -682
- package/packages/pages/multiModule/components/copy/copyTwo.less +180 -180
- package/packages/pages/multiModule/components/copy/copy_en.jsx +368 -368
- package/packages/pages/multiModule/components/copy/copy_en.less +145 -145
- package/packages/pages/multiModule/components/copy/copylist.jsx +291 -291
- package/packages/pages/multiModule/components/copy/copylist.less +83 -83
- package/packages/pages/multiModule/components/copy/risk.jsx +296 -296
- package/packages/pages/multiModule/components/copy/risk.less +123 -123
- package/packages/pages/multiModule/components/sign/signMy.jsx +308 -308
- package/packages/pages/multiModule/components/sign/signMy.less +127 -127
- package/packages/pages/multiModule/components/subscribe/subscribe.jsx +113 -113
- package/packages/pages/multiModule/components/subscribe/subscribe.less +82 -82
- package/packages/pages/multiModule/multiModule.jsx +26 -26
- package/packages/pages/multiModule/multiModule.less +19 -19
- package/packages/pages/sign/signMy.jsx +223 -223
- package/packages/pages/sign/signMy.less +129 -129
- package/packages/pages/video/video.jsx +7746 -7745
- package/packages/pages/video/video.less +715 -715
- package/packages/style/index.less +1 -1
- package/packages/style/reset.less +345 -345
- package/packages/utils/asrController.js +259 -259
- package/packages/utils/asyncComponent.jsx +26 -26
- package/packages/utils/mixin.js +27 -27
- package/packages/utils/setRem.js +10 -10
- package/packages/utils/utils.js +199 -199
- package/public/index.html +77 -77
- package/src/index.js +11 -11
- package/src/index.less +5 -5
- package/tsconfig.json +11 -11
|
@@ -1,259 +1,259 @@
|
|
|
1
|
-
// import Recorder from "recorder-js";
|
|
2
|
-
// import Recorder from "js-audio-recorder";
|
|
3
|
-
// import Recorder from "./recorder";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// console.log(Recorder)
|
|
7
|
-
//生成32位随机数UUID
|
|
8
|
-
function getRandomStrNum(){
|
|
9
|
-
var s = [];
|
|
10
|
-
var hexDigits = "0123456789abcdef";
|
|
11
|
-
for (var i = 0; i < 32; i++) {
|
|
12
|
-
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
13
|
-
}
|
|
14
|
-
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
15
|
-
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
16
|
-
s[8] = s[13] = s[18] = s[23];
|
|
17
|
-
|
|
18
|
-
var uuid = s.join("");
|
|
19
|
-
return uuid;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//获取ali的token
|
|
24
|
-
let token = 'a07198021d434d1288cd4ab3178712cb';
|
|
25
|
-
let appkey = 'E6DAPlpMun5L2dJ7';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//定义ws的相关参数
|
|
29
|
-
let websocket = null; //websocket实例
|
|
30
|
-
let timer_websocket = null; //websocket定时器, 用于实时获取语音转文本的结果
|
|
31
|
-
let websocket_task_id = null; //websocket任务id 整个实时语音识别的会话ID,整个请求中需要保持一致,32位唯一ID。
|
|
32
|
-
let websocket_audio2txt_time = 0; //websocket 语音转文本 一句话收集完毕的时间,用于判断间隔
|
|
33
|
-
let websocket_audio2txt_result_msg = null; //websocket实例 音频转文字的结果
|
|
34
|
-
let websocket_audio2txt_result_msg_temp = null; //websocket实例 音频转文字的结果
|
|
35
|
-
let websocket_audio2txt_complete_b = false; //websocket 语音转文本 是否完成 true:完毕 false:未完毕
|
|
36
|
-
let websocket_audio2txt_complete_time_end = 100; //websocket 语音转文本 判断文本是否收集完毕的阈值 单位毫秒
|
|
37
|
-
|
|
38
|
-
export default class MyAsrController {
|
|
39
|
-
constructor(headers) {
|
|
40
|
-
console.log('MyAsrController', headers, headers.appKey)
|
|
41
|
-
this.token = headers.token || 'default';
|
|
42
|
-
this.appKey = headers.appKey;
|
|
43
|
-
this.url = headers.url;
|
|
44
|
-
|
|
45
|
-
//初始化录音实例
|
|
46
|
-
// this.recorderInstance = new Recorder({
|
|
47
|
-
// sampleBits: 16, // 采样位数,,默认是16
|
|
48
|
-
// sampleRate: 16000, //音频采样率,默认是16000Hz,
|
|
49
|
-
// numChannels: 1, // 声道,支持 1 或 2, 默认是1
|
|
50
|
-
// compiling: true // 是否边录边转换,默认是false
|
|
51
|
-
// });
|
|
52
|
-
this.recorderInstance = headers.recorder
|
|
53
|
-
// console.log(this.recorderInstance)
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
onAsrMessage(data) {
|
|
57
|
-
console.log('onAsrMessage: ', data.result)
|
|
58
|
-
}
|
|
59
|
-
onSentenceEnd(data) {
|
|
60
|
-
console.log('onSentenceEnd: ', data)
|
|
61
|
-
}
|
|
62
|
-
onSentenceBegin(data) {
|
|
63
|
-
console.log('检测到了一句话的开始');
|
|
64
|
-
}
|
|
65
|
-
onConnectOK() {
|
|
66
|
-
console.log('连接成功');
|
|
67
|
-
}
|
|
68
|
-
onConnectError(data) {
|
|
69
|
-
console.log('连接错误');
|
|
70
|
-
}
|
|
71
|
-
onAsrError(data) {
|
|
72
|
-
console.log('服务端返回错误');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
initWebSocket() {
|
|
76
|
-
console.log("初始化weosocket");
|
|
77
|
-
|
|
78
|
-
//初始化参数
|
|
79
|
-
websocket_audio2txt_complete_b = false;
|
|
80
|
-
websocket_audio2txt_time = 0;
|
|
81
|
-
|
|
82
|
-
//检测如果未关闭、则先关闭在重连
|
|
83
|
-
if (this.websocket){
|
|
84
|
-
this.websocket.close();
|
|
85
|
-
this.websocket = null;
|
|
86
|
-
}
|
|
87
|
-
try{
|
|
88
|
-
console.log(`${this.url}?token=${this.token}`);
|
|
89
|
-
this.websocket = new WebSocket(`${this.url}?token=${this.token}`);
|
|
90
|
-
// this.websocket.debug = true;
|
|
91
|
-
|
|
92
|
-
this.websocket.onmessage = this.websocketOnMessage.bind(this);
|
|
93
|
-
this.websocket.onopen = this.websocketOnOpen.bind(this);
|
|
94
|
-
this.websocket.onerror = this.websocketOnError.bind(this);
|
|
95
|
-
this.websocket.onclose = this.websocketClose.bind(this);
|
|
96
|
-
}catch(err) {
|
|
97
|
-
console.error(err)
|
|
98
|
-
this.onConnectError()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
Disconnect() {
|
|
104
|
-
try {
|
|
105
|
-
this.recorderInstance.stop();
|
|
106
|
-
} catch(err){
|
|
107
|
-
console.log(err)
|
|
108
|
-
}
|
|
109
|
-
clearInterval(this.interval);
|
|
110
|
-
this.websocketStopTranscription()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
websocketOnOpen() { // 连接建立之后执行send方法发送数据
|
|
114
|
-
//生成新的任务id
|
|
115
|
-
websocket_task_id = getRandomStrNum();
|
|
116
|
-
//生成ali的请求参数message_id
|
|
117
|
-
let message_id = getRandomStrNum();
|
|
118
|
-
const appKey = this.appKey;
|
|
119
|
-
|
|
120
|
-
let actions = {
|
|
121
|
-
"header":{
|
|
122
|
-
"namespace":"SpeechTranscriber", //固定值
|
|
123
|
-
"name": "StartTranscription", //发送请求的名称,固定值
|
|
124
|
-
"appkey": appKey, //appkey
|
|
125
|
-
"message_id": message_id, //消息id
|
|
126
|
-
"task_id": websocket_task_id, //任务id
|
|
127
|
-
},
|
|
128
|
-
"payload":{
|
|
129
|
-
"format": "PCM",//音频编码格式,默认是PCM(无压缩的PCM文件或WAV文件),16bit采样位数的单声道。
|
|
130
|
-
"sample_rate": 16000, //需要与录音采样率一致、默认是16000,单位是Hz。
|
|
131
|
-
"enable_intermediate_result": true, //是否返回中间识别结果,默认是false。
|
|
132
|
-
"enable_punctuation_prediction": true, //是否在后处理中添加标点,默认是false。
|
|
133
|
-
"enable_inverse_text_normalization": true, //是否在后处理中执行数字转写,默认是false。
|
|
134
|
-
"max_sentence_silence":300,// 语音断句检测阈值,静音时长超过该阈值会被认为断句,参数范围200ms~2000ms,默认值800ms。
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//发送请求
|
|
139
|
-
this.websocketSend(JSON.stringify(actions));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
websocketStopTranscription() {
|
|
143
|
-
//生成ali的请求参数message_id
|
|
144
|
-
let message_id = getRandomStrNum();
|
|
145
|
-
const appKey = this.appKey;
|
|
146
|
-
|
|
147
|
-
let actions = {
|
|
148
|
-
"header":{
|
|
149
|
-
"namespace":"SpeechTranscriber", //固定值
|
|
150
|
-
"name": "StopTranscription", //发送请求的名称,固定值
|
|
151
|
-
"appkey": appKey, //appkey
|
|
152
|
-
"message_id": message_id, //消息id
|
|
153
|
-
"task_id": websocket_task_id, //任务id
|
|
154
|
-
},
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
//发送请求
|
|
158
|
-
this.websocketSend(JSON.stringify(actions));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
websocketOnError() {
|
|
162
|
-
console.log("连接建立失败");
|
|
163
|
-
this.onConnectError()
|
|
164
|
-
this.Disconnect()
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
websocketOnMessage(e) {
|
|
168
|
-
//接受ali 语音返回的数据
|
|
169
|
-
const ret = JSON.parse(e.data);
|
|
170
|
-
//判断返回的数据类型
|
|
171
|
-
if (ret.header.name === 'TranscriptionResultChanged'){
|
|
172
|
-
//数据在收集中 一句话的中间结果
|
|
173
|
-
// console.log('数据在收集中');
|
|
174
|
-
//实时获取语音转文本的结果
|
|
175
|
-
this.onAsrMessage({
|
|
176
|
-
result: ret.payload.result,
|
|
177
|
-
index: ret.payload.index,
|
|
178
|
-
words: ret.payload.words,
|
|
179
|
-
})
|
|
180
|
-
// ingText(ret.payload.result);
|
|
181
|
-
} else if (ret.header.name === 'SentenceBegin') {
|
|
182
|
-
//一句话开始后,就可以启动录音了
|
|
183
|
-
this.onSentenceBegin({
|
|
184
|
-
index: ret.payload.index,
|
|
185
|
-
})
|
|
186
|
-
} else if (ret.header.name === 'TranscriptionStarted') {
|
|
187
|
-
console.log("服务端已经准备好了进行识别,客户端可以发送音频数据了");
|
|
188
|
-
this.onConnectOK();
|
|
189
|
-
//获取音频信息,定时获取并发送
|
|
190
|
-
this.interval = setInterval(() => {
|
|
191
|
-
this.getPCMAndSend();
|
|
192
|
-
}, 100)
|
|
193
|
-
} else if (ret.header.name === 'SentenceEnd') {
|
|
194
|
-
// console.log('数据接收结束', ret);
|
|
195
|
-
this.onSentenceEnd({
|
|
196
|
-
result: ret.payload.result,
|
|
197
|
-
index: ret.payload.index,
|
|
198
|
-
})
|
|
199
|
-
} else if ( ret.header.name === 'TranscriptionCompleted') {
|
|
200
|
-
console.log('服务端已停止了语音转写', ret);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (ret.header.status != 20000000) {
|
|
204
|
-
this.onAsrError({
|
|
205
|
-
status: ret.header.status,
|
|
206
|
-
message: ret.header.status_text,
|
|
207
|
-
taskId: ret.header.task_id,
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
// console.log('status返回正常')
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
websocketSend(Data) { // 数据发送
|
|
215
|
-
//console.log('websocket 数据发送',data);
|
|
216
|
-
//判断是否连接成功,连接成功再发送数据过去
|
|
217
|
-
if (this.websocket.readyState===1){
|
|
218
|
-
this.websocket.send(Data);
|
|
219
|
-
} else {
|
|
220
|
-
console.log('websock未连接-------------------');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
websocketClose(e) { // 关闭
|
|
225
|
-
console.log('断开连接', e);
|
|
226
|
-
// window.IMOpenfire('false')
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
//获取音频信息,并发送
|
|
230
|
-
getPCMAndSend() {
|
|
231
|
-
//获取音频信息
|
|
232
|
-
let NextData = this.recorderInstance.getNextData();
|
|
233
|
-
let blob = new Blob(NextData)
|
|
234
|
-
let blob_size = blob.size;
|
|
235
|
-
// console.log("获取音频信息,并发送,blob_size:"+blob_size , blob);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
//ali最大支持3200字节的音频
|
|
239
|
-
let max_blob_size = 3200;//支持1600 或3200
|
|
240
|
-
let my_num = blob_size/max_blob_size;
|
|
241
|
-
my_num = my_num + 1;
|
|
242
|
-
|
|
243
|
-
//切分音频发送
|
|
244
|
-
for (let i = 0; i < my_num; i++) {
|
|
245
|
-
var end_index_blob = max_blob_size*(i+1);
|
|
246
|
-
//判断结束时候的分界
|
|
247
|
-
if(end_index_blob > blob_size){
|
|
248
|
-
end_index_blob = blob_size;
|
|
249
|
-
}
|
|
250
|
-
//切分音频
|
|
251
|
-
var blob2 = blob.slice(i*max_blob_size,end_index_blob);
|
|
252
|
-
//生成新的blob
|
|
253
|
-
const newbolb = new Blob([blob2], {type: 'audio/pcm'})
|
|
254
|
-
//发送
|
|
255
|
-
this.websocketSend(newbolb);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
}
|
|
1
|
+
// import Recorder from "recorder-js";
|
|
2
|
+
// import Recorder from "js-audio-recorder";
|
|
3
|
+
// import Recorder from "./recorder";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// console.log(Recorder)
|
|
7
|
+
//生成32位随机数UUID
|
|
8
|
+
function getRandomStrNum(){
|
|
9
|
+
var s = [];
|
|
10
|
+
var hexDigits = "0123456789abcdef";
|
|
11
|
+
for (var i = 0; i < 32; i++) {
|
|
12
|
+
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
13
|
+
}
|
|
14
|
+
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
15
|
+
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
16
|
+
s[8] = s[13] = s[18] = s[23];
|
|
17
|
+
|
|
18
|
+
var uuid = s.join("");
|
|
19
|
+
return uuid;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
//获取ali的token
|
|
24
|
+
let token = 'a07198021d434d1288cd4ab3178712cb';
|
|
25
|
+
let appkey = 'E6DAPlpMun5L2dJ7';
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
//定义ws的相关参数
|
|
29
|
+
let websocket = null; //websocket实例
|
|
30
|
+
let timer_websocket = null; //websocket定时器, 用于实时获取语音转文本的结果
|
|
31
|
+
let websocket_task_id = null; //websocket任务id 整个实时语音识别的会话ID,整个请求中需要保持一致,32位唯一ID。
|
|
32
|
+
let websocket_audio2txt_time = 0; //websocket 语音转文本 一句话收集完毕的时间,用于判断间隔
|
|
33
|
+
let websocket_audio2txt_result_msg = null; //websocket实例 音频转文字的结果
|
|
34
|
+
let websocket_audio2txt_result_msg_temp = null; //websocket实例 音频转文字的结果
|
|
35
|
+
let websocket_audio2txt_complete_b = false; //websocket 语音转文本 是否完成 true:完毕 false:未完毕
|
|
36
|
+
let websocket_audio2txt_complete_time_end = 100; //websocket 语音转文本 判断文本是否收集完毕的阈值 单位毫秒
|
|
37
|
+
|
|
38
|
+
export default class MyAsrController {
|
|
39
|
+
constructor(headers) {
|
|
40
|
+
console.log('MyAsrController', headers, headers.appKey)
|
|
41
|
+
this.token = headers.token || 'default';
|
|
42
|
+
this.appKey = headers.appKey;
|
|
43
|
+
this.url = headers.url;
|
|
44
|
+
|
|
45
|
+
//初始化录音实例
|
|
46
|
+
// this.recorderInstance = new Recorder({
|
|
47
|
+
// sampleBits: 16, // 采样位数,,默认是16
|
|
48
|
+
// sampleRate: 16000, //音频采样率,默认是16000Hz,
|
|
49
|
+
// numChannels: 1, // 声道,支持 1 或 2, 默认是1
|
|
50
|
+
// compiling: true // 是否边录边转换,默认是false
|
|
51
|
+
// });
|
|
52
|
+
this.recorderInstance = headers.recorder
|
|
53
|
+
// console.log(this.recorderInstance)
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
onAsrMessage(data) {
|
|
57
|
+
console.log('onAsrMessage: ', data.result)
|
|
58
|
+
}
|
|
59
|
+
onSentenceEnd(data) {
|
|
60
|
+
console.log('onSentenceEnd: ', data)
|
|
61
|
+
}
|
|
62
|
+
onSentenceBegin(data) {
|
|
63
|
+
console.log('检测到了一句话的开始');
|
|
64
|
+
}
|
|
65
|
+
onConnectOK() {
|
|
66
|
+
console.log('连接成功');
|
|
67
|
+
}
|
|
68
|
+
onConnectError(data) {
|
|
69
|
+
console.log('连接错误');
|
|
70
|
+
}
|
|
71
|
+
onAsrError(data) {
|
|
72
|
+
console.log('服务端返回错误');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
initWebSocket() {
|
|
76
|
+
console.log("初始化weosocket");
|
|
77
|
+
|
|
78
|
+
//初始化参数
|
|
79
|
+
websocket_audio2txt_complete_b = false;
|
|
80
|
+
websocket_audio2txt_time = 0;
|
|
81
|
+
|
|
82
|
+
//检测如果未关闭、则先关闭在重连
|
|
83
|
+
if (this.websocket){
|
|
84
|
+
this.websocket.close();
|
|
85
|
+
this.websocket = null;
|
|
86
|
+
}
|
|
87
|
+
try{
|
|
88
|
+
console.log(`${this.url}?token=${this.token}`);
|
|
89
|
+
this.websocket = new WebSocket(`${this.url}?token=${this.token}`);
|
|
90
|
+
// this.websocket.debug = true;
|
|
91
|
+
|
|
92
|
+
this.websocket.onmessage = this.websocketOnMessage.bind(this);
|
|
93
|
+
this.websocket.onopen = this.websocketOnOpen.bind(this);
|
|
94
|
+
this.websocket.onerror = this.websocketOnError.bind(this);
|
|
95
|
+
this.websocket.onclose = this.websocketClose.bind(this);
|
|
96
|
+
}catch(err) {
|
|
97
|
+
console.error(err)
|
|
98
|
+
this.onConnectError()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Disconnect() {
|
|
104
|
+
try {
|
|
105
|
+
this.recorderInstance.stop();
|
|
106
|
+
} catch(err){
|
|
107
|
+
console.log(err)
|
|
108
|
+
}
|
|
109
|
+
clearInterval(this.interval);
|
|
110
|
+
this.websocketStopTranscription()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
websocketOnOpen() { // 连接建立之后执行send方法发送数据
|
|
114
|
+
//生成新的任务id
|
|
115
|
+
websocket_task_id = getRandomStrNum();
|
|
116
|
+
//生成ali的请求参数message_id
|
|
117
|
+
let message_id = getRandomStrNum();
|
|
118
|
+
const appKey = this.appKey;
|
|
119
|
+
|
|
120
|
+
let actions = {
|
|
121
|
+
"header":{
|
|
122
|
+
"namespace":"SpeechTranscriber", //固定值
|
|
123
|
+
"name": "StartTranscription", //发送请求的名称,固定值
|
|
124
|
+
"appkey": appKey, //appkey
|
|
125
|
+
"message_id": message_id, //消息id
|
|
126
|
+
"task_id": websocket_task_id, //任务id
|
|
127
|
+
},
|
|
128
|
+
"payload":{
|
|
129
|
+
"format": "PCM",//音频编码格式,默认是PCM(无压缩的PCM文件或WAV文件),16bit采样位数的单声道。
|
|
130
|
+
"sample_rate": 16000, //需要与录音采样率一致、默认是16000,单位是Hz。
|
|
131
|
+
"enable_intermediate_result": true, //是否返回中间识别结果,默认是false。
|
|
132
|
+
"enable_punctuation_prediction": true, //是否在后处理中添加标点,默认是false。
|
|
133
|
+
"enable_inverse_text_normalization": true, //是否在后处理中执行数字转写,默认是false。
|
|
134
|
+
"max_sentence_silence":300,// 语音断句检测阈值,静音时长超过该阈值会被认为断句,参数范围200ms~2000ms,默认值800ms。
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//发送请求
|
|
139
|
+
this.websocketSend(JSON.stringify(actions));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
websocketStopTranscription() {
|
|
143
|
+
//生成ali的请求参数message_id
|
|
144
|
+
let message_id = getRandomStrNum();
|
|
145
|
+
const appKey = this.appKey;
|
|
146
|
+
|
|
147
|
+
let actions = {
|
|
148
|
+
"header":{
|
|
149
|
+
"namespace":"SpeechTranscriber", //固定值
|
|
150
|
+
"name": "StopTranscription", //发送请求的名称,固定值
|
|
151
|
+
"appkey": appKey, //appkey
|
|
152
|
+
"message_id": message_id, //消息id
|
|
153
|
+
"task_id": websocket_task_id, //任务id
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//发送请求
|
|
158
|
+
this.websocketSend(JSON.stringify(actions));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
websocketOnError() {
|
|
162
|
+
console.log("连接建立失败");
|
|
163
|
+
this.onConnectError()
|
|
164
|
+
this.Disconnect()
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
websocketOnMessage(e) {
|
|
168
|
+
//接受ali 语音返回的数据
|
|
169
|
+
const ret = JSON.parse(e.data);
|
|
170
|
+
//判断返回的数据类型
|
|
171
|
+
if (ret.header.name === 'TranscriptionResultChanged'){
|
|
172
|
+
//数据在收集中 一句话的中间结果
|
|
173
|
+
// console.log('数据在收集中');
|
|
174
|
+
//实时获取语音转文本的结果
|
|
175
|
+
this.onAsrMessage({
|
|
176
|
+
result: ret.payload.result,
|
|
177
|
+
index: ret.payload.index,
|
|
178
|
+
words: ret.payload.words,
|
|
179
|
+
})
|
|
180
|
+
// ingText(ret.payload.result);
|
|
181
|
+
} else if (ret.header.name === 'SentenceBegin') {
|
|
182
|
+
//一句话开始后,就可以启动录音了
|
|
183
|
+
this.onSentenceBegin({
|
|
184
|
+
index: ret.payload.index,
|
|
185
|
+
})
|
|
186
|
+
} else if (ret.header.name === 'TranscriptionStarted') {
|
|
187
|
+
console.log("服务端已经准备好了进行识别,客户端可以发送音频数据了");
|
|
188
|
+
this.onConnectOK();
|
|
189
|
+
//获取音频信息,定时获取并发送
|
|
190
|
+
this.interval = setInterval(() => {
|
|
191
|
+
this.getPCMAndSend();
|
|
192
|
+
}, 100)
|
|
193
|
+
} else if (ret.header.name === 'SentenceEnd') {
|
|
194
|
+
// console.log('数据接收结束', ret);
|
|
195
|
+
this.onSentenceEnd({
|
|
196
|
+
result: ret.payload.result,
|
|
197
|
+
index: ret.payload.index,
|
|
198
|
+
})
|
|
199
|
+
} else if ( ret.header.name === 'TranscriptionCompleted') {
|
|
200
|
+
console.log('服务端已停止了语音转写', ret);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (ret.header.status != 20000000) {
|
|
204
|
+
this.onAsrError({
|
|
205
|
+
status: ret.header.status,
|
|
206
|
+
message: ret.header.status_text,
|
|
207
|
+
taskId: ret.header.task_id,
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
// console.log('status返回正常')
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
websocketSend(Data) { // 数据发送
|
|
215
|
+
//console.log('websocket 数据发送',data);
|
|
216
|
+
//判断是否连接成功,连接成功再发送数据过去
|
|
217
|
+
if (this.websocket.readyState===1){
|
|
218
|
+
this.websocket.send(Data);
|
|
219
|
+
} else {
|
|
220
|
+
console.log('websock未连接-------------------');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
websocketClose(e) { // 关闭
|
|
225
|
+
console.log('断开连接', e);
|
|
226
|
+
// window.IMOpenfire('false')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//获取音频信息,并发送
|
|
230
|
+
getPCMAndSend() {
|
|
231
|
+
//获取音频信息
|
|
232
|
+
let NextData = this.recorderInstance.getNextData();
|
|
233
|
+
let blob = new Blob(NextData)
|
|
234
|
+
let blob_size = blob.size;
|
|
235
|
+
// console.log("获取音频信息,并发送,blob_size:"+blob_size , blob);
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
//ali最大支持3200字节的音频
|
|
239
|
+
let max_blob_size = 3200;//支持1600 或3200
|
|
240
|
+
let my_num = blob_size/max_blob_size;
|
|
241
|
+
my_num = my_num + 1;
|
|
242
|
+
|
|
243
|
+
//切分音频发送
|
|
244
|
+
for (let i = 0; i < my_num; i++) {
|
|
245
|
+
var end_index_blob = max_blob_size*(i+1);
|
|
246
|
+
//判断结束时候的分界
|
|
247
|
+
if(end_index_blob > blob_size){
|
|
248
|
+
end_index_blob = blob_size;
|
|
249
|
+
}
|
|
250
|
+
//切分音频
|
|
251
|
+
var blob2 = blob.slice(i*max_blob_size,end_index_blob);
|
|
252
|
+
//生成新的blob
|
|
253
|
+
const newbolb = new Blob([blob2], {type: 'audio/pcm'})
|
|
254
|
+
//发送
|
|
255
|
+
this.websocketSend(newbolb);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import React, { Component } from "react";
|
|
2
|
-
|
|
3
|
-
export default function asyncComponent(importComponent) {
|
|
4
|
-
class AsyncComponent extends Component {
|
|
5
|
-
constructor(props) {
|
|
6
|
-
super(props);
|
|
7
|
-
|
|
8
|
-
this.state = {
|
|
9
|
-
component: null
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async componentDidMount() {
|
|
14
|
-
const { default: component } = await importComponent();
|
|
15
|
-
|
|
16
|
-
this.setState({component});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
render() {
|
|
20
|
-
const C = this.state.component;
|
|
21
|
-
|
|
22
|
-
return C ? <C {...this.props} /> : null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return AsyncComponent;
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
|
|
3
|
+
export default function asyncComponent(importComponent) {
|
|
4
|
+
class AsyncComponent extends Component {
|
|
5
|
+
constructor(props) {
|
|
6
|
+
super(props);
|
|
7
|
+
|
|
8
|
+
this.state = {
|
|
9
|
+
component: null
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async componentDidMount() {
|
|
14
|
+
const { default: component } = await importComponent();
|
|
15
|
+
|
|
16
|
+
this.setState({component});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
render() {
|
|
20
|
+
const C = this.state.component;
|
|
21
|
+
|
|
22
|
+
return C ? <C {...this.props} /> : null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return AsyncComponent;
|
|
27
27
|
}
|
package/packages/utils/mixin.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export default methods => {
|
|
2
|
-
return target => {
|
|
3
|
-
Object.assign(target.prototype, methods);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 字符串填充函数
|
|
9
|
-
* @param {string} value 目标字符串
|
|
10
|
-
* @param {array} position 需要填充的位置
|
|
11
|
-
* @param {string} padstr 填充字符串
|
|
12
|
-
* @return {string} 返回目标字符串
|
|
13
|
-
*/
|
|
14
|
-
export const padStr = (value, position, padstr, inputElement) => {
|
|
15
|
-
position.forEach((item, index) => {
|
|
16
|
-
if (value.length > item + index) {
|
|
17
|
-
value = value.substring(0, item + index) + padstr + value.substring(item + index)
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
value = value.trim();
|
|
21
|
-
// 解决安卓部分浏览器插入空格后光标错位问题
|
|
22
|
-
requestAnimationFrame(() => {
|
|
23
|
-
inputElement.setSelectionRange(value.length, value.length);
|
|
24
|
-
})
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
|
|
1
|
+
export default methods => {
|
|
2
|
+
return target => {
|
|
3
|
+
Object.assign(target.prototype, methods);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 字符串填充函数
|
|
9
|
+
* @param {string} value 目标字符串
|
|
10
|
+
* @param {array} position 需要填充的位置
|
|
11
|
+
* @param {string} padstr 填充字符串
|
|
12
|
+
* @return {string} 返回目标字符串
|
|
13
|
+
*/
|
|
14
|
+
export const padStr = (value, position, padstr, inputElement) => {
|
|
15
|
+
position.forEach((item, index) => {
|
|
16
|
+
if (value.length > item + index) {
|
|
17
|
+
value = value.substring(0, item + index) + padstr + value.substring(item + index)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
value = value.trim();
|
|
21
|
+
// 解决安卓部分浏览器插入空格后光标错位问题
|
|
22
|
+
requestAnimationFrame(() => {
|
|
23
|
+
inputElement.setSelectionRange(value.length, value.length);
|
|
24
|
+
})
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
package/packages/utils/setRem.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(function(psdw){
|
|
2
|
-
var dpr=0 , rem=0 , scale=0;
|
|
3
|
-
var htmlDOM=document.documentElement;
|
|
4
|
-
dpr=window.devicePixelRatio;
|
|
5
|
-
var currentWidth=htmlDOM.clientWidth;
|
|
6
|
-
scale=currentWidth/psdw;
|
|
7
|
-
rem=psdw/14;
|
|
8
|
-
rem=rem*scale;
|
|
9
|
-
htmlDOM.style.fontSize=rem+'px';
|
|
10
|
-
htmlDOM.setAttribute('data-dpr',dpr)
|
|
1
|
+
(function(psdw){
|
|
2
|
+
var dpr=0 , rem=0 , scale=0;
|
|
3
|
+
var htmlDOM=document.documentElement;
|
|
4
|
+
dpr=window.devicePixelRatio;
|
|
5
|
+
var currentWidth=htmlDOM.clientWidth;
|
|
6
|
+
scale=currentWidth/psdw;
|
|
7
|
+
rem=psdw/14;
|
|
8
|
+
rem=rem*scale;
|
|
9
|
+
htmlDOM.style.fontSize=rem+'px';
|
|
10
|
+
htmlDOM.setAttribute('data-dpr',dpr)
|
|
11
11
|
})(1920)
|