react-native-sherpa-onnx 0.3.7 → 0.3.8
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 +3 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-tts.cpp +31 -4
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +9 -1
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.cpp +7 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-validate-tts.cpp +14 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +15 -0
- package/ios/SherpaOnnx+TTS.mm +1 -0
- package/ios/model_detect/sherpa-onnx-model-detect-tts.mm +36 -4
- package/ios/model_detect/sherpa-onnx-model-detect.h +9 -1
- package/ios/model_detect/sherpa-onnx-validate-tts.mm +14 -0
- package/ios/tts/sherpa-onnx-tts-wrapper.mm +9 -0
- package/lib/module/download/ModelDownloadManager.js +1 -1
- package/lib/module/download/ModelDownloadManager.js.map +1 -1
- package/lib/module/download/background-downloader-types.js +2 -0
- package/lib/module/download/background-downloader-types.js.map +1 -0
- package/lib/module/download/downloadTask.js +54 -1
- package/lib/module/download/downloadTask.js.map +1 -1
- package/lib/module/download/index.js +1 -1
- package/lib/module/download/index.js.map +1 -1
- package/lib/module/download/registry.js +1 -0
- package/lib/module/download/registry.js.map +1 -1
- package/lib/module/tts/index.js +1 -1
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/streaming.js +1 -1
- package/lib/module/tts/streaming.js.map +1 -1
- package/lib/module/tts/types.js +4 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +1 -1
- package/lib/typescript/src/download/ModelDownloadManager.d.ts +2 -1
- package/lib/typescript/src/download/ModelDownloadManager.d.ts.map +1 -1
- package/lib/typescript/src/download/background-downloader-types.d.ts +64 -0
- package/lib/typescript/src/download/background-downloader-types.d.ts.map +1 -0
- package/lib/typescript/src/download/downloadTask.d.ts +10 -0
- package/lib/typescript/src/download/downloadTask.d.ts.map +1 -1
- package/lib/typescript/src/download/index.d.ts +2 -2
- package/lib/typescript/src/download/index.d.ts.map +1 -1
- package/lib/typescript/src/download/registry.d.ts.map +1 -1
- package/lib/typescript/src/tts/index.d.ts +1 -1
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/streaming.d.ts.map +1 -1
- package/lib/typescript/src/tts/types.d.ts +6 -1
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeSherpaOnnx.ts +1 -1
- package/src/download/ModelDownloadManager.ts +2 -0
- package/src/download/background-downloader-types.ts +73 -0
- package/src/download/downloadTask.ts +68 -0
- package/src/download/index.ts +2 -0
- package/src/download/registry.ts +1 -0
- package/src/tts/index.ts +3 -0
- package/src/tts/streaming.ts +2 -0
- package/src/tts/types.ts +9 -0
- package/lib/module/download/background-downloader.d.js +0 -2
- package/lib/module/download/background-downloader.d.js.map +0 -1
- package/src/download/background-downloader.d.ts +0 -43
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time shim for @kesha-antonov/react-native-background-downloader.
|
|
3
|
+
*
|
|
4
|
+
* The package currently ships TS sources without distributable .d.ts files.
|
|
5
|
+
* We route TS path resolution to this shim so the SDK can typecheck strictly
|
|
6
|
+
* without checking third-party TS internals.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface BackgroundDownloaderNotificationTexts {
|
|
10
|
+
downloadTitle?: string;
|
|
11
|
+
downloadStarting?: string;
|
|
12
|
+
downloadProgress?: string;
|
|
13
|
+
downloadPaused?: string;
|
|
14
|
+
downloadFinished?: string;
|
|
15
|
+
groupTitle?: string;
|
|
16
|
+
groupText?: string | ((count: number) => string);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type BackgroundDownloaderSetConfigOptions = {
|
|
20
|
+
showNotificationsEnabled?: boolean;
|
|
21
|
+
notificationsGrouping?: {
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
mode?: 'individual' | 'summaryOnly';
|
|
24
|
+
texts?: BackgroundDownloaderNotificationTexts;
|
|
25
|
+
};
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
progressInterval?: number;
|
|
28
|
+
progressMinBytes?: number;
|
|
29
|
+
isLogsEnabled?: boolean;
|
|
30
|
+
maxParallelDownloads?: number;
|
|
31
|
+
allowsCellularAccess?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface DownloadTask {
|
|
35
|
+
id: string;
|
|
36
|
+
start(): void;
|
|
37
|
+
stop(): void;
|
|
38
|
+
pause(): Promise<void>;
|
|
39
|
+
resume(): Promise<void>;
|
|
40
|
+
begin(
|
|
41
|
+
cb: (data: {
|
|
42
|
+
expectedBytes?: number;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
}) => void
|
|
45
|
+
): DownloadTask;
|
|
46
|
+
progress(
|
|
47
|
+
cb: (data: { bytesDownloaded: number; bytesTotal: number }) => void
|
|
48
|
+
): DownloadTask;
|
|
49
|
+
done(
|
|
50
|
+
cb: (data: {
|
|
51
|
+
location?: string;
|
|
52
|
+
bytesDownloaded: number;
|
|
53
|
+
bytesTotal: number;
|
|
54
|
+
}) => void
|
|
55
|
+
): DownloadTask;
|
|
56
|
+
error(
|
|
57
|
+
cb: (data: { error?: string; errorCode?: number }) => void
|
|
58
|
+
): DownloadTask;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare function setConfig(
|
|
62
|
+
options: BackgroundDownloaderSetConfigOptions
|
|
63
|
+
): void;
|
|
64
|
+
|
|
65
|
+
export declare function createDownloadTask(options: {
|
|
66
|
+
id: string;
|
|
67
|
+
url: string;
|
|
68
|
+
destination: string;
|
|
69
|
+
metadata?: Record<string, unknown>;
|
|
70
|
+
}): DownloadTask;
|
|
71
|
+
|
|
72
|
+
export declare function completeHandler(taskId: string): void;
|
|
73
|
+
export declare function getExistingDownloadTasks(): Promise<DownloadTask[]>;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import type { BackgroundDownloaderSetConfigOptions } from './background-downloader-types';
|
|
1
3
|
import {
|
|
2
4
|
createDownloadTask,
|
|
3
5
|
completeHandler,
|
|
4
6
|
getExistingDownloadTasks,
|
|
7
|
+
setConfig,
|
|
5
8
|
} from '@kesha-antonov/react-native-background-downloader';
|
|
6
9
|
import {
|
|
7
10
|
exists,
|
|
@@ -41,6 +44,68 @@ function makeDownloadTaskId(category: ModelCategory, id: string): string {
|
|
|
41
44
|
|
|
42
45
|
const activeDownloadTasks = new Map<string, { stop: () => void }>();
|
|
43
46
|
|
|
47
|
+
let androidDownloaderNotificationConfigApplied = false;
|
|
48
|
+
let didWarnConfigFailure = false;
|
|
49
|
+
|
|
50
|
+
function warnBackgroundDownloaderConfigFailure(
|
|
51
|
+
context: string,
|
|
52
|
+
error: unknown
|
|
53
|
+
) {
|
|
54
|
+
if (didWarnConfigFailure) return;
|
|
55
|
+
didWarnConfigFailure = true;
|
|
56
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
57
|
+
console.warn(
|
|
58
|
+
`[Download] Background downloader config failed (${context}): ${reason}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type { BackgroundDownloaderSetConfigOptions };
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Apply your own `@kesha-antonov/react-native-background-downloader` `setConfig` **before** the first
|
|
66
|
+
* model download. When called, the SDK will **not** overwrite it with built-in defaults on first download.
|
|
67
|
+
*
|
|
68
|
+
* Safe to call at app startup (e.g. `App.tsx`). Other `setConfig` options (e.g. headers) are forwarded
|
|
69
|
+
* where the native module supports them on each platform.
|
|
70
|
+
*/
|
|
71
|
+
export function configureModelDownloadBackgroundDownloader(
|
|
72
|
+
options: BackgroundDownloaderSetConfigOptions
|
|
73
|
+
): void {
|
|
74
|
+
try {
|
|
75
|
+
setConfig(options);
|
|
76
|
+
androidDownloaderNotificationConfigApplied = true;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// Keep fallback default config enabled if custom config fails.
|
|
79
|
+
warnBackgroundDownloaderConfigFailure('custom', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Library default is showNotificationsEnabled: false (silent empty FGS notification).
|
|
85
|
+
* Enable visible notifications unless the host app already called `configureModelDownloadBackgroundDownloader`.
|
|
86
|
+
*/
|
|
87
|
+
function ensureAndroidBackgroundDownloaderNotifications() {
|
|
88
|
+
if (androidDownloaderNotificationConfigApplied) return;
|
|
89
|
+
if (Platform.OS !== 'android') return;
|
|
90
|
+
try {
|
|
91
|
+
setConfig({
|
|
92
|
+
showNotificationsEnabled: true,
|
|
93
|
+
notificationsGrouping: {
|
|
94
|
+
enabled: false,
|
|
95
|
+
mode: 'individual',
|
|
96
|
+
texts: {
|
|
97
|
+
downloadTitle: 'Model download',
|
|
98
|
+
downloadStarting: 'Starting download…',
|
|
99
|
+
downloadProgress: 'Downloading… {progress}%',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
androidDownloaderNotificationConfigApplied = true;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
warnBackgroundDownloaderConfigFailure('default', error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
44
109
|
export async function downloadModelByCategory<T extends ModelMetaBase>(
|
|
45
110
|
category: ModelCategory,
|
|
46
111
|
id: string,
|
|
@@ -103,6 +168,8 @@ export async function downloadModelByCategory<T extends ModelMetaBase>(
|
|
|
103
168
|
throw new Error(`Insufficient disk space: ${diskSpaceCheck.message}`);
|
|
104
169
|
}
|
|
105
170
|
|
|
171
|
+
ensureAndroidBackgroundDownloaderNotifications();
|
|
172
|
+
|
|
106
173
|
const statePath = getDownloadStatePath(category, id);
|
|
107
174
|
|
|
108
175
|
if (opts?.overwrite) {
|
|
@@ -339,6 +406,7 @@ export async function resumeDownload<T extends ModelMetaBase>(
|
|
|
339
406
|
deleteArchiveAfterExtract?: boolean;
|
|
340
407
|
}
|
|
341
408
|
): Promise<DownloadResult> {
|
|
409
|
+
ensureAndroidBackgroundDownloaderNotifications();
|
|
342
410
|
const taskId = makeDownloadTaskId(category, id);
|
|
343
411
|
const existingTasks = await getExistingDownloadTasks();
|
|
344
412
|
const existing = existingTasks.find((t) => t.id === taskId);
|
package/src/download/index.ts
CHANGED
|
@@ -30,8 +30,10 @@ export {
|
|
|
30
30
|
ModelCategory,
|
|
31
31
|
getProtectedModelKeysForBulkDelete,
|
|
32
32
|
purgeDownloadedModelArtifacts,
|
|
33
|
+
configureModelDownloadBackgroundDownloader,
|
|
33
34
|
} from './ModelDownloadManager';
|
|
34
35
|
export type {
|
|
36
|
+
BackgroundDownloaderSetConfigOptions,
|
|
35
37
|
ModelMetaBase,
|
|
36
38
|
TtsModelMeta,
|
|
37
39
|
TtsModelType,
|
package/src/download/registry.ts
CHANGED
|
@@ -96,6 +96,7 @@ function deriveType(id: string): TtsModelType {
|
|
|
96
96
|
if (lower.includes('kitten')) return 'kitten';
|
|
97
97
|
if (lower.includes('pocket')) return 'pocket';
|
|
98
98
|
if (lower.includes('zipvoice')) return 'zipvoice';
|
|
99
|
+
if (lower.includes('supertonic')) return 'supertonic';
|
|
99
100
|
return 'unknown';
|
|
100
101
|
}
|
|
101
102
|
|
package/src/tts/index.ts
CHANGED
|
@@ -49,6 +49,8 @@ function flattenTtsModelOptionsForNative(
|
|
|
49
49
|
? modelOptions.kitten
|
|
50
50
|
: modelType === 'pocket'
|
|
51
51
|
? modelOptions.pocket
|
|
52
|
+
: modelType === 'supertonic'
|
|
53
|
+
? modelOptions.supertonic
|
|
52
54
|
: undefined;
|
|
53
55
|
if (!block)
|
|
54
56
|
return {
|
|
@@ -446,6 +448,7 @@ export type {
|
|
|
446
448
|
TtsKokoroModelOptions,
|
|
447
449
|
TtsKittenModelOptions,
|
|
448
450
|
TtsPocketModelOptions,
|
|
451
|
+
TtsSupertonicModelOptions,
|
|
449
452
|
TtsUpdateOptions,
|
|
450
453
|
TtsGenerationOptions,
|
|
451
454
|
GeneratedAudio,
|
package/src/tts/streaming.ts
CHANGED
package/src/tts/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { ModelPathConfig } from '../types';
|
|
|
9
9
|
* - 'kitten': KittenTTS models (lightweight, multi-speaker)
|
|
10
10
|
* - 'pocket': Pocket TTS models
|
|
11
11
|
* - 'zipvoice': Zipvoice models (voice cloning capable)
|
|
12
|
+
* - 'supertonic': Supertonic models
|
|
12
13
|
* - 'auto': Auto-detect model type based on files present (default)
|
|
13
14
|
*/
|
|
14
15
|
export type TTSModelType =
|
|
@@ -18,6 +19,7 @@ export type TTSModelType =
|
|
|
18
19
|
| 'kitten'
|
|
19
20
|
| 'pocket'
|
|
20
21
|
| 'zipvoice'
|
|
22
|
+
| 'supertonic'
|
|
21
23
|
| 'auto';
|
|
22
24
|
|
|
23
25
|
/** Runtime list of supported TTS model types. */
|
|
@@ -28,6 +30,7 @@ export const TTS_MODEL_TYPES: readonly TTSModelType[] = [
|
|
|
28
30
|
'kitten',
|
|
29
31
|
'pocket',
|
|
30
32
|
'zipvoice',
|
|
33
|
+
'supertonic',
|
|
31
34
|
'auto',
|
|
32
35
|
] as const;
|
|
33
36
|
|
|
@@ -68,6 +71,11 @@ export interface TtsPocketModelOptions {
|
|
|
68
71
|
// No init-time options in Kotlin OfflineTtsPocketModelConfig; voice cloning is via GenerationConfig at generate time.
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
/** Options for Supertonic models. Applied only when modelType is 'supertonic'. */
|
|
75
|
+
export interface TtsSupertonicModelOptions {
|
|
76
|
+
// No init-time model options exposed by sherpa-onnx currently.
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
/**
|
|
72
80
|
* Model-specific TTS options. Only the block for the actually loaded model type is applied;
|
|
73
81
|
* others are ignored (e.g. vits options have no effect when a kokoro model is loaded).
|
|
@@ -78,6 +86,7 @@ export interface TtsModelOptions {
|
|
|
78
86
|
kokoro?: TtsKokoroModelOptions;
|
|
79
87
|
kitten?: TtsKittenModelOptions;
|
|
80
88
|
pocket?: TtsPocketModelOptions;
|
|
89
|
+
supertonic?: TtsSupertonicModelOptions;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["download/background-downloader.d.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type declarations for @kesha-antonov/react-native-background-downloader
|
|
3
|
-
* when the package is not installed (e.g. SDK build). The real package provides full types.
|
|
4
|
-
*/
|
|
5
|
-
declare module '@kesha-antonov/react-native-background-downloader' {
|
|
6
|
-
export interface DownloadTask {
|
|
7
|
-
id: string;
|
|
8
|
-
start(): void;
|
|
9
|
-
stop(): void;
|
|
10
|
-
pause(): Promise<void>;
|
|
11
|
-
resume(): Promise<void>;
|
|
12
|
-
begin(
|
|
13
|
-
cb: (data: {
|
|
14
|
-
expectedBytes?: number;
|
|
15
|
-
headers?: Record<string, string>;
|
|
16
|
-
}) => void
|
|
17
|
-
): DownloadTask;
|
|
18
|
-
progress(
|
|
19
|
-
cb: (data: { bytesDownloaded: number; bytesTotal: number }) => void
|
|
20
|
-
): DownloadTask;
|
|
21
|
-
done(
|
|
22
|
-
cb: (data: {
|
|
23
|
-
location?: string;
|
|
24
|
-
bytesDownloaded: number;
|
|
25
|
-
bytesTotal: number;
|
|
26
|
-
}) => void
|
|
27
|
-
): DownloadTask;
|
|
28
|
-
error(
|
|
29
|
-
cb: (data: { error?: string; errorCode?: number }) => void
|
|
30
|
-
): DownloadTask;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function createDownloadTask(options: {
|
|
34
|
-
id: string;
|
|
35
|
-
url: string;
|
|
36
|
-
destination: string;
|
|
37
|
-
metadata?: Record<string, unknown>;
|
|
38
|
-
}): DownloadTask;
|
|
39
|
-
|
|
40
|
-
export function completeHandler(taskId: string): void;
|
|
41
|
-
|
|
42
|
-
export function getExistingDownloadTasks(): Promise<DownloadTask[]>;
|
|
43
|
-
}
|