react-native-executorch 0.7.0-nightly-b4770df-20260205 → 0.7.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/common/rnexecutorch/ErrorCodes.h +15 -30
- package/common/rnexecutorch/host_objects/ModelHostObject.h +5 -0
- package/common/rnexecutorch/models/llm/LLM.cpp +7 -0
- package/common/rnexecutorch/models/llm/LLM.h +1 -0
- package/lib/module/constants/llmDefaults.js +31 -0
- package/lib/module/constants/llmDefaults.js.map +1 -1
- package/lib/module/constants/modelUrls.js +220 -0
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +255 -73
- package/lib/module/constants/ocr/models.js.map +1 -1
- package/lib/module/constants/ocr/symbols.js +4 -0
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/constants/tts/models.js +6 -2
- package/lib/module/constants/tts/models.js.map +1 -1
- package/lib/module/constants/tts/voices.js +27 -3
- package/lib/module/constants/tts/voices.js.map +1 -1
- package/lib/module/constants/versions.js +2 -2
- package/lib/module/controllers/LLMController.js +9 -0
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/errors/ErrorCodes.js +54 -0
- package/lib/module/errors/ErrorCodes.js.map +1 -1
- package/lib/module/errors/errorUtils.js +30 -6
- package/lib/module/errors/errorUtils.js.map +1 -1
- package/lib/module/hooks/computer_vision/useClassification.js +7 -0
- package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageEmbeddings.js +8 -0
- package/lib/module/hooks/computer_vision/useImageEmbeddings.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageSegmentation.js +7 -0
- package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -1
- package/lib/module/hooks/computer_vision/useOCR.js +7 -0
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/computer_vision/useObjectDetection.js +7 -0
- package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
- package/lib/module/hooks/computer_vision/useStyleTransfer.js +7 -0
- package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
- package/lib/module/hooks/computer_vision/useTextToImage.js +7 -0
- package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -1
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +7 -0
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/general/useExecutorchModule.js +8 -0
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +11 -3
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +8 -0
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextToSpeech.js +8 -0
- package/lib/module/hooks/natural_language_processing/useTextToSpeech.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +7 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useVAD.js +7 -0
- package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -1
- package/lib/module/hooks/useModule.js +12 -0
- package/lib/module/hooks/useModule.js.map +1 -1
- package/lib/module/index.js +10 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/BaseModule.js +22 -0
- package/lib/module/modules/BaseModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ClassificationModule.js +20 -0
- package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js +19 -0
- package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js +22 -0
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/OCRModule.js +26 -0
- package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js +22 -0
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
- package/lib/module/modules/computer_vision/StyleTransferModule.js +20 -0
- package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
- package/lib/module/modules/computer_vision/TextToImageModule.js +33 -0
- package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -1
- package/lib/module/modules/computer_vision/VerticalOCRModule.js +27 -0
- package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
- package/lib/module/modules/general/ExecutorchModule.js +21 -0
- package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +104 -0
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +67 -21
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextToSpeechModule.js +40 -0
- package/lib/module/modules/natural_language_processing/TextToSpeechModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TokenizerModule.js +54 -2
- package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/VADModule.js +20 -0
- package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -1
- package/lib/module/types/classification.js +4 -0
- package/lib/module/types/classification.js.map +1 -0
- package/lib/module/types/common.js +96 -0
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/executorchModule.js +4 -0
- package/lib/module/types/executorchModule.js.map +1 -0
- package/lib/module/types/imageEmbeddings.js +4 -0
- package/lib/module/types/imageEmbeddings.js.map +1 -0
- package/lib/module/types/imageSegmentation.js +22 -1
- package/lib/module/types/imageSegmentation.js.map +1 -1
- package/lib/module/types/llm.js +80 -2
- package/lib/module/types/llm.js.map +1 -1
- package/lib/module/types/objectDetection.js +42 -2
- package/lib/module/types/objectDetection.js.map +1 -1
- package/lib/module/types/styleTransfer.js +4 -0
- package/lib/module/types/styleTransfer.js.map +1 -0
- package/lib/module/types/textEmbeddings.js +4 -0
- package/lib/module/types/textEmbeddings.js.map +1 -0
- package/lib/module/types/tokenizer.js +4 -0
- package/lib/module/types/tokenizer.js.map +1 -0
- package/lib/module/types/tti.js +4 -0
- package/lib/module/types/tti.js.map +1 -0
- package/lib/module/types/vad.js +2 -0
- package/lib/module/utils/ResourceFetcher.js +63 -0
- package/lib/module/utils/ResourceFetcher.js.map +1 -1
- package/lib/module/utils/llm.js +24 -1
- package/lib/module/utils/llm.js.map +1 -1
- package/lib/typescript/constants/llmDefaults.d.ts +27 -0
- package/lib/typescript/constants/llmDefaults.d.ts.map +1 -1
- package/lib/typescript/constants/modelUrls.d.ts +165 -0
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +189 -315
- package/lib/typescript/constants/ocr/models.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/symbols.d.ts +3 -0
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/constants/tts/models.d.ts +4 -0
- package/lib/typescript/constants/tts/models.d.ts.map +1 -1
- package/lib/typescript/constants/tts/voices.d.ts +24 -0
- package/lib/typescript/constants/tts/voices.d.ts.map +1 -1
- package/lib/typescript/constants/versions.d.ts +2 -2
- package/lib/typescript/controllers/LLMController.d.ts +2 -0
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/errors/ErrorCodes.d.ts +54 -0
- package/lib/typescript/errors/ErrorCodes.d.ts.map +1 -1
- package/lib/typescript/errors/errorUtils.d.ts +9 -0
- package/lib/typescript/errors/errorUtils.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +9 -38
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +9 -19
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +9 -22
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +9 -20
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts +9 -13
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +9 -10
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +9 -19
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +9 -16
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts +9 -15
- package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +9 -18
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +9 -15
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -1
- package/lib/typescript/hooks/useModule.d.ts +12 -0
- package/lib/typescript/hooks/useModule.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +10 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/BaseModule.d.ts +20 -0
- package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +21 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts +17 -0
- package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +21 -3
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts +25 -2
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +20 -0
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +18 -0
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +29 -0
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +26 -2
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/general/ExecutorchModule.d.ts +19 -0
- package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +97 -7
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +62 -4
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +19 -0
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts +37 -2
- package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +47 -2
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +18 -0
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -1
- package/lib/typescript/types/classification.d.ts +50 -0
- package/lib/typescript/types/classification.d.ts.map +1 -0
- package/lib/typescript/types/common.d.ts +92 -0
- package/lib/typescript/types/common.d.ts.map +1 -1
- package/lib/typescript/types/executorchModule.d.ts +45 -0
- package/lib/typescript/types/executorchModule.d.ts.map +1 -0
- package/lib/typescript/types/imageEmbeddings.d.ts +48 -0
- package/lib/typescript/types/imageEmbeddings.d.ts.map +1 -0
- package/lib/typescript/types/imageSegmentation.d.ts +55 -0
- package/lib/typescript/types/imageSegmentation.d.ts.map +1 -1
- package/lib/typescript/types/llm.d.ts +193 -5
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/lib/typescript/types/objectDetection.d.ts +71 -2
- package/lib/typescript/types/objectDetection.d.ts.map +1 -1
- package/lib/typescript/types/ocr.d.ts +97 -2
- package/lib/typescript/types/ocr.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +114 -0
- package/lib/typescript/types/stt.d.ts.map +1 -1
- package/lib/typescript/types/styleTransfer.d.ts +48 -0
- package/lib/typescript/types/styleTransfer.d.ts.map +1 -0
- package/lib/typescript/types/textEmbeddings.d.ts +53 -0
- package/lib/typescript/types/textEmbeddings.d.ts.map +1 -0
- package/lib/typescript/types/tokenizer.d.ts +75 -0
- package/lib/typescript/types/tokenizer.d.ts.map +1 -0
- package/lib/typescript/types/tti.d.ts +74 -0
- package/lib/typescript/types/tti.d.ts.map +1 -0
- package/lib/typescript/types/tts.d.ts +77 -0
- package/lib/typescript/types/tts.d.ts.map +1 -1
- package/lib/typescript/types/vad.d.ts +53 -0
- package/lib/typescript/types/vad.d.ts.map +1 -1
- package/lib/typescript/utils/ResourceFetcher.d.ts +55 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
- package/lib/typescript/utils/llm.d.ts +22 -0
- package/lib/typescript/utils/llm.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants/llmDefaults.ts +27 -0
- package/src/constants/modelUrls.ts +166 -0
- package/src/constants/ocr/models.ts +192 -266
- package/src/constants/ocr/symbols.ts +3 -0
- package/src/constants/tts/models.ts +6 -2
- package/src/constants/tts/voices.ts +27 -3
- package/src/constants/versions.ts +2 -2
- package/src/controllers/LLMController.ts +15 -0
- package/src/errors/ErrorCodes.ts +54 -0
- package/src/errors/errorUtils.ts +37 -17
- package/src/hooks/computer_vision/useClassification.ts +15 -7
- package/src/hooks/computer_vision/useImageEmbeddings.ts +15 -7
- package/src/hooks/computer_vision/useImageSegmentation.ts +15 -7
- package/src/hooks/computer_vision/useOCR.ts +9 -21
- package/src/hooks/computer_vision/useObjectDetection.ts +15 -7
- package/src/hooks/computer_vision/useStyleTransfer.ts +15 -7
- package/src/hooks/computer_vision/useTextToImage.ts +9 -26
- package/src/hooks/computer_vision/useVerticalOCR.ts +9 -19
- package/src/hooks/general/useExecutorchModule.ts +12 -7
- package/src/hooks/natural_language_processing/useLLM.ts +24 -28
- package/src/hooks/natural_language_processing/useSpeechToText.ts +13 -5
- package/src/hooks/natural_language_processing/useTextEmbeddings.ts +15 -10
- package/src/hooks/natural_language_processing/useTextToSpeech.ts +10 -6
- package/src/hooks/natural_language_processing/useTokenizer.ts +10 -6
- package/src/hooks/natural_language_processing/useVAD.ts +9 -7
- package/src/hooks/useModule.ts +15 -0
- package/src/index.ts +10 -5
- package/src/modules/BaseModule.ts +20 -0
- package/src/modules/computer_vision/ClassificationModule.ts +19 -1
- package/src/modules/computer_vision/ImageEmbeddingsModule.ts +17 -0
- package/src/modules/computer_vision/ImageSegmentationModule.ts +21 -1
- package/src/modules/computer_vision/OCRModule.ts +25 -2
- package/src/modules/computer_vision/ObjectDetectionModule.ts +20 -0
- package/src/modules/computer_vision/StyleTransferModule.ts +18 -0
- package/src/modules/computer_vision/TextToImageModule.ts +29 -0
- package/src/modules/computer_vision/VerticalOCRModule.ts +26 -2
- package/src/modules/general/ExecutorchModule.ts +19 -0
- package/src/modules/natural_language_processing/LLMModule.ts +104 -18
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +63 -39
- package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +19 -0
- package/src/modules/natural_language_processing/TextToSpeechModule.ts +43 -2
- package/src/modules/natural_language_processing/TokenizerModule.ts +51 -3
- package/src/modules/natural_language_processing/VADModule.ts +18 -0
- package/src/types/classification.ts +51 -0
- package/src/types/common.ts +93 -0
- package/src/types/executorchModule.ts +50 -0
- package/src/types/imageEmbeddings.ts +51 -0
- package/src/types/imageSegmentation.ts +64 -1
- package/src/types/llm.ts +208 -11
- package/src/types/objectDetection.ts +79 -1
- package/src/types/ocr.ts +107 -2
- package/src/types/stt.ts +136 -1
- package/src/types/styleTransfer.ts +51 -0
- package/src/types/textEmbeddings.ts +58 -0
- package/src/types/tokenizer.ts +86 -0
- package/src/types/tti.ts +87 -0
- package/src/types/tts.ts +85 -2
- package/src/types/vad.ts +58 -0
- package/src/utils/ResourceFetcher.ts +55 -0
- package/src/utils/llm.ts +22 -1
package/src/types/ocr.ts
CHANGED
|
@@ -1,14 +1,119 @@
|
|
|
1
1
|
import { symbols } from '../constants/ocr/symbols';
|
|
2
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
3
|
+
import { ResourceSource } from './common';
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* OCRDetection represents a single detected text instance in an image,
|
|
7
|
+
* including its bounding box, recognized text, and confidence score.
|
|
8
|
+
*
|
|
9
|
+
* @category Types
|
|
10
|
+
* @property {Point[]} bbox - An array of points defining the bounding box around the detected text.
|
|
11
|
+
* @property {string} text - The recognized text within the bounding box.
|
|
12
|
+
* @property {number} score - The confidence score of the OCR detection, ranging from 0 to 1.
|
|
13
|
+
*/
|
|
3
14
|
export interface OCRDetection {
|
|
4
|
-
bbox:
|
|
15
|
+
bbox: Point[];
|
|
5
16
|
text: string;
|
|
6
17
|
score: number;
|
|
7
18
|
}
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Point represents a coordinate in 2D space.
|
|
22
|
+
*
|
|
23
|
+
* @category Types
|
|
24
|
+
* @property {number} x - The x-coordinate of the point.
|
|
25
|
+
* @property {number} y - The y-coordinate of the point.
|
|
26
|
+
*/
|
|
27
|
+
export interface Point {
|
|
10
28
|
x: number;
|
|
11
29
|
y: number;
|
|
12
30
|
}
|
|
13
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Configuration properties for the `useOCR` hook.
|
|
34
|
+
*
|
|
35
|
+
* @category Types
|
|
36
|
+
*/
|
|
37
|
+
export interface OCRProps {
|
|
38
|
+
/**
|
|
39
|
+
* Object containing the necessary model sources and configuration for the OCR pipeline.
|
|
40
|
+
*/
|
|
41
|
+
model: {
|
|
42
|
+
/**
|
|
43
|
+
* `ResourceSource` that specifies the location of the text detector model binary.
|
|
44
|
+
*/
|
|
45
|
+
detectorSource: ResourceSource;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `ResourceSource` that specifies the location of the text recognizer model binary.
|
|
49
|
+
*/
|
|
50
|
+
recognizerSource: ResourceSource;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The language configuration enum for the OCR model (e.g., English, Polish, etc.).
|
|
54
|
+
*/
|
|
55
|
+
language: OCRLanguage;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Boolean that can prevent automatic model loading (and downloading the data if loaded for the first time) after running the hook.
|
|
60
|
+
* Defaults to `false`.
|
|
61
|
+
*/
|
|
62
|
+
preventLoad?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Configuration properties for the `useVerticalOCR` hook.
|
|
67
|
+
*
|
|
68
|
+
* @category Types
|
|
69
|
+
*/
|
|
70
|
+
export interface VerticalOCRProps extends OCRProps {
|
|
71
|
+
/**
|
|
72
|
+
* Boolean indicating whether to treat each character independently during recognition.
|
|
73
|
+
* Defaults to `false`.
|
|
74
|
+
*/
|
|
75
|
+
independentCharacters?: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Return type for the `useOCR` hook.
|
|
80
|
+
* Manages the state and operations for Optical Character Recognition (OCR).
|
|
81
|
+
*
|
|
82
|
+
* @category Types
|
|
83
|
+
*/
|
|
84
|
+
export interface OCRType {
|
|
85
|
+
/**
|
|
86
|
+
* Contains the error object if the models failed to load, download, or encountered a runtime error during recognition.
|
|
87
|
+
*/
|
|
88
|
+
error: RnExecutorchError | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Indicates whether both detector and recognizer models are loaded and ready to process images.
|
|
92
|
+
*/
|
|
93
|
+
isReady: boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Indicates whether the model is currently processing an image.
|
|
97
|
+
*/
|
|
98
|
+
isGenerating: boolean;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Represents the total download progress of the model binaries as a value between 0 and 1.
|
|
102
|
+
*/
|
|
103
|
+
downloadProgress: number;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Executes the OCR pipeline (detection and recognition) on the provided image.
|
|
107
|
+
* @param imageSource - A string representing the image source (e.g., a file path, URI, or base64 string) to be processed.
|
|
108
|
+
* @returns A Promise that resolves to the OCR results (typically containing the recognized text strings and their bounding boxes).
|
|
109
|
+
* @throws {RnExecutorchError} If the models are not loaded or are currently processing another image.
|
|
110
|
+
*/
|
|
111
|
+
forward: (imageSource: string) => Promise<OCRDetection[]>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Enumeration of supported OCR languages based on available symbol sets.
|
|
116
|
+
*
|
|
117
|
+
* @category Types
|
|
118
|
+
*/
|
|
14
119
|
export type OCRLanguage = keyof typeof symbols;
|
package/src/types/stt.ts
CHANGED
|
@@ -1,6 +1,115 @@
|
|
|
1
1
|
import { ResourceSource } from './common';
|
|
2
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for Speech to Text model.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
9
|
+
export interface SpeechToTextProps {
|
|
10
|
+
/**
|
|
11
|
+
* Configuration object containing model sources.
|
|
12
|
+
*/
|
|
13
|
+
model: SpeechToTextModelConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
|
|
16
|
+
*/
|
|
17
|
+
preventLoad?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* React hook for managing Speech to Text (STT) instance.
|
|
22
|
+
*
|
|
23
|
+
* @category Types
|
|
24
|
+
*/
|
|
25
|
+
export interface SpeechToTextType {
|
|
26
|
+
/**
|
|
27
|
+
* Contains the error message if the model failed to load.
|
|
28
|
+
*/
|
|
29
|
+
error: null | RnExecutorchError;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Indicates whether the model has successfully loaded and is ready for inference.
|
|
33
|
+
*/
|
|
34
|
+
isReady: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether the model is currently processing an inference.
|
|
38
|
+
*/
|
|
39
|
+
isGenerating: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tracks the progress of the model download process.
|
|
43
|
+
*/
|
|
44
|
+
downloadProgress: number;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Contains the part of the transcription that is finalized and will not change.
|
|
48
|
+
* Useful for displaying stable results during streaming.
|
|
49
|
+
*/
|
|
50
|
+
committedTranscription: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Contains the part of the transcription that is still being processed and may change.
|
|
54
|
+
* Useful for displaying live, partial results during streaming.
|
|
55
|
+
*/
|
|
56
|
+
nonCommittedTranscription: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Runs the encoding part of the model on the provided waveform.
|
|
60
|
+
* @param waveform - The input audio waveform array.
|
|
61
|
+
* @returns A promise resolving to the encoded data.
|
|
62
|
+
*/
|
|
63
|
+
encode(waveform: Float32Array): Promise<Float32Array>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Runs the decoder of the model.
|
|
67
|
+
* @param tokens - The encoded audio data.
|
|
68
|
+
* @param encoderOutput - The output from the encoder.
|
|
69
|
+
* @returns A promise resolving to the decoded text.
|
|
70
|
+
*/
|
|
71
|
+
decode(
|
|
72
|
+
tokens: Int32Array,
|
|
73
|
+
encoderOutput: Float32Array
|
|
74
|
+
): Promise<Float32Array>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Starts a transcription process for a given input array, which should be a waveform at 16kHz.
|
|
78
|
+
* @param waveform - The input audio waveform.
|
|
79
|
+
* @param options - Decoding options, e.g. `{ language: 'es' }` for multilingual models.
|
|
80
|
+
* @returns Resolves a promise with the output transcription when the model is finished.
|
|
81
|
+
*/
|
|
82
|
+
transcribe(
|
|
83
|
+
waveform: Float32Array,
|
|
84
|
+
options?: DecodingOptions | undefined
|
|
85
|
+
): Promise<string>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Starts a streaming transcription process.
|
|
89
|
+
* Use in combination with `streamInsert` to feed audio chunks and `streamStop` to end the stream.
|
|
90
|
+
* Updates `committedTranscription` and `nonCommittedTranscription` as transcription progresses.
|
|
91
|
+
* @param options - Decoding options including language.
|
|
92
|
+
* @returns The final transcription string.
|
|
93
|
+
*/
|
|
94
|
+
stream(options?: DecodingOptions | undefined): Promise<string>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Inserts a chunk of audio data (sampled at 16kHz) into the ongoing streaming transcription.
|
|
98
|
+
* @param waveform - The audio chunk to insert.
|
|
99
|
+
*/
|
|
100
|
+
streamInsert(waveform: Float32Array): void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Stops the ongoing streaming transcription process.
|
|
104
|
+
*/
|
|
105
|
+
streamStop(): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Languages supported by whisper (not whisper.en)
|
|
110
|
+
*
|
|
111
|
+
* @category Types
|
|
112
|
+
*/
|
|
4
113
|
export type SpeechToTextLanguage =
|
|
5
114
|
| 'af'
|
|
6
115
|
| 'sq'
|
|
@@ -78,13 +187,39 @@ export type SpeechToTextLanguage =
|
|
|
78
187
|
| 'cy'
|
|
79
188
|
| 'yi';
|
|
80
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Options for decoding speech to text.
|
|
192
|
+
*
|
|
193
|
+
* @category Types
|
|
194
|
+
* @property {SpeechToTextLanguage} [language] - Optional language code to guide the transcription.
|
|
195
|
+
*/
|
|
81
196
|
export interface DecodingOptions {
|
|
82
197
|
language?: SpeechToTextLanguage;
|
|
83
198
|
}
|
|
84
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Configuration for Speech to Text model.
|
|
202
|
+
*
|
|
203
|
+
* @category Types
|
|
204
|
+
*/
|
|
85
205
|
export interface SpeechToTextModelConfig {
|
|
206
|
+
/**
|
|
207
|
+
* A boolean flag indicating whether the model supports multiple languages.
|
|
208
|
+
*/
|
|
86
209
|
isMultilingual: boolean;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A string that specifies the location of a `.pte` file for the encoder.
|
|
213
|
+
*/
|
|
87
214
|
encoderSource: ResourceSource;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* A string that specifies the location of a `.pte` file for the decoder.
|
|
218
|
+
*/
|
|
88
219
|
decoderSource: ResourceSource;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* A string that specifies the location to the tokenizer for the model.
|
|
223
|
+
*/
|
|
89
224
|
tokenizerSource: ResourceSource;
|
|
90
225
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
|
+
import { ResourceSource } from './common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration properties for the `useStyleTransfer` hook.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
* @property {Object} model - Object containing the `modelSource` for the style transfer model.
|
|
9
|
+
* @property {ResourceSource} model.modelSource - `ResourceSource` that specifies the location of the style transfer model binary.
|
|
10
|
+
* @property {boolean} [preventLoad] - Boolean that can prevent automatic model loading (and downloading the data if loaded for the first time) after running the hook.
|
|
11
|
+
*/
|
|
12
|
+
export interface StyleTransferProps {
|
|
13
|
+
model: { modelSource: ResourceSource };
|
|
14
|
+
preventLoad?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Return type for the `useStyleTransfer` hook.
|
|
19
|
+
* Manages the state and operations for applying artistic style transfer to images.
|
|
20
|
+
*
|
|
21
|
+
* @category Types
|
|
22
|
+
*/
|
|
23
|
+
export interface StyleTransferType {
|
|
24
|
+
/**
|
|
25
|
+
* Contains the error object if the model failed to load, download, or encountered a runtime error during style transfer.
|
|
26
|
+
*/
|
|
27
|
+
error: RnExecutorchError | null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Indicates whether the style transfer model is loaded and ready to process images.
|
|
31
|
+
*/
|
|
32
|
+
isReady: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Indicates whether the model is currently processing an image.
|
|
36
|
+
*/
|
|
37
|
+
isGenerating: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represents the download progress of the model binary as a value between 0 and 1.
|
|
41
|
+
*/
|
|
42
|
+
downloadProgress: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Executes the model's forward pass to apply the specific artistic style to the provided image.
|
|
46
|
+
* @param imageSource - A string representing the input image source (e.g., a file path, URI, or base64 string) to be stylized.
|
|
47
|
+
* @returns A Promise that resolves to a string containing the stylized image (typically as a base64 string or a file URI).
|
|
48
|
+
* @throws {RnExecutorchError} If the model is not loaded or is currently processing another image.
|
|
49
|
+
*/
|
|
50
|
+
forward: (imageSource: string) => Promise<string>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
|
+
import { ResourceSource } from '../types/common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for the useTextEmbeddings hook.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
* @property {Object} model - An object containing the model and tokenizer sources.
|
|
9
|
+
* @property {boolean} [preventLoad] - Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
|
|
10
|
+
*/
|
|
11
|
+
export interface TextEmbeddingsProps {
|
|
12
|
+
model: {
|
|
13
|
+
/**
|
|
14
|
+
* The source of the text embeddings model binary.
|
|
15
|
+
*/
|
|
16
|
+
modelSource: ResourceSource;
|
|
17
|
+
/**
|
|
18
|
+
* The source of the tokenizer JSON file.
|
|
19
|
+
*/
|
|
20
|
+
tokenizerSource: ResourceSource;
|
|
21
|
+
};
|
|
22
|
+
preventLoad?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* React hook state and methods for managing a Text Embeddings model instance.
|
|
27
|
+
*
|
|
28
|
+
* @category Types
|
|
29
|
+
*/
|
|
30
|
+
export interface TextEmbeddingsType {
|
|
31
|
+
/**
|
|
32
|
+
* Contains the error message if the model failed to load or during inference.
|
|
33
|
+
*/
|
|
34
|
+
error: null | RnExecutorchError;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether the embeddings model has successfully loaded and is ready for inference.
|
|
38
|
+
*/
|
|
39
|
+
isReady: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Indicates whether the model is currently generating embeddings.
|
|
43
|
+
*/
|
|
44
|
+
isGenerating: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Tracks the progress of the model download process (value between 0 and 1).
|
|
48
|
+
*/
|
|
49
|
+
downloadProgress: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Runs the text embeddings model on the provided input string.
|
|
53
|
+
* @param input - The text string to embed.
|
|
54
|
+
* @returns A promise resolving to a Float32Array containing the vector embeddings.
|
|
55
|
+
* @throws {RnExecutorchError} If the model is not loaded or is currently processing another request.
|
|
56
|
+
*/
|
|
57
|
+
forward(input: string): Promise<Float32Array>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
|
+
import { ResourceSource } from './common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for initializing and configuring a Tokenizer instance.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
9
|
+
export interface TokenizerProps {
|
|
10
|
+
/**
|
|
11
|
+
* Object containing:
|
|
12
|
+
*
|
|
13
|
+
* `tokenizerSource` - A `ResourceSource` that specifies the location of the tokenizer.
|
|
14
|
+
*/
|
|
15
|
+
tokenizer: { tokenizerSource: ResourceSource };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
|
|
19
|
+
*/
|
|
20
|
+
preventLoad?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* React hook state and methods for managing a Tokenizer instance.
|
|
25
|
+
*
|
|
26
|
+
* @category Types
|
|
27
|
+
*/
|
|
28
|
+
export interface TokenizerType {
|
|
29
|
+
/**
|
|
30
|
+
* Contains the error message if the tokenizer failed to load or during processing.
|
|
31
|
+
*/
|
|
32
|
+
error: null | RnExecutorchError;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Indicates whether the tokenizer has successfully loaded and is ready for use.
|
|
36
|
+
*/
|
|
37
|
+
isReady: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Indicates whether the tokenizer is currently processing data.
|
|
41
|
+
*/
|
|
42
|
+
isGenerating: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Tracks the progress of the tokenizer download process (value between 0 and 1).
|
|
46
|
+
*/
|
|
47
|
+
downloadProgress: number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Converts an array of token IDs into a string.
|
|
51
|
+
* @param tokens - An array or `number[]` of token IDs to decode.
|
|
52
|
+
* @param skipSpecialTokens - Optional boolean to indicate whether special tokens should be skipped during decoding.
|
|
53
|
+
* @returns A promise resolving to the decoded text string.
|
|
54
|
+
*/
|
|
55
|
+
decode(
|
|
56
|
+
tokens: number[],
|
|
57
|
+
skipSpecialTokens: boolean | undefined
|
|
58
|
+
): Promise<string>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Converts a string into an array of token IDs.
|
|
62
|
+
* @param text - The input text string to tokenize.
|
|
63
|
+
* @returns A promise resolving to an array `number[]` containing the encoded token IDs.
|
|
64
|
+
*/
|
|
65
|
+
encode(text: string): Promise<number[]>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns the size of the tokenizer's vocabulary.
|
|
69
|
+
* @returns A promise resolving to the vocabulary size.
|
|
70
|
+
*/
|
|
71
|
+
getVocabSize(): Promise<number>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns the token associated to the ID.
|
|
75
|
+
* @param id - The numeric token ID.
|
|
76
|
+
* @returns A promise resolving to the token string representation.
|
|
77
|
+
*/
|
|
78
|
+
idToToken(id: number): Promise<string>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the ID associated to the token.
|
|
82
|
+
* @param token - The token string.
|
|
83
|
+
* @returns A promise resolving to the token ID.
|
|
84
|
+
*/
|
|
85
|
+
tokenToId(token: string): Promise<number>;
|
|
86
|
+
}
|
package/src/types/tti.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
|
+
import { ResourceSource } from '../types/common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration properties for the `useTextToImage` hook.
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
9
|
+
export interface TextToImageProps {
|
|
10
|
+
/**
|
|
11
|
+
* Object containing the required model sources for the diffusion pipeline.
|
|
12
|
+
*/
|
|
13
|
+
model: {
|
|
14
|
+
/** Source for the text tokenizer binary/config. */
|
|
15
|
+
tokenizerSource: ResourceSource;
|
|
16
|
+
/** Source for the diffusion scheduler binary/config. */
|
|
17
|
+
schedulerSource: ResourceSource;
|
|
18
|
+
/** Source for the text encoder model binary. */
|
|
19
|
+
encoderSource: ResourceSource;
|
|
20
|
+
/** Source for the UNet (noise predictor) model binary. */
|
|
21
|
+
unetSource: ResourceSource;
|
|
22
|
+
/** Source for the VAE decoder model binary, used to decode the final image. */
|
|
23
|
+
decoderSource: ResourceSource;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Optional callback function that is triggered after each diffusion inference step.
|
|
28
|
+
* Useful for updating a progress bar during image generation.
|
|
29
|
+
* @param stepIdx - The index of the current inference step.
|
|
30
|
+
*/
|
|
31
|
+
inferenceCallback?: (stepIdx: number) => void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Boolean that can prevent automatic model loading (and downloading the data if loaded for the first time) after running the hook.
|
|
35
|
+
* Defaults to `false`.
|
|
36
|
+
*/
|
|
37
|
+
preventLoad?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Return type for the `useTextToImage` hook.
|
|
42
|
+
* Manages the state and operations for generating images from text prompts using a diffusion model pipeline.
|
|
43
|
+
*
|
|
44
|
+
* @category Types
|
|
45
|
+
*/
|
|
46
|
+
export interface TextToImageType {
|
|
47
|
+
/**
|
|
48
|
+
* Contains the error object if any of the pipeline models failed to load, download, or encountered a runtime error.
|
|
49
|
+
*/
|
|
50
|
+
error: RnExecutorchError | null;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Indicates whether the entire diffusion pipeline is loaded into memory and ready for generation.
|
|
54
|
+
*/
|
|
55
|
+
isReady: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Indicates whether the model is currently generating an image.
|
|
59
|
+
*/
|
|
60
|
+
isGenerating: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Represents the total download progress of all the model binaries combined, as a value between 0 and 1.
|
|
64
|
+
*/
|
|
65
|
+
downloadProgress: number;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Runs the diffusion pipeline to generate an image from the provided text prompt.
|
|
69
|
+
* @param input - The text prompt describing the desired image.
|
|
70
|
+
* @param [imageSize] - Optional. The target width and height of the generated image (e.g., 512 for 512x512). Defaults to the model's standard size if omitted.
|
|
71
|
+
* @param [numSteps] - Optional. The number of denoising steps for the diffusion process. More steps generally yield higher quality at the cost of generation time.
|
|
72
|
+
* @param [seed] - Optional. A random seed for reproducible generation. Should be a positive integer.
|
|
73
|
+
* @returns A Promise that resolves to a string representing the generated image (e.g., base64 string or file URI).
|
|
74
|
+
* @throws {RnExecutorchError} If the model is not loaded or is currently generating another image.
|
|
75
|
+
*/
|
|
76
|
+
generate: (
|
|
77
|
+
input: string,
|
|
78
|
+
imageSize?: number,
|
|
79
|
+
numSteps?: number,
|
|
80
|
+
seed?: number
|
|
81
|
+
) => Promise<string>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Interrupts the currently active image generation process at the next available inference step.
|
|
85
|
+
*/
|
|
86
|
+
interrupt: () => void;
|
|
87
|
+
}
|
package/src/types/tts.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ResourceSource } from './common';
|
|
2
|
+
import { RnExecutorchError } from '../errors/errorUtils';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* List all the languages available in TTS models (as lang shorthands)
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
4
9
|
export type TextToSpeechLanguage =
|
|
5
10
|
| 'en-us' // American English
|
|
6
11
|
| 'en-gb'; // British English
|
|
@@ -10,6 +15,7 @@ export type TextToSpeechLanguage =
|
|
|
10
15
|
*
|
|
11
16
|
* So far in Kokoro, each voice is directly associated with a language.
|
|
12
17
|
*
|
|
18
|
+
* @category Types
|
|
13
19
|
* @property {TextToSpeechLanguage} lang - speaker's language
|
|
14
20
|
* @property {ResourceSource} voiceSource - a source to a binary file with voice embedding
|
|
15
21
|
* @property {KokoroVoiceExtras} [extra] - an optional extra sources or properties related to specific voice
|
|
@@ -20,7 +26,13 @@ export interface VoiceConfig {
|
|
|
20
26
|
extra?: KokoroVoiceExtras; // ... add more possible types
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Kokoro-specific voice extra props
|
|
31
|
+
*
|
|
32
|
+
* @category Types
|
|
33
|
+
* @property {ResourceSource} taggerSource - source to Kokoro's tagger model binary
|
|
34
|
+
* @property {ResourceSource} lexiconSource - source to Kokoro's lexicon binary
|
|
35
|
+
*/
|
|
24
36
|
export interface KokoroVoiceExtras {
|
|
25
37
|
taggerSource: ResourceSource;
|
|
26
38
|
lexiconSource: ResourceSource;
|
|
@@ -29,6 +41,11 @@ export interface KokoroVoiceExtras {
|
|
|
29
41
|
/**
|
|
30
42
|
* Kokoro model configuration.
|
|
31
43
|
* Only the core Kokoro model sources, as phonemizer sources are included in voice configuration.
|
|
44
|
+
*
|
|
45
|
+
* @category Types
|
|
46
|
+
* @property {'kokoro'} type - model type identifier
|
|
47
|
+
* @property {ResourceSource} durationPredictorSource - source to Kokoro's duration predictor model binary
|
|
48
|
+
* @property {ResourceSource} synthesizerSource - source to Kokoro's synthesizer model binary
|
|
32
49
|
*/
|
|
33
50
|
export interface KokoroConfig {
|
|
34
51
|
type: 'kokoro';
|
|
@@ -39,6 +56,7 @@ export interface KokoroConfig {
|
|
|
39
56
|
/**
|
|
40
57
|
* General Text to Speech module configuration
|
|
41
58
|
*
|
|
59
|
+
* @category Types
|
|
42
60
|
* @property {KokoroConfig} model - a selected T2S model
|
|
43
61
|
* @property {VoiceConfig} voice - a selected speaker's voice
|
|
44
62
|
* @property {KokoroOptions} [options] - a completely optional model-specific configuration
|
|
@@ -48,9 +66,22 @@ export interface TextToSpeechConfig {
|
|
|
48
66
|
voice: VoiceConfig;
|
|
49
67
|
}
|
|
50
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Props for the useTextToSpeech hook.
|
|
71
|
+
*
|
|
72
|
+
* @category Types
|
|
73
|
+
* @extends TextToSpeechConfig
|
|
74
|
+
*
|
|
75
|
+
* @property {boolean} [preventLoad] - Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
|
|
76
|
+
*/
|
|
77
|
+
export interface TextToSpeechProps extends TextToSpeechConfig {
|
|
78
|
+
preventLoad?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
51
81
|
/**
|
|
52
82
|
* Text to Speech module input definition
|
|
53
83
|
*
|
|
84
|
+
* @category Types
|
|
54
85
|
* @property {string} text - a text to be spoken
|
|
55
86
|
* @property {number} [speed] - optional speed argument - the higher it is, the faster the speech becomes
|
|
56
87
|
*/
|
|
@@ -59,6 +90,56 @@ export interface TextToSpeechInput {
|
|
|
59
90
|
speed?: number;
|
|
60
91
|
}
|
|
61
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Return type for the `useTextToSpeech` hook.
|
|
95
|
+
* Manages the state and operations for Text-to-Speech generation.
|
|
96
|
+
*
|
|
97
|
+
* @category Types
|
|
98
|
+
*/
|
|
99
|
+
export interface TextToSpeechType {
|
|
100
|
+
/**
|
|
101
|
+
* Contains the error object if the model failed to load or encountered an error during inference.
|
|
102
|
+
*/
|
|
103
|
+
error: RnExecutorchError | null;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Indicates whether the Text-to-Speech model is loaded and ready to accept inputs.
|
|
107
|
+
*/
|
|
108
|
+
isReady: boolean;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Indicates whether the model is currently generating audio.
|
|
112
|
+
*/
|
|
113
|
+
isGenerating: boolean;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Represents the download progress of the model and voice assets as a value between 0 and 1.
|
|
117
|
+
*/
|
|
118
|
+
downloadProgress: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Runs the model to convert the provided text into speech audio in a single pass.
|
|
122
|
+
* * @param input - The `TextToSpeechInput` object containing the `text` to synthesize and optional `speed`.
|
|
123
|
+
* @returns A Promise that resolves with the generated audio data (typically a `Float32Array`).
|
|
124
|
+
* @throws {RnExecutorchError} If the model is not loaded or is currently generating.
|
|
125
|
+
*/
|
|
126
|
+
forward: (input: TextToSpeechInput) => Promise<Float32Array>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Streams the generated audio data incrementally.
|
|
130
|
+
* This is optimal for real-time playback, allowing audio to start playing before the full text is synthesized.
|
|
131
|
+
* * @param input - The `TextToSpeechStreamingInput` object containing `text`, optional `speed`, and lifecycle callbacks (`onBegin`, `onNext`, `onEnd`).
|
|
132
|
+
* @returns A Promise that resolves when the streaming process is complete.
|
|
133
|
+
* @throws {RnExecutorchError} If the model is not loaded or is currently generating.
|
|
134
|
+
*/
|
|
135
|
+
stream: (input: TextToSpeechStreamingInput) => Promise<void>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Interrupts and stops the currently active audio generation stream.
|
|
139
|
+
*/
|
|
140
|
+
streamStop: () => void;
|
|
141
|
+
}
|
|
142
|
+
|
|
62
143
|
/**
|
|
63
144
|
* Text to Speech streaming input definition
|
|
64
145
|
*
|
|
@@ -66,6 +147,8 @@ export interface TextToSpeechInput {
|
|
|
66
147
|
* executed at given moments of the streaming.
|
|
67
148
|
* Actions such as playing the audio should happen within the onNext callback.
|
|
68
149
|
* Callbacks can be both synchronous or asynchronous.
|
|
150
|
+
*
|
|
151
|
+
* @category Types
|
|
69
152
|
* @property {() => void | Promise<void>} [onBegin] - Called when streaming begins
|
|
70
153
|
* @property {(audio: Float32Array) => void | Promise<void>} [onNext] - Called after each audio chunk gets calculated.
|
|
71
154
|
* @property {() => void | Promise<void>} [onEnd] - Called when streaming ends
|