react-native-sherpa-onnx 0.1.0
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/LICENSE +20 -0
- package/README.md +402 -0
- package/SherpaOnnx.podspec +84 -0
- package/android/build.gradle +193 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/CMakeLists.txt +121 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +1918 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +841 -0
- package/android/src/main/cpp/jni/sherpa-onnx-jni.cpp +129 -0
- package/android/src/main/cpp/jni/sherpa-onnx-wrapper.cpp +649 -0
- package/android/src/main/cpp/jni/sherpa-onnx-wrapper.h +56 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +316 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxPackage.kt +33 -0
- package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
- package/ios/SherpaOnnx.h +5 -0
- package/ios/SherpaOnnx.mm +293 -0
- package/ios/SherpaOnnx.xcconfig +19 -0
- package/ios/include/sherpa-onnx/c-api/c-api.h +1918 -0
- package/ios/include/sherpa-onnx/c-api/cxx-api.h +841 -0
- package/ios/sherpa-onnx-wrapper.h +57 -0
- package/ios/sherpa-onnx-wrapper.mm +432 -0
- package/lib/module/NativeSherpaOnnx.js +5 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -0
- package/lib/module/diarization/index.js +54 -0
- package/lib/module/diarization/index.js.map +1 -0
- package/lib/module/enhancement/index.js +54 -0
- package/lib/module/enhancement/index.js.map +1 -0
- package/lib/module/index.js +25 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/separation/index.js +54 -0
- package/lib/module/separation/index.js.map +1 -0
- package/lib/module/stt/index.js +79 -0
- package/lib/module/stt/index.js.map +1 -0
- package/lib/module/stt/types.js +4 -0
- package/lib/module/stt/types.js.map +1 -0
- package/lib/module/tts/index.js +54 -0
- package/lib/module/tts/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +93 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/module/vad/index.js +54 -0
- package/lib/module/vad/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +39 -0
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -0
- package/lib/typescript/src/diarization/index.d.ts +49 -0
- package/lib/typescript/src/diarization/index.d.ts.map +1 -0
- package/lib/typescript/src/enhancement/index.d.ts +47 -0
- package/lib/typescript/src/enhancement/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/separation/index.d.ts +48 -0
- package/lib/typescript/src/separation/index.d.ts.map +1 -0
- package/lib/typescript/src/stt/index.d.ts +53 -0
- package/lib/typescript/src/stt/index.d.ts.map +1 -0
- package/lib/typescript/src/stt/types.d.ts +39 -0
- package/lib/typescript/src/stt/types.d.ts.map +1 -0
- package/lib/typescript/src/tts/index.d.ts +47 -0
- package/lib/typescript/src/tts/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +59 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +53 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/vad/index.d.ts +48 -0
- package/lib/typescript/src/vad/index.d.ts.map +1 -0
- package/package.json +221 -0
- package/scripts/copy-headers.js +184 -0
- package/scripts/setup-assets.js +323 -0
- package/scripts/setup-ios-framework.sh +282 -0
- package/scripts/switch-registry.js +75 -0
- package/src/NativeSherpaOnnx.ts +44 -0
- package/src/diarization/index.ts +69 -0
- package/src/enhancement/index.ts +67 -0
- package/src/index.tsx +30 -0
- package/src/separation/index.ts +68 -0
- package/src/stt/index.ts +83 -0
- package/src/stt/types.ts +42 -0
- package/src/tts/index.ts +67 -0
- package/src/types.ts +73 -0
- package/src/utils.ts +97 -0
- package/src/vad/index.ts +70 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { InitializeOptions, ModelType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* STT-specific initialization options
|
|
4
|
+
*/
|
|
5
|
+
export interface STTInitializeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Model directory path configuration
|
|
8
|
+
*/
|
|
9
|
+
modelPath: InitializeOptions['modelPath'];
|
|
10
|
+
/**
|
|
11
|
+
* Model quantization preference
|
|
12
|
+
* - true: Prefer int8 quantized models (model.int8.onnx) - smaller, faster
|
|
13
|
+
* - false: Prefer regular models (model.onnx) - higher accuracy
|
|
14
|
+
* - undefined: Try int8 first, then fall back to regular (default behavior)
|
|
15
|
+
*/
|
|
16
|
+
preferInt8?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Explicit model type specification for STT models
|
|
19
|
+
* - 'transducer': Force detection as Zipformer/Transducer model
|
|
20
|
+
* - 'paraformer': Force detection as Paraformer model
|
|
21
|
+
* - 'nemo_ctc': Force detection as NeMo CTC model
|
|
22
|
+
* - 'whisper': Force detection as Whisper model
|
|
23
|
+
* - 'wenet_ctc': Force detection as WeNet CTC model
|
|
24
|
+
* - 'sense_voice': Force detection as SenseVoice model
|
|
25
|
+
* - 'funasr_nano': Force detection as FunASR Nano model
|
|
26
|
+
* - 'auto': Automatic detection based on files (default)
|
|
27
|
+
*/
|
|
28
|
+
modelType?: ModelType;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Transcription result
|
|
32
|
+
*/
|
|
33
|
+
export interface TranscriptionResult {
|
|
34
|
+
/**
|
|
35
|
+
* Transcribed text
|
|
36
|
+
*/
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/stt/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAE1C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-to-Speech (TTS) feature module
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This feature is not yet implemented. This module serves as a placeholder
|
|
6
|
+
* for future TTS functionality.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Future usage:
|
|
11
|
+
* import { initializeTTS, synthesizeText } from 'react-native-sherpa-onnx/tts';
|
|
12
|
+
*
|
|
13
|
+
* await initializeTTS({ modelPath: 'models/tts-model' });
|
|
14
|
+
* const audioPath = await synthesizeText('Hello, world!');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* TTS initialization options (placeholder)
|
|
19
|
+
*/
|
|
20
|
+
export interface TTSInitializeOptions {
|
|
21
|
+
modelPath: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TTS synthesis result (placeholder)
|
|
25
|
+
*/
|
|
26
|
+
export interface SynthesisResult {
|
|
27
|
+
audioPath: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize Text-to-Speech (TTS) with model directory.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} Not yet implemented
|
|
33
|
+
*/
|
|
34
|
+
export declare function initializeTTS(_options: TTSInitializeOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Synthesize text to speech audio.
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} Not yet implemented
|
|
39
|
+
*/
|
|
40
|
+
export declare function synthesizeText(_text: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Release TTS resources.
|
|
43
|
+
*
|
|
44
|
+
* @throws {Error} Not yet implemented
|
|
45
|
+
*/
|
|
46
|
+
export declare function unloadTTS(): Promise<void>;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;CAEnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;CAEnB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI7D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAIzC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model path configuration options
|
|
3
|
+
*/
|
|
4
|
+
export type ModelPathConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Path type: 'asset' - Model is bundled in app assets
|
|
7
|
+
* On iOS: Bundle path (e.g., "models/sherpa-onnx-model")
|
|
8
|
+
* On Android: Asset path (e.g., "models/sherpa-onnx-model")
|
|
9
|
+
*/
|
|
10
|
+
type: 'asset';
|
|
11
|
+
path: string;
|
|
12
|
+
} | {
|
|
13
|
+
/**
|
|
14
|
+
* Path type: 'file' - Model is in file system
|
|
15
|
+
* Absolute path to model directory
|
|
16
|
+
*/
|
|
17
|
+
type: 'file';
|
|
18
|
+
path: string;
|
|
19
|
+
} | {
|
|
20
|
+
/**
|
|
21
|
+
* Path type: 'auto' - Automatically detect path type
|
|
22
|
+
* Tries asset first, then file system
|
|
23
|
+
*/
|
|
24
|
+
type: 'auto';
|
|
25
|
+
path: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Model type for explicit model detection
|
|
29
|
+
*/
|
|
30
|
+
export type ModelType = 'transducer' | 'paraformer' | 'nemo_ctc' | 'whisper' | 'wenet_ctc' | 'sense_voice' | 'funasr_nano' | 'auto';
|
|
31
|
+
/**
|
|
32
|
+
* Model initialization options
|
|
33
|
+
*/
|
|
34
|
+
export interface InitializeOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Model directory path configuration
|
|
37
|
+
*/
|
|
38
|
+
modelPath: ModelPathConfig | string;
|
|
39
|
+
/**
|
|
40
|
+
* Model quantization preference
|
|
41
|
+
* - true: Prefer int8 quantized models (model.int8.onnx) - smaller, faster
|
|
42
|
+
* - false: Prefer regular models (model.onnx) - higher accuracy
|
|
43
|
+
* - undefined: Try int8 first, then fall back to regular (default behavior)
|
|
44
|
+
*/
|
|
45
|
+
preferInt8?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Explicit model type specification
|
|
48
|
+
* - 'transducer': Force detection as Zipformer/Transducer model
|
|
49
|
+
* - 'paraformer': Force detection as Paraformer model
|
|
50
|
+
* - 'nemo_ctc': Force detection as NeMo CTC model
|
|
51
|
+
* - 'whisper': Force detection as Whisper model
|
|
52
|
+
* - 'wenet_ctc': Force detection as WeNet CTC model
|
|
53
|
+
* - 'sense_voice': Force detection as SenseVoice model
|
|
54
|
+
* - 'funasr_nano': Force detection as FunASR Nano model
|
|
55
|
+
* - 'auto': Automatic detection based on files (default)
|
|
56
|
+
*/
|
|
57
|
+
modelType?: ModelType;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB;IACE;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,SAAS,GACT,WAAW,GACX,aAAa,GACb,aAAa,GACb,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,EAAE,eAAe,GAAG,MAAM,CAAC;IAEpC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ModelPathConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for model path handling
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Predefined model identifiers
|
|
7
|
+
*/
|
|
8
|
+
export declare const MODELS: {
|
|
9
|
+
readonly ZIPFORMER_EN: "sherpa-onnx-zipformer-small-en";
|
|
10
|
+
readonly PARAFORMER_ZH: "sherpa-onnx-paraformer-zh-small";
|
|
11
|
+
};
|
|
12
|
+
export type ModelId = (typeof MODELS)[keyof typeof MODELS];
|
|
13
|
+
/**
|
|
14
|
+
* Get the default model directory path for the current platform.
|
|
15
|
+
* This is a helper for apps that want to use a standard location.
|
|
16
|
+
*
|
|
17
|
+
* @returns Platform-specific default path
|
|
18
|
+
*/
|
|
19
|
+
export declare function getDefaultModelPath(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Create a model path configuration for asset models.
|
|
22
|
+
* Use this when models are bundled in your app's assets.
|
|
23
|
+
*
|
|
24
|
+
* @param assetPath - Path relative to assets (e.g., "models/sherpa-onnx-model")
|
|
25
|
+
* @returns Model path configuration
|
|
26
|
+
*/
|
|
27
|
+
export declare function assetModelPath(assetPath: string): ModelPathConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Create a model path configuration for file system models.
|
|
30
|
+
* Use this when models are downloaded or stored in file system.
|
|
31
|
+
*
|
|
32
|
+
* @param filePath - Absolute path to model directory
|
|
33
|
+
* @returns Model path configuration
|
|
34
|
+
*/
|
|
35
|
+
export declare function fileModelPath(filePath: string): ModelPathConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Create a model path configuration with auto-detection.
|
|
38
|
+
* Tries asset first, then file system.
|
|
39
|
+
*
|
|
40
|
+
* @param path - Path to try (will be checked as both asset and file)
|
|
41
|
+
* @returns Model path configuration
|
|
42
|
+
*/
|
|
43
|
+
export declare function autoModelPath(path: string): ModelPathConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve model path based on configuration.
|
|
46
|
+
* This handles different path types (asset, file, auto) and returns
|
|
47
|
+
* a platform-specific absolute path that can be used by native code.
|
|
48
|
+
*
|
|
49
|
+
* @param config - Model path configuration or simple string path
|
|
50
|
+
* @returns Promise resolving to absolute path usable by native code
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveModelPath(config: ModelPathConfig | string): Promise<string>;
|
|
53
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAEX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAQ5C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAKjE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAK/D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAK3D;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,eAAe,GAAG,MAAM,GAC/B,OAAO,CAAC,MAAM,CAAC,CAUjB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice Activity Detection (VAD) feature module
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This feature is not yet implemented. This module serves as a placeholder
|
|
6
|
+
* for future VAD functionality.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Future usage:
|
|
11
|
+
* import { initializeVAD, detectVoiceActivity } from 'react-native-sherpa-onnx/vad';
|
|
12
|
+
*
|
|
13
|
+
* await initializeVAD({ modelPath: 'models/vad-model' });
|
|
14
|
+
* const segments = await detectVoiceActivity('path/to/audio.wav');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* VAD initialization options (placeholder)
|
|
19
|
+
*/
|
|
20
|
+
export interface VADInitializeOptions {
|
|
21
|
+
modelPath: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Voice activity segment
|
|
25
|
+
*/
|
|
26
|
+
export interface VoiceSegment {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize Voice Activity Detection (VAD) with model directory.
|
|
32
|
+
*
|
|
33
|
+
* @throws {Error} Not yet implemented
|
|
34
|
+
*/
|
|
35
|
+
export declare function initializeVAD(_options: VADInitializeOptions): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Detect voice activity in an audio file.
|
|
38
|
+
*
|
|
39
|
+
* @throws {Error} Not yet implemented
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectVoiceActivity(_filePath: string): Promise<VoiceSegment[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Release VAD resources.
|
|
44
|
+
*
|
|
45
|
+
* @throws {Error} Not yet implemented
|
|
46
|
+
*/
|
|
47
|
+
export declare function unloadVAD(): Promise<void>;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vad/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;CAEnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CAEb;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,EAAE,CAAC,CAIzB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAIzC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-sherpa-onnx",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./stt": {
|
|
14
|
+
"source": "./src/stt/index.ts",
|
|
15
|
+
"types": "./lib/typescript/src/stt/index.d.ts",
|
|
16
|
+
"default": "./lib/module/stt/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./tts": {
|
|
19
|
+
"source": "./src/tts/index.ts",
|
|
20
|
+
"types": "./lib/typescript/src/tts/index.d.ts",
|
|
21
|
+
"default": "./lib/module/tts/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./vad": {
|
|
24
|
+
"source": "./src/vad/index.ts",
|
|
25
|
+
"types": "./lib/typescript/src/vad/index.d.ts",
|
|
26
|
+
"default": "./lib/module/vad/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./diarization": {
|
|
29
|
+
"source": "./src/diarization/index.ts",
|
|
30
|
+
"types": "./lib/typescript/src/diarization/index.d.ts",
|
|
31
|
+
"default": "./lib/module/diarization/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./enhancement": {
|
|
34
|
+
"source": "./src/enhancement/index.ts",
|
|
35
|
+
"types": "./lib/typescript/src/enhancement/index.d.ts",
|
|
36
|
+
"default": "./lib/module/enhancement/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./separation": {
|
|
39
|
+
"source": "./src/separation/index.ts",
|
|
40
|
+
"types": "./lib/typescript/src/separation/index.d.ts",
|
|
41
|
+
"default": "./lib/module/separation/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"src",
|
|
47
|
+
"lib",
|
|
48
|
+
"android",
|
|
49
|
+
"ios",
|
|
50
|
+
"scripts/**",
|
|
51
|
+
"scripts/**/*",
|
|
52
|
+
"cpp",
|
|
53
|
+
"*.podspec",
|
|
54
|
+
"react-native.config.js",
|
|
55
|
+
"!ios/build",
|
|
56
|
+
"!android/build",
|
|
57
|
+
"!android/gradle",
|
|
58
|
+
"!android/gradlew",
|
|
59
|
+
"!android/gradlew.bat",
|
|
60
|
+
"!android/local.properties",
|
|
61
|
+
"!**/__tests__",
|
|
62
|
+
"!**/__fixtures__",
|
|
63
|
+
"!**/__mocks__",
|
|
64
|
+
"!**/.*",
|
|
65
|
+
"!./sherpa-onnx",
|
|
66
|
+
"!./sherpa-onnx/**",
|
|
67
|
+
"!ios/Frameworks/.gitkeep"
|
|
68
|
+
],
|
|
69
|
+
"scripts": {
|
|
70
|
+
"example": "yarn workspace react-native-sherpa-onnx-example",
|
|
71
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
72
|
+
"copy-headers": "node scripts/copy-headers.js",
|
|
73
|
+
"download-ios-framework": "bash scripts/setup-ios-framework.sh",
|
|
74
|
+
"setup-assets": "node scripts/setup-assets.js",
|
|
75
|
+
"postinstall": "node scripts/setup-assets.js",
|
|
76
|
+
"prepublishOnly": "yarn copy-headers",
|
|
77
|
+
"prepack": "yarn copy-headers",
|
|
78
|
+
"prepare": "bob build",
|
|
79
|
+
"typecheck": "tsc",
|
|
80
|
+
"lint": "eslint --ignore-pattern \"sherpa-onnx/**\" \"**/*.{js,ts,tsx}\"",
|
|
81
|
+
"prettier": "npx prettier --write \"**/*.{js,ts,tsx}\"",
|
|
82
|
+
"test": "jest",
|
|
83
|
+
"verdaccio:start": "VERDACCIO_BODY_SIZE_LIMIT=100mb verdaccio --config verdaccio.config.yaml",
|
|
84
|
+
"registry:local": "node scripts/switch-registry.js local",
|
|
85
|
+
"registry:public": "node scripts/switch-registry.js public",
|
|
86
|
+
"release": "release-it --only-version"
|
|
87
|
+
},
|
|
88
|
+
"keywords": [
|
|
89
|
+
"react-native",
|
|
90
|
+
"ios",
|
|
91
|
+
"android"
|
|
92
|
+
],
|
|
93
|
+
"repository": {
|
|
94
|
+
"type": "git",
|
|
95
|
+
"url": "git+https://github.com/XDcobra/react-native-sherpa-onnx.git"
|
|
96
|
+
},
|
|
97
|
+
"author": "XDcobra <xdcobra11@gmail.com> (https://github.com/XDcobra)",
|
|
98
|
+
"license": "MIT",
|
|
99
|
+
"bugs": {
|
|
100
|
+
"url": "https://github.com/XDcobra/react-native-sherpa-onnx/issues"
|
|
101
|
+
},
|
|
102
|
+
"homepage": "https://github.com/XDcobra/react-native-sherpa-onnx#readme",
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"registry": "https://registry.npmjs.org/"
|
|
105
|
+
},
|
|
106
|
+
"devDependencies": {
|
|
107
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
108
|
+
"@eslint/compat": "^1.3.2",
|
|
109
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
110
|
+
"@eslint/js": "^9.35.0",
|
|
111
|
+
"@react-native/babel-preset": "0.83.0",
|
|
112
|
+
"@react-native/eslint-config": "0.83.0",
|
|
113
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
114
|
+
"@types/jest": "^29.5.14",
|
|
115
|
+
"@types/react": "^19.2.0",
|
|
116
|
+
"commitlint": "^19.8.1",
|
|
117
|
+
"del-cli": "^6.0.0",
|
|
118
|
+
"eslint": "^9.35.0",
|
|
119
|
+
"eslint-config-prettier": "^10.1.8",
|
|
120
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
121
|
+
"jest": "^29.7.0",
|
|
122
|
+
"lefthook": "^2.0.3",
|
|
123
|
+
"prettier": "^2.8.8",
|
|
124
|
+
"react": "19.2.0",
|
|
125
|
+
"react-native": "0.83.0",
|
|
126
|
+
"react-native-builder-bob": "^0.40.13",
|
|
127
|
+
"release-it": "^19.0.4",
|
|
128
|
+
"turbo": "^2.5.6",
|
|
129
|
+
"typescript": "^5.9.2"
|
|
130
|
+
},
|
|
131
|
+
"peerDependencies": {
|
|
132
|
+
"react": "*",
|
|
133
|
+
"react-native": "*"
|
|
134
|
+
},
|
|
135
|
+
"workspaces": [
|
|
136
|
+
"example"
|
|
137
|
+
],
|
|
138
|
+
"packageManager": "yarn@4.11.0",
|
|
139
|
+
"react-native-builder-bob": {
|
|
140
|
+
"source": "src",
|
|
141
|
+
"output": "lib",
|
|
142
|
+
"targets": [
|
|
143
|
+
[
|
|
144
|
+
"module",
|
|
145
|
+
{
|
|
146
|
+
"esm": true
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
"typescript",
|
|
151
|
+
{
|
|
152
|
+
"project": "tsconfig.build.json"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
"codegenConfig": {
|
|
158
|
+
"name": "SherpaOnnxSpec",
|
|
159
|
+
"type": "modules",
|
|
160
|
+
"jsSrcsDir": "src",
|
|
161
|
+
"android": {
|
|
162
|
+
"javaPackageName": "com.sherpaonnx"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"prettier": {
|
|
166
|
+
"quoteProps": "consistent",
|
|
167
|
+
"singleQuote": true,
|
|
168
|
+
"tabWidth": 2,
|
|
169
|
+
"trailingComma": "es5",
|
|
170
|
+
"useTabs": false
|
|
171
|
+
},
|
|
172
|
+
"jest": {
|
|
173
|
+
"preset": "react-native",
|
|
174
|
+
"modulePathIgnorePatterns": [
|
|
175
|
+
"<rootDir>/example/node_modules",
|
|
176
|
+
"<rootDir>/lib/"
|
|
177
|
+
]
|
|
178
|
+
},
|
|
179
|
+
"commitlint": {
|
|
180
|
+
"extends": [
|
|
181
|
+
"@commitlint/config-conventional"
|
|
182
|
+
],
|
|
183
|
+
"rules": {
|
|
184
|
+
"header-max-length": [
|
|
185
|
+
2,
|
|
186
|
+
"always",
|
|
187
|
+
300
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"release-it": {
|
|
192
|
+
"git": {
|
|
193
|
+
"commitMessage": "chore: release ${version}",
|
|
194
|
+
"tagName": "v${version}"
|
|
195
|
+
},
|
|
196
|
+
"npm": {
|
|
197
|
+
"publish": true
|
|
198
|
+
},
|
|
199
|
+
"github": {
|
|
200
|
+
"release": true
|
|
201
|
+
},
|
|
202
|
+
"plugins": {
|
|
203
|
+
"@release-it/conventional-changelog": {
|
|
204
|
+
"preset": {
|
|
205
|
+
"name": "angular"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"create-react-native-library": {
|
|
211
|
+
"type": "turbo-module",
|
|
212
|
+
"languages": "kotlin-objc",
|
|
213
|
+
"tools": [
|
|
214
|
+
"eslint",
|
|
215
|
+
"jest",
|
|
216
|
+
"lefthook",
|
|
217
|
+
"release-it"
|
|
218
|
+
],
|
|
219
|
+
"version": "0.57.0"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Script to copy sherpa-onnx header files to Android and iOS include directories.
|
|
5
|
+
* This ensures that the headers are available when the package is published to npm,
|
|
6
|
+
* even if the git submodule is not initialized.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
const SOURCE_DIR = path.join(
|
|
13
|
+
__dirname,
|
|
14
|
+
'..',
|
|
15
|
+
'sherpa-onnx',
|
|
16
|
+
'sherpa-onnx',
|
|
17
|
+
'c-api'
|
|
18
|
+
);
|
|
19
|
+
const ANDROID_DEST_DIR = path.join(
|
|
20
|
+
__dirname,
|
|
21
|
+
'..',
|
|
22
|
+
'android',
|
|
23
|
+
'src',
|
|
24
|
+
'main',
|
|
25
|
+
'cpp',
|
|
26
|
+
'include',
|
|
27
|
+
'sherpa-onnx',
|
|
28
|
+
'c-api'
|
|
29
|
+
);
|
|
30
|
+
const IOS_DEST_DIR = path.join(
|
|
31
|
+
__dirname,
|
|
32
|
+
'..',
|
|
33
|
+
'ios',
|
|
34
|
+
'include',
|
|
35
|
+
'sherpa-onnx',
|
|
36
|
+
'c-api'
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const HEADER_FILES = ['c-api.h', 'cxx-api.h'];
|
|
40
|
+
|
|
41
|
+
// C++ API implementation file needed for iOS (compiles the C++ wrapper around C API)
|
|
42
|
+
const CXX_IMPL_FILE = 'cxx-api.cc';
|
|
43
|
+
const IOS_ROOT_DIR = path.join(__dirname, '..', 'ios');
|
|
44
|
+
|
|
45
|
+
function ensureDirectoryExists(dirPath) {
|
|
46
|
+
if (!fs.existsSync(dirPath)) {
|
|
47
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
48
|
+
console.log(`Created directory: ${dirPath}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyFile(source, destination) {
|
|
53
|
+
try {
|
|
54
|
+
fs.copyFileSync(source, destination);
|
|
55
|
+
console.log(
|
|
56
|
+
`Copied: ${path.basename(source)} -> ${path.relative(
|
|
57
|
+
process.cwd(),
|
|
58
|
+
destination
|
|
59
|
+
)}`
|
|
60
|
+
);
|
|
61
|
+
return true;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(`Failed to copy ${source}:`, error.message);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function areHeadersAlreadyPresent() {
|
|
69
|
+
// Check if all critical headers are already in the destination directories
|
|
70
|
+
const requiredFiles = [
|
|
71
|
+
path.join(ANDROID_DEST_DIR, 'c-api.h'),
|
|
72
|
+
path.join(IOS_DEST_DIR, 'c-api.h'),
|
|
73
|
+
path.join(IOS_DEST_DIR, 'cxx-api.h'),
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
return requiredFiles.every((file) => fs.existsSync(file));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function main() {
|
|
80
|
+
console.log('Checking sherpa-onnx header files...\n');
|
|
81
|
+
|
|
82
|
+
// Check if headers are already present (e.g., from npm package)
|
|
83
|
+
if (areHeadersAlreadyPresent()) {
|
|
84
|
+
console.log('Header files already present, skipping copy.');
|
|
85
|
+
console.log(' Android: android/src/main/cpp/include/sherpa-onnx/c-api/');
|
|
86
|
+
console.log(' iOS: ios/include/sherpa-onnx/c-api/');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log(
|
|
91
|
+
'Header files not found, attempting to copy from git submodule...\n'
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Check if source directory exists
|
|
95
|
+
if (!fs.existsSync(SOURCE_DIR)) {
|
|
96
|
+
console.error(`Error: Source directory not found: ${SOURCE_DIR}`);
|
|
97
|
+
console.error('Possible causes:');
|
|
98
|
+
console.error(' 1. Git submodule is not initialized');
|
|
99
|
+
console.error(
|
|
100
|
+
' 2. You are using an npm package (headers should already be included)'
|
|
101
|
+
);
|
|
102
|
+
console.error('');
|
|
103
|
+
console.error('Solutions:');
|
|
104
|
+
console.error(
|
|
105
|
+
' • Initialize submodule: git submodule update --init --recursive'
|
|
106
|
+
);
|
|
107
|
+
console.error(
|
|
108
|
+
' • Check if headers exist in ios/include/ or android/.../include/'
|
|
109
|
+
);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Ensure destination directories exist
|
|
114
|
+
ensureDirectoryExists(ANDROID_DEST_DIR);
|
|
115
|
+
ensureDirectoryExists(IOS_DEST_DIR);
|
|
116
|
+
|
|
117
|
+
let successCount = 0;
|
|
118
|
+
let failCount = 0;
|
|
119
|
+
|
|
120
|
+
// Copy header files to Android
|
|
121
|
+
console.log('Copying to Android...');
|
|
122
|
+
for (const headerFile of HEADER_FILES) {
|
|
123
|
+
const source = path.join(SOURCE_DIR, headerFile);
|
|
124
|
+
const destination = path.join(ANDROID_DEST_DIR, headerFile);
|
|
125
|
+
|
|
126
|
+
if (!fs.existsSync(source)) {
|
|
127
|
+
console.error(`Source file not found: ${source}`);
|
|
128
|
+
failCount++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (copyFile(source, destination)) {
|
|
133
|
+
successCount++;
|
|
134
|
+
} else {
|
|
135
|
+
failCount++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Copy header files to iOS
|
|
140
|
+
console.log('\nCopying to iOS...');
|
|
141
|
+
for (const headerFile of HEADER_FILES) {
|
|
142
|
+
const source = path.join(SOURCE_DIR, headerFile);
|
|
143
|
+
const destination = path.join(IOS_DEST_DIR, headerFile);
|
|
144
|
+
|
|
145
|
+
if (!fs.existsSync(source)) {
|
|
146
|
+
console.error(`Source file not found: ${source}`);
|
|
147
|
+
failCount++;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (copyFile(source, destination)) {
|
|
152
|
+
successCount++;
|
|
153
|
+
} else {
|
|
154
|
+
failCount++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Copy C++ API implementation to iOS root (needed for compilation)
|
|
159
|
+
console.log('\nCopying C++ API implementation to iOS...');
|
|
160
|
+
const cxxImplSource = path.join(SOURCE_DIR, CXX_IMPL_FILE);
|
|
161
|
+
const cxxImplDest = path.join(IOS_ROOT_DIR, CXX_IMPL_FILE);
|
|
162
|
+
|
|
163
|
+
if (!fs.existsSync(cxxImplSource)) {
|
|
164
|
+
console.error(`Source file not found: ${cxxImplSource}`);
|
|
165
|
+
failCount++;
|
|
166
|
+
} else if (copyFile(cxxImplSource, cxxImplDest)) {
|
|
167
|
+
successCount++;
|
|
168
|
+
} else {
|
|
169
|
+
failCount++;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
console.log(`\n${'='.repeat(50)}`);
|
|
173
|
+
console.log(
|
|
174
|
+
`Summary: ${successCount} files copied successfully, ${failCount} failed`
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (failCount > 0) {
|
|
178
|
+
process.exit(1);
|
|
179
|
+
} else {
|
|
180
|
+
console.log('All header files copied successfully!');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
main();
|