react-native-sherpa-onnx 0.3.0 → 0.3.2
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/README.md +21 -7
- package/SherpaOnnx.podspec +1 -1
- package/android/build.gradle +35 -26
- package/android/prebuilt-download.gradle +27 -14
- package/android/src/main/cpp/CMakeLists.txt +51 -17
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.cpp +14 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +16 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +3 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +19 -2
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +2 -1
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +1 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +114 -8
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxOnlineSttHelper.kt +535 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +10 -10
- package/ios/SherpaOnnx+OnlineSTT.mm +365 -0
- package/ios/SherpaOnnx+TTS.mm +35 -9
- package/ios/SherpaOnnx.mm +6 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +3 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +16 -0
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +19 -2
- package/ios/model_detect/sherpa-onnx-model-detect.h +2 -1
- package/ios/online_stt/sherpa-onnx-online-stt-wrapper.h +85 -0
- package/ios/online_stt/sherpa-onnx-online-stt-wrapper.mm +270 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/stt/index.js +4 -0
- package/lib/module/stt/index.js.map +1 -1
- package/lib/module/stt/streaming.js +257 -0
- package/lib/module/stt/streaming.js.map +1 -0
- package/lib/module/stt/streamingTypes.js +38 -0
- package/lib/module/stt/streamingTypes.js.map +1 -0
- package/lib/module/tts/index.js +4 -43
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/streaming.js +220 -0
- package/lib/module/tts/streaming.js.map +1 -0
- package/lib/module/tts/streamingTypes.js +4 -0
- package/lib/module/tts/streamingTypes.js.map +1 -0
- package/lib/module/tts/types.js +8 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +66 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/stt/index.d.ts +3 -0
- package/lib/typescript/src/stt/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/streaming.d.ts +42 -0
- package/lib/typescript/src/stt/streaming.d.ts.map +1 -0
- package/lib/typescript/src/stt/streamingTypes.d.ts +122 -0
- package/lib/typescript/src/stt/streamingTypes.d.ts.map +1 -0
- package/lib/typescript/src/tts/index.d.ts +3 -1
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/streaming.d.ts +24 -0
- package/lib/typescript/src/tts/streaming.d.ts.map +1 -0
- package/lib/typescript/src/tts/streamingTypes.d.ts +27 -0
- package/lib/typescript/src/tts/streamingTypes.d.ts.map +1 -0
- package/lib/typescript/src/tts/types.d.ts +19 -6
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/NativeSherpaOnnx.ts +95 -0
- package/src/index.tsx +2 -2
- package/src/stt/index.ts +17 -0
- package/src/stt/streaming.ts +361 -0
- package/src/stt/streamingTypes.ts +151 -0
- package/src/tts/index.ts +6 -66
- package/src/tts/streaming.ts +336 -0
- package/src/tts/streamingTypes.ts +54 -0
- package/src/tts/types.ts +20 -10
- package/android/codegen.gradle +0 -57
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { OnlineSTTModelType, StreamingSttEngine, StreamingSttInitOptions } from './streamingTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Map detected STT model type (from detectSttModel) to an online (streaming) model type.
|
|
4
|
+
* Throws if the detected type has no streaming support.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mapDetectedToOnlineType(detectedType: string | undefined): OnlineSTTModelType;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the online (streaming) model type for a detected STT model type, or null if streaming is not supported.
|
|
9
|
+
* Use this to check whether the current model can be used with createStreamingSTT() (e.g. for live transcription).
|
|
10
|
+
*/
|
|
11
|
+
export declare function getOnlineTypeOrNull(detectedType: string | undefined): OnlineSTTModelType | null;
|
|
12
|
+
/**
|
|
13
|
+
* Create a streaming (online) STT engine. Use this for real-time recognition with
|
|
14
|
+
* partial results and endpoint detection. Call destroy() when done.
|
|
15
|
+
*
|
|
16
|
+
* @param options - Streaming STT init options (modelPath required; modelType optional, use 'auto' to detect from directory)
|
|
17
|
+
* @returns Promise resolving to a StreamingSttEngine
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // With explicit model type
|
|
21
|
+
* const engine = await createStreamingSTT({
|
|
22
|
+
* modelPath: { type: 'asset', path: 'models/streaming-zipformer-en' },
|
|
23
|
+
* modelType: 'transducer',
|
|
24
|
+
* });
|
|
25
|
+
* // With auto-detection
|
|
26
|
+
* const engine = await createStreamingSTT({
|
|
27
|
+
* modelPath: { type: 'asset', path: 'models/sherpa-onnx-streaming-t-one-russian-2025-09-08' },
|
|
28
|
+
* modelType: 'auto',
|
|
29
|
+
* });
|
|
30
|
+
* const stream = await engine.createStream();
|
|
31
|
+
* await stream.acceptWaveform(samples, 16000);
|
|
32
|
+
* if (await stream.isReady()) {
|
|
33
|
+
* await stream.decode();
|
|
34
|
+
* const result = await stream.getResult();
|
|
35
|
+
* console.log(result.text);
|
|
36
|
+
* }
|
|
37
|
+
* await stream.release();
|
|
38
|
+
* await engine.destroy();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createStreamingSTT(options: StreamingSttInitOptions): Promise<StreamingSttEngine>;
|
|
42
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../src/stt/streaming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EAGxB,MAAM,kBAAkB,CAAC;AAI1B;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,kBAAkB,CAmBpB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,kBAAkB,GAAG,IAAI,CAM3B;AAwED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8M7B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ModelPathConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Online (streaming) STT model types.
|
|
4
|
+
* These models use OnlineRecognizer + OnlineStream in sherpa-onnx.
|
|
5
|
+
* Must match the native OnlineRecognizer model config (transducer, paraformer, zipformer2_ctc, nemo_ctc, tone_ctc).
|
|
6
|
+
*/
|
|
7
|
+
export type OnlineSTTModelType = 'transducer' | 'paraformer' | 'zipformer2_ctc' | 'nemo_ctc' | 'tone_ctc';
|
|
8
|
+
/** Runtime list of supported online STT model types. */
|
|
9
|
+
export declare const ONLINE_STT_MODEL_TYPES: readonly OnlineSTTModelType[];
|
|
10
|
+
/**
|
|
11
|
+
* Single endpoint rule (Kotlin EndpointRule).
|
|
12
|
+
* Used to detect end of utterance in streaming recognition.
|
|
13
|
+
*/
|
|
14
|
+
export interface EndpointRule {
|
|
15
|
+
/** If true, rule only matches when the segment contains non-silence. */
|
|
16
|
+
mustContainNonSilence: boolean;
|
|
17
|
+
/** Minimum trailing silence in seconds. */
|
|
18
|
+
minTrailingSilence: number;
|
|
19
|
+
/** Minimum utterance length in seconds (e.g. max length cap). */
|
|
20
|
+
minUtteranceLength: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Endpoint detection config (Kotlin EndpointConfig).
|
|
24
|
+
* Three rules; first match determines end of utterance.
|
|
25
|
+
*/
|
|
26
|
+
export interface EndpointConfig {
|
|
27
|
+
/** Rule 1: e.g. 2.4s trailing silence, no speech required. */
|
|
28
|
+
rule1?: EndpointRule;
|
|
29
|
+
/** Rule 2: e.g. 1.4s trailing silence, speech required. */
|
|
30
|
+
rule2?: EndpointRule;
|
|
31
|
+
/** Rule 3: e.g. max utterance length 20s. */
|
|
32
|
+
rule3?: EndpointRule;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options for initializing the streaming (online) STT engine.
|
|
36
|
+
*/
|
|
37
|
+
export interface StreamingSttInitOptions {
|
|
38
|
+
/** Model path configuration (asset, file, or auto). */
|
|
39
|
+
modelPath: ModelPathConfig;
|
|
40
|
+
/** Online model type. Use 'auto' to detect from model directory (calls detectSttModel and maps to an online type). */
|
|
41
|
+
modelType: OnlineSTTModelType | 'auto';
|
|
42
|
+
/** Enable endpoint detection. Default: true. */
|
|
43
|
+
enableEndpoint?: boolean;
|
|
44
|
+
/** Endpoint rules. Defaults match Kotlin (rule1: 2.4s silence, rule2: 1.4s + speech, rule3: 20s max). */
|
|
45
|
+
endpointConfig?: EndpointConfig;
|
|
46
|
+
/** Decoding method. Default: "greedy_search". */
|
|
47
|
+
decodingMethod?: 'greedy_search' | 'modified_beam_search';
|
|
48
|
+
/** Max active paths for beam search. Default: 4. */
|
|
49
|
+
maxActivePaths?: number;
|
|
50
|
+
/** Path to hotwords file (transducer/nemo_transducer). */
|
|
51
|
+
hotwordsFile?: string;
|
|
52
|
+
/** Hotwords score. Default: 1.5. */
|
|
53
|
+
hotwordsScore?: number;
|
|
54
|
+
/** Number of threads for inference. Default: 1. */
|
|
55
|
+
numThreads?: number;
|
|
56
|
+
/** Execution provider (e.g. "cpu"). */
|
|
57
|
+
provider?: string;
|
|
58
|
+
/** Path(s) to rule FSTs for ITN. */
|
|
59
|
+
ruleFsts?: string;
|
|
60
|
+
/** Path(s) to rule FARs for ITN. */
|
|
61
|
+
ruleFars?: string;
|
|
62
|
+
/** Blank penalty. */
|
|
63
|
+
blankPenalty?: number;
|
|
64
|
+
/** Enable debug logging. Default: false. */
|
|
65
|
+
debug?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Enable adaptive input normalization for audio chunks in processAudioChunk().
|
|
68
|
+
* When true (default), input is scaled so the peak is ~0.8 to handle varying device levels (e.g. quiet mics on iOS).
|
|
69
|
+
* Set to false if your audio is already in the expected range [-1, 1] and you want to pass it through unchanged.
|
|
70
|
+
*/
|
|
71
|
+
enableInputNormalization?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Partial or final recognition result from streaming STT (maps to Kotlin OnlineRecognizerResult).
|
|
75
|
+
*/
|
|
76
|
+
export interface StreamingSttResult {
|
|
77
|
+
text: string;
|
|
78
|
+
tokens: string[];
|
|
79
|
+
timestamps: number[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Streaming STT stream. Created by StreamingSttEngine.createStream().
|
|
83
|
+
* Feeds audio via acceptWaveform, then decode / getResult / isEndpoint.
|
|
84
|
+
*/
|
|
85
|
+
export interface SttStream {
|
|
86
|
+
readonly streamId: string;
|
|
87
|
+
/** Feed PCM samples (float in [-1, 1]) to the stream. */
|
|
88
|
+
acceptWaveform(samples: number[], sampleRate: number): Promise<void>;
|
|
89
|
+
/** Signal that no more audio will be fed. */
|
|
90
|
+
inputFinished(): Promise<void>;
|
|
91
|
+
/** Run decoding on accumulated audio (call when isReady() is true). */
|
|
92
|
+
decode(): Promise<void>;
|
|
93
|
+
/** True if there is enough audio to decode. */
|
|
94
|
+
isReady(): Promise<boolean>;
|
|
95
|
+
/** Get current partial or final result. Call after decode(). */
|
|
96
|
+
getResult(): Promise<StreamingSttResult>;
|
|
97
|
+
/** True if endpoint (end of utterance) was detected. */
|
|
98
|
+
isEndpoint(): Promise<boolean>;
|
|
99
|
+
/** Reset stream state for reuse. */
|
|
100
|
+
reset(): Promise<void>;
|
|
101
|
+
/** Release native stream; do not use after this. */
|
|
102
|
+
release(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Convenience: feed audio, auto-decode while ready, return result and endpoint status.
|
|
105
|
+
* Reduces bridge round-trips from 5 to 1 per chunk.
|
|
106
|
+
*/
|
|
107
|
+
processAudioChunk(samples: number[], sampleRate: number): Promise<{
|
|
108
|
+
result: StreamingSttResult;
|
|
109
|
+
isEndpoint: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Streaming STT engine (OnlineRecognizer). Create via createStreamingSTT().
|
|
114
|
+
*/
|
|
115
|
+
export interface StreamingSttEngine {
|
|
116
|
+
readonly instanceId: string;
|
|
117
|
+
/** Create a new stream for this recognizer. Optional hotwords string. */
|
|
118
|
+
createStream(hotwords?: string): Promise<SttStream>;
|
|
119
|
+
/** Release native recognizer and all streams. */
|
|
120
|
+
destroy(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=streamingTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamingTypes.d.ts","sourceRoot":"","sources":["../../../../src/stt/streamingTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ,YAAY,GACZ,gBAAgB,GAChB,UAAU,GACV,UAAU,CAAC;AAEf,wDAAwD;AACxD,eAAO,MAAM,sBAAsB,EAAE,SAAS,kBAAkB,EAMtD,CAAC;AAEX;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC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
|
60
60
|
* Share a TTS audio file (file path or content URI).
|
|
61
61
|
*/
|
|
62
62
|
export declare function shareAudioFile(fileUri: string, mimeType?: string): Promise<void>;
|
|
63
|
-
export
|
|
63
|
+
export { createStreamingTTS } from './streaming';
|
|
64
|
+
export type { StreamingTtsEngine } from './streamingTypes';
|
|
65
|
+
export type { TTSInitializeOptions, TTSModelType, TtsModelOptions, TtsVitsModelOptions, TtsMatchaModelOptions, TtsKokoroModelOptions, TtsKittenModelOptions, TtsPocketModelOptions, TtsUpdateOptions, TtsGenerationOptions, GeneratedAudio, GeneratedAudioWithTimestamps, TtsSubtitleItem, TTSModelInfo, TtsEngine, TtsStreamController, TtsStreamHandlers, TtsStreamChunk, TtsStreamEnd, TtsStreamError, } from './types';
|
|
64
66
|
export { TTS_MODEL_TYPES } from './types';
|
|
65
67
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tts/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EAIZ,cAAc,EAGd,SAAS,EACV,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAqEhD;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,YAAY,CAAA;CAAE,GACrC,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAGD;AA6BD;;;;;;;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 +1,24 @@
|
|
|
1
|
+
import type { TTSInitializeOptions } from './types';
|
|
2
|
+
import type { StreamingTtsEngine } from './streamingTypes';
|
|
3
|
+
import type { ModelPathConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Create a streaming TTS engine instance. Use for incremental generation with
|
|
6
|
+
* chunk callbacks and PCM playback. Call destroy() when done.
|
|
7
|
+
*
|
|
8
|
+
* @param options - TTS initialization options or model path configuration
|
|
9
|
+
* @returns Promise resolving to a StreamingTtsEngine instance
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const tts = await createStreamingTTS({
|
|
13
|
+
* modelPath: { type: 'asset', path: 'models/vits-piper-en' },
|
|
14
|
+
* modelType: 'vits',
|
|
15
|
+
* });
|
|
16
|
+
* const controller = await tts.generateSpeechStream('Hello', undefined, {
|
|
17
|
+
* onChunk: (chunk) => playPcm(chunk.samples, chunk.sampleRate),
|
|
18
|
+
* onEnd: () => {},
|
|
19
|
+
* });
|
|
20
|
+
* await tts.destroy();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createStreamingTTS(options: TTSInitializeOptions | ModelPathConfig): Promise<StreamingTtsEngine>;
|
|
24
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../src/tts/streaming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EAUrB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAwFhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,GAAG,eAAe,GAC9C,OAAO,CAAC,kBAAkB,CAAC,CAmN7B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TtsStreamHandlers, TtsStreamController, TtsGenerationOptions, TTSModelInfo } from './types';
|
|
2
|
+
export type { TtsStreamChunk, TtsStreamEnd, TtsStreamError, TtsStreamHandlers, TtsStreamController, TtsGenerationOptions, TTSModelInfo, } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Streaming-only TTS engine returned by createStreamingTTS().
|
|
5
|
+
* Use for incremental generation with chunk callbacks and PCM playback.
|
|
6
|
+
* Call destroy() when done to free native resources.
|
|
7
|
+
*/
|
|
8
|
+
export interface StreamingTtsEngine {
|
|
9
|
+
readonly instanceId: string;
|
|
10
|
+
/** Generate speech in streaming mode; audio delivered via handlers. */
|
|
11
|
+
generateSpeechStream(text: string, options: TtsGenerationOptions | undefined, handlers: TtsStreamHandlers): Promise<TtsStreamController>;
|
|
12
|
+
/** Cancel the current streaming generation. */
|
|
13
|
+
cancelSpeechStream(): Promise<void>;
|
|
14
|
+
/** Start built-in PCM playback (e.g. for play-while-generating). */
|
|
15
|
+
startPcmPlayer(sampleRate: number, channels: number): Promise<void>;
|
|
16
|
+
/** Write float PCM samples to the player. Use from onChunk. */
|
|
17
|
+
writePcmChunk(samples: number[]): Promise<void>;
|
|
18
|
+
/** Stop and release the PCM player. */
|
|
19
|
+
stopPcmPlayer(): Promise<void>;
|
|
20
|
+
/** Model sample rate and number of speakers. */
|
|
21
|
+
getModelInfo(): Promise<TTSModelInfo>;
|
|
22
|
+
getSampleRate(): Promise<number>;
|
|
23
|
+
getNumSpeakers(): Promise<number>;
|
|
24
|
+
/** Release native TTS resources. Do not use the engine after this. */
|
|
25
|
+
destroy(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=streamingTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamingTypes.d.ts","sourceRoot":"","sources":["../../../../src/tts/streamingTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,uEAAuE;IACvE,oBAAoB,CAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEhC,+CAA+C;IAC/C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC,oEAAoE;IACpE,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE,+DAA+D;IAC/D,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD,uCAAuC;IACvC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/B,gDAAgD;IAChD,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAElC,sEAAsE;IACtE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
|
@@ -239,6 +239,8 @@ export interface GeneratedAudioWithTimestamps extends GeneratedAudio {
|
|
|
239
239
|
export interface TtsStreamChunk {
|
|
240
240
|
/** Instance ID (set by native for multi-instance routing). */
|
|
241
241
|
instanceId?: string;
|
|
242
|
+
/** Request ID for this generation (distinguishes concurrent streams on same instance). */
|
|
243
|
+
requestId?: string;
|
|
242
244
|
samples: number[];
|
|
243
245
|
sampleRate: number;
|
|
244
246
|
progress: number;
|
|
@@ -250,6 +252,8 @@ export interface TtsStreamChunk {
|
|
|
250
252
|
export interface TtsStreamEnd {
|
|
251
253
|
/** Instance ID (set by native for multi-instance routing). */
|
|
252
254
|
instanceId?: string;
|
|
255
|
+
/** Request ID for this generation. */
|
|
256
|
+
requestId?: string;
|
|
253
257
|
cancelled: boolean;
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
@@ -258,8 +262,20 @@ export interface TtsStreamEnd {
|
|
|
258
262
|
export interface TtsStreamError {
|
|
259
263
|
/** Instance ID (set by native for multi-instance routing). */
|
|
260
264
|
instanceId?: string;
|
|
265
|
+
/** Request ID for this generation. */
|
|
266
|
+
requestId?: string;
|
|
261
267
|
message: string;
|
|
262
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Controller returned by generateSpeechStream().
|
|
271
|
+
* Use cancel() to stop generation, unsubscribe() to remove event listeners.
|
|
272
|
+
*/
|
|
273
|
+
export interface TtsStreamController {
|
|
274
|
+
/** Cancel the ongoing TTS generation. */
|
|
275
|
+
cancel(): Promise<void>;
|
|
276
|
+
/** Remove event listeners (called automatically on end/error, or manually). */
|
|
277
|
+
unsubscribe(): void;
|
|
278
|
+
}
|
|
263
279
|
/**
|
|
264
280
|
* Handlers for TTS streaming generation (chunk, end, error).
|
|
265
281
|
*/
|
|
@@ -269,18 +285,15 @@ export interface TtsStreamHandlers {
|
|
|
269
285
|
onError?: (event: TtsStreamError) => void;
|
|
270
286
|
}
|
|
271
287
|
/**
|
|
272
|
-
* Instance-based TTS engine returned by createTTS().
|
|
288
|
+
* Instance-based batch TTS engine returned by createTTS().
|
|
289
|
+
* Use for one-shot synthesis (generateSpeech, generateSpeechWithTimestamps).
|
|
290
|
+
* For streaming, use createStreamingTTS() and StreamingTtsEngine instead.
|
|
273
291
|
* Call destroy() when done to free native resources.
|
|
274
292
|
*/
|
|
275
293
|
export interface TtsEngine {
|
|
276
294
|
readonly instanceId: string;
|
|
277
295
|
generateSpeech(text: string, options?: TtsGenerationOptions): Promise<GeneratedAudio>;
|
|
278
296
|
generateSpeechWithTimestamps(text: string, options?: TtsGenerationOptions): Promise<GeneratedAudioWithTimestamps>;
|
|
279
|
-
generateSpeechStream(text: string, options: TtsGenerationOptions | undefined, handlers: TtsStreamHandlers): Promise<() => void>;
|
|
280
|
-
cancelSpeechStream(): Promise<void>;
|
|
281
|
-
startPcmPlayer(sampleRate: number, channels: number): Promise<void>;
|
|
282
|
-
writePcmChunk(samples: number[]): Promise<void>;
|
|
283
|
-
stopPcmPlayer(): Promise<void>;
|
|
284
297
|
updateParams(options: TtsUpdateOptions): Promise<{
|
|
285
298
|
success: boolean;
|
|
286
299
|
detectedModels: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/tts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,MAAM,CAAC;AAEX,iDAAiD;AACjD,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAQzC,CAAC;AAIX,wGAAwG;AACxG,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8GAA8G;AAC9G,MAAM,WAAW,qBAAqB;IACpC,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8GAA8G;AAC9G,MAAM,WAAW,qBAAqB;IACpC,uDAAuD;IACvD,WAAW,CAAC,E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,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-sherpa-onnx",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Offline Speech-to-text, text-to-speech, speaker diarization, speech enhancement, source separation, and VAD with sherpa-onnx for React NativeSpeech-to-Text with sherpa-onnx for React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -185,7 +185,6 @@
|
|
|
185
185
|
"name": "SherpaOnnxSpec",
|
|
186
186
|
"type": "modules",
|
|
187
187
|
"jsSrcsDir": "src",
|
|
188
|
-
"includesGeneratedCode": false,
|
|
189
188
|
"android": {
|
|
190
189
|
"javaPackageName": "com.sherpaonnx"
|
|
191
190
|
}
|
package/src/NativeSherpaOnnx.ts
CHANGED
|
@@ -120,6 +120,97 @@ export interface Spec extends TurboModule {
|
|
|
120
120
|
*/
|
|
121
121
|
unloadStt(instanceId: string): Promise<void>;
|
|
122
122
|
|
|
123
|
+
// ==================== Online (streaming) STT Methods ====================
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Initialize OnlineRecognizer for streaming STT (single options object to avoid iOS TurboModule marshalling crash with many args).
|
|
127
|
+
* @param instanceId - Unique ID for this engine instance (from createStreamingSTT)
|
|
128
|
+
* @param options - All init options (modelDir, modelType, enableEndpoint, decodingMethod, maxActivePaths, and optional endpoint/rule params)
|
|
129
|
+
*/
|
|
130
|
+
initializeOnlineSttWithOptions(
|
|
131
|
+
instanceId: string,
|
|
132
|
+
options: {
|
|
133
|
+
modelDir: string;
|
|
134
|
+
modelType: string;
|
|
135
|
+
enableEndpoint?: boolean;
|
|
136
|
+
decodingMethod?: string;
|
|
137
|
+
maxActivePaths?: number;
|
|
138
|
+
hotwordsFile?: string;
|
|
139
|
+
hotwordsScore?: number;
|
|
140
|
+
numThreads?: number;
|
|
141
|
+
provider?: string;
|
|
142
|
+
ruleFsts?: string;
|
|
143
|
+
ruleFars?: string;
|
|
144
|
+
blankPenalty?: number;
|
|
145
|
+
debug?: boolean;
|
|
146
|
+
rule1MustContainNonSilence?: boolean;
|
|
147
|
+
rule1MinTrailingSilence?: number;
|
|
148
|
+
rule1MinUtteranceLength?: number;
|
|
149
|
+
rule2MustContainNonSilence?: boolean;
|
|
150
|
+
rule2MinTrailingSilence?: number;
|
|
151
|
+
rule2MinUtteranceLength?: number;
|
|
152
|
+
rule3MustContainNonSilence?: boolean;
|
|
153
|
+
rule3MinTrailingSilence?: number;
|
|
154
|
+
rule3MinUtteranceLength?: number;
|
|
155
|
+
}
|
|
156
|
+
): Promise<{ success: boolean }>;
|
|
157
|
+
|
|
158
|
+
/** Create a new stream for the given OnlineRecognizer instance. */
|
|
159
|
+
createSttStream(
|
|
160
|
+
instanceId: string,
|
|
161
|
+
streamId: string,
|
|
162
|
+
hotwords?: string
|
|
163
|
+
): Promise<void>;
|
|
164
|
+
|
|
165
|
+
/** Feed PCM samples to a streaming STT stream. */
|
|
166
|
+
acceptSttWaveform(
|
|
167
|
+
streamId: string,
|
|
168
|
+
samples: number[],
|
|
169
|
+
sampleRate: number
|
|
170
|
+
): Promise<void>;
|
|
171
|
+
|
|
172
|
+
/** Signal end of input for a streaming STT stream. */
|
|
173
|
+
sttStreamInputFinished(streamId: string): Promise<void>;
|
|
174
|
+
|
|
175
|
+
/** Run decoding on the stream (call when isSttStreamReady is true). */
|
|
176
|
+
decodeSttStream(streamId: string): Promise<void>;
|
|
177
|
+
|
|
178
|
+
/** True if the stream has enough audio to decode. */
|
|
179
|
+
isSttStreamReady(streamId: string): Promise<boolean>;
|
|
180
|
+
|
|
181
|
+
/** Get current partial or final result (call after decodeSttStream). */
|
|
182
|
+
getSttStreamResult(streamId: string): Promise<{
|
|
183
|
+
text: string;
|
|
184
|
+
tokens: string[];
|
|
185
|
+
timestamps: number[];
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
/** True if endpoint (end of utterance) was detected. */
|
|
189
|
+
isSttStreamEndpoint(streamId: string): Promise<boolean>;
|
|
190
|
+
|
|
191
|
+
/** Reset stream state for reuse. */
|
|
192
|
+
resetSttStream(streamId: string): Promise<void>;
|
|
193
|
+
|
|
194
|
+
/** Release stream and remove from native state. */
|
|
195
|
+
releaseSttStream(streamId: string): Promise<void>;
|
|
196
|
+
|
|
197
|
+
/** Release OnlineRecognizer and all its streams. */
|
|
198
|
+
unloadOnlineStt(instanceId: string): Promise<void>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Convenience: feed audio, decode while ready, return result and endpoint status in one call.
|
|
202
|
+
*/
|
|
203
|
+
processSttAudioChunk(
|
|
204
|
+
streamId: string,
|
|
205
|
+
samples: number[],
|
|
206
|
+
sampleRate: number
|
|
207
|
+
): Promise<{
|
|
208
|
+
text: string;
|
|
209
|
+
tokens: string[];
|
|
210
|
+
timestamps: number[];
|
|
211
|
+
isEndpoint: boolean;
|
|
212
|
+
}>;
|
|
213
|
+
|
|
123
214
|
// ==================== TTS Methods ====================
|
|
124
215
|
|
|
125
216
|
/**
|
|
@@ -230,14 +321,18 @@ export interface Spec extends TurboModule {
|
|
|
230
321
|
estimated: boolean;
|
|
231
322
|
}>;
|
|
232
323
|
|
|
324
|
+
// ==================== Online (streaming) TTS Methods ====================
|
|
325
|
+
|
|
233
326
|
/**
|
|
234
327
|
* Generate speech in streaming mode (emits chunk events).
|
|
235
328
|
* @param instanceId - Unique ID for this engine instance
|
|
329
|
+
* @param requestId - Unique ID for this generation (included in chunk/end/error events for routing)
|
|
236
330
|
* @param text - Text to convert to speech
|
|
237
331
|
* @param options - Generation options (sid, speed, referenceAudio, referenceText, numSteps, silenceScale, extra)
|
|
238
332
|
*/
|
|
239
333
|
generateTtsStream(
|
|
240
334
|
instanceId: string,
|
|
335
|
+
requestId: string,
|
|
241
336
|
text: string,
|
|
242
337
|
options: Object
|
|
243
338
|
): Promise<void>;
|
package/src/index.tsx
CHANGED
|
@@ -17,8 +17,8 @@ export {
|
|
|
17
17
|
} from './utils';
|
|
18
18
|
|
|
19
19
|
// Note: Feature-specific exports are available via subpath imports:
|
|
20
|
-
// - import { ... } from 'react-native-sherpa-onnx/stt'
|
|
21
|
-
// - import { ... } from 'react-native-sherpa-onnx/tts'
|
|
20
|
+
// - import { createSTT, createStreamingSTT, ... } from 'react-native-sherpa-onnx/stt'
|
|
21
|
+
// - import { createTTS, ... } from 'react-native-sherpa-onnx/tts'
|
|
22
22
|
// - import { ... } from 'react-native-sherpa-onnx/download'
|
|
23
23
|
// - import { ... } from 'react-native-sherpa-onnx/vad' (planned)
|
|
24
24
|
// - import { ... } from 'react-native-sherpa-onnx/diarization' (planned)
|
package/src/stt/index.ts
CHANGED
|
@@ -219,6 +219,23 @@ export async function createSTT(
|
|
|
219
219
|
return engine;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
// Streaming (online) STT
|
|
223
|
+
export {
|
|
224
|
+
createStreamingSTT,
|
|
225
|
+
mapDetectedToOnlineType,
|
|
226
|
+
getOnlineTypeOrNull,
|
|
227
|
+
} from './streaming';
|
|
228
|
+
export type {
|
|
229
|
+
OnlineSTTModelType,
|
|
230
|
+
StreamingSttEngine,
|
|
231
|
+
StreamingSttInitOptions,
|
|
232
|
+
StreamingSttResult,
|
|
233
|
+
SttStream,
|
|
234
|
+
EndpointConfig,
|
|
235
|
+
EndpointRule,
|
|
236
|
+
} from './streamingTypes';
|
|
237
|
+
export { ONLINE_STT_MODEL_TYPES } from './streamingTypes';
|
|
238
|
+
|
|
222
239
|
// Export types and runtime type list
|
|
223
240
|
export type {
|
|
224
241
|
STTInitializeOptions,
|