@@ -8,34 +8,10 @@ import {
88 SECOND ,
99} from '../constants/sttDefaults' ;
1010import { _SpeechToTextModule } from '../native/RnExecutorchModules' ;
11+ import { TokenDecoder } from '../tokenizers/tokenDecoder' ;
1112import { ResourceSource } from '../types/common' ;
1213import { fetchResource } from '../utils/fetchResource' ;
13- import { TokenDecoder } from '../tokenizers/tokenDecoder' ;
14-
15- const longCommonInfPref = ( seq1 : number [ ] , seq2 : number [ ] ) => {
16- let maxInd = 0 ;
17- let maxLength = 0 ;
18-
19- for ( let i = 0 ; i < seq1 . length ; i ++ ) {
20- let j = 0 ;
21- let hammingDist = 0 ;
22- while (
23- j < seq2 . length &&
24- i + j < seq1 . length &&
25- ( seq1 [ i + j ] === seq2 [ j ] || hammingDist < HAMMING_DIST_THRESHOLD )
26- ) {
27- if ( seq1 [ i + j ] !== seq2 [ j ] ) {
28- hammingDist ++ ;
29- }
30- j ++ ;
31- }
32- if ( j >= maxLength ) {
33- maxLength = j ;
34- maxInd = i ;
35- }
36- }
37- return maxInd ;
38- } ;
14+ import { longCommonInfPref } from '../utils/tokenizerUtils' ;
3915
4016export class SpeechToTextController {
4117 private nativeModule : _SpeechToTextModule ;
@@ -139,7 +115,6 @@ export class SpeechToTextController {
139115 this . onErrorCallback ?.(
140116 new Error ( `Error when loading the SpeechToTextController! ${ e } ` )
141117 ) ;
142- console . error ( 'Error when loading the SpeechToTextController!' , e ) ;
143118 }
144119 }
145120
@@ -223,7 +198,6 @@ export class SpeechToTextController {
223198 let output ;
224199 try {
225200 output = await this . nativeModule . decode ( seq , [ encoderOutput ] ) ;
226- console . log ( output [ 0 ] ) ;
227201 } catch ( error ) {
228202 this . onErrorCallback ?.( `Decode ${ error } ` ) ;
229203 return '' ;
@@ -264,7 +238,11 @@ export class SpeechToTextController {
264238 continue ;
265239 }
266240
267- const maxInd = longCommonInfPref ( seqs . at ( - 2 ) ! , seqs . at ( - 1 ) ! ) ;
241+ const maxInd = longCommonInfPref (
242+ seqs . at ( - 2 ) ! ,
243+ seqs . at ( - 1 ) ! ,
244+ HAMMING_DIST_THRESHOLD
245+ ) ;
268246 finalSeq = [ ...this . sequence , ...seqs . at ( - 2 ) ! . slice ( 0 , maxInd ) ] ;
269247 this . sequence = finalSeq ;
270248 this . decodedTranscribeCallback ( finalSeq ) ;
0 commit comments