正在显示
3 个修改的文件
包含
30 行增加
和
6 行删除
| @@ -106,9 +106,9 @@ if (navigator.mediaDevices.getUserMedia) { | @@ -106,9 +106,9 @@ if (navigator.mediaDevices.getUserMedia) { | ||
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | let result = recognizer.getResult(recognizer_stream); | 108 | let result = recognizer.getResult(recognizer_stream); |
| 109 | - console.log(result) | ||
| 110 | 109 | ||
| 111 | if (result.keyword.length > 0) { | 110 | if (result.keyword.length > 0) { |
| 111 | + console.log(result) | ||
| 112 | lastResult = result; | 112 | lastResult = result; |
| 113 | resultList.push(JSON.stringify(result)); | 113 | resultList.push(JSON.stringify(result)); |
| 114 | } | 114 | } |
| @@ -287,4 +287,4 @@ function downsampleBuffer(buffer, exportSampleRate) { | @@ -287,4 +287,4 @@ function downsampleBuffer(buffer, exportSampleRate) { | ||
| 287 | offsetBuffer = nextOffsetBuffer; | 287 | offsetBuffer = nextOffsetBuffer; |
| 288 | } | 288 | } |
| 289 | return result; | 289 | return result; |
| 290 | -}; | ||
| 290 | +}; |
| @@ -67,7 +67,7 @@ function initModelConfig(config, Module) { | @@ -67,7 +67,7 @@ function initModelConfig(config, Module) { | ||
| 67 | const paraformer_len = 2 * 4 | 67 | const paraformer_len = 2 * 4 |
| 68 | const ctc_len = 1 * 4 | 68 | const ctc_len = 1 * 4 |
| 69 | 69 | ||
| 70 | - const len = transducer.len + paraformer_len + ctc_len + 5 * 4; | 70 | + const len = transducer.len + paraformer_len + ctc_len + 7 * 4; |
| 71 | const ptr = Module._malloc(len); | 71 | const ptr = Module._malloc(len); |
| 72 | 72 | ||
| 73 | let offset = 0; | 73 | let offset = 0; |
| @@ -76,7 +76,10 @@ function initModelConfig(config, Module) { | @@ -76,7 +76,10 @@ function initModelConfig(config, Module) { | ||
| 76 | const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1; | 76 | const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1; |
| 77 | const providerLen = Module.lengthBytesUTF8(config.provider) + 1; | 77 | const providerLen = Module.lengthBytesUTF8(config.provider) + 1; |
| 78 | const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1; | 78 | const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1; |
| 79 | - const bufferLen = tokensLen + providerLen + modelTypeLen; | 79 | + const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1; |
| 80 | + const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1; | ||
| 81 | + const bufferLen = | ||
| 82 | + tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen; | ||
| 80 | const buffer = Module._malloc(bufferLen); | 83 | const buffer = Module._malloc(bufferLen); |
| 81 | 84 | ||
| 82 | offset = 0; | 85 | offset = 0; |
| @@ -87,6 +90,14 @@ function initModelConfig(config, Module) { | @@ -87,6 +90,14 @@ function initModelConfig(config, Module) { | ||
| 87 | offset += providerLen; | 90 | offset += providerLen; |
| 88 | 91 | ||
| 89 | Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen); | 92 | Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen); |
| 93 | + offset += modelTypeLen; | ||
| 94 | + | ||
| 95 | + Module.stringToUTF8( | ||
| 96 | + config.modelingUnit || '', buffer + offset, modelingUnitLen); | ||
| 97 | + offset += modelingUnitLen; | ||
| 98 | + | ||
| 99 | + Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen); | ||
| 100 | + offset += bpeVocabLen; | ||
| 90 | 101 | ||
| 91 | offset = transducer.len + paraformer_len + ctc_len; | 102 | offset = transducer.len + paraformer_len + ctc_len; |
| 92 | Module.setValue(ptr + offset, buffer, 'i8*'); // tokens | 103 | Module.setValue(ptr + offset, buffer, 'i8*'); // tokens |
| @@ -105,6 +116,17 @@ function initModelConfig(config, Module) { | @@ -105,6 +116,17 @@ function initModelConfig(config, Module) { | ||
| 105 | ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType | 116 | ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType |
| 106 | offset += 4; | 117 | offset += 4; |
| 107 | 118 | ||
| 119 | + Module.setValue( | ||
| 120 | + ptr + offset, buffer + tokensLen + providerLen + modelTypeLen, | ||
| 121 | + 'i8*'); // modelingUnit | ||
| 122 | + offset += 4; | ||
| 123 | + | ||
| 124 | + Module.setValue( | ||
| 125 | + ptr + offset, | ||
| 126 | + buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen, | ||
| 127 | + 'i8*'); // bpeVocab | ||
| 128 | + offset += 4; | ||
| 129 | + | ||
| 108 | return { | 130 | return { |
| 109 | buffer: buffer, ptr: ptr, len: len, transducer: transducer | 131 | buffer: buffer, ptr: ptr, len: len, transducer: transducer |
| 110 | } | 132 | } |
| @@ -248,7 +270,9 @@ function createKws(Module, myConfig) { | @@ -248,7 +270,9 @@ function createKws(Module, myConfig) { | ||
| 248 | provider: 'cpu', | 270 | provider: 'cpu', |
| 249 | modelType: '', | 271 | modelType: '', |
| 250 | numThreads: 1, | 272 | numThreads: 1, |
| 251 | - debug: 1 | 273 | + debug: 1, |
| 274 | + modelingUnit: 'cjkchar', | ||
| 275 | + bpeVocab: '', | ||
| 252 | }; | 276 | }; |
| 253 | 277 | ||
| 254 | let featConfig = { | 278 | let featConfig = { |
| @@ -19,7 +19,7 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, ""); | @@ -19,7 +19,7 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, ""); | ||
| 19 | static_assert(sizeof(SherpaOnnxOnlineModelConfig) == | 19 | static_assert(sizeof(SherpaOnnxOnlineModelConfig) == |
| 20 | sizeof(SherpaOnnxOnlineTransducerModelConfig) + | 20 | sizeof(SherpaOnnxOnlineTransducerModelConfig) + |
| 21 | sizeof(SherpaOnnxOnlineParaformerModelConfig) + | 21 | sizeof(SherpaOnnxOnlineParaformerModelConfig) + |
| 22 | - sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 5 * 4, | 22 | + sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 7 * 4, |
| 23 | ""); | 23 | ""); |
| 24 | static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, ""); | 24 | static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, ""); |
| 25 | static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) == | 25 | static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) == |
-
请 注册 或 登录 后发表评论