Skip to content

Commit 98ccf0b

Browse files
committed
Enhance VAD and part of TTS documentation
1 parent 2188c61 commit 98ccf0b

File tree

7 files changed

+79
-17
lines changed

7 files changed

+79
-17
lines changed

packages/react-native-executorch/src/hooks/natural_language_processing/useTextEmbeddings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { TextEmbeddingsModule } from '../../modules/natural_language_processing/TextEmbeddingsModule';
22
import { useModule } from '../useModule';
3-
import { TextEmbeddingsType, Props } from '../../types/textEmbeddings';
3+
import { TextEmbeddingsType, TextEmbeddingsProps } from '../../types/textEmbeddings';
44

55
/**
66
* React hook for managing a Text Embeddings model instance.
77
*
88
* @param TextEmbeddingsConfiguration - Configuration object containing `model` source and optional `preventLoad` flag.
99
* @returns Ready to use Text Embeddings model.
1010
*/
11-
export const useTextEmbeddings = ({ model, preventLoad = false }: Props): TextEmbeddingsType =>
11+
export const useTextEmbeddings = ({ model, preventLoad = false }: TextEmbeddingsProps): TextEmbeddingsType =>
1212
useModule({
1313
module: TextEmbeddingsModule,
1414
model,

packages/react-native-executorch/src/hooks/natural_language_processing/useTextToSpeech.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ interface Props extends TextToSpeechConfig {
1212
preventLoad?: boolean;
1313
}
1414

15+
16+
/**
17+
* React hook for managing Text to Speech instance.
18+
*
19+
* @param TextToSpeechConfiguration - Configuration object containing `model` source, `voice` and optional `preventLoad`.
20+
* @returns Ready to use Text to Speech model.
21+
*/
1522
export const useTextToSpeech = ({
1623
model,
1724
voice,

packages/react-native-executorch/src/hooks/natural_language_processing/useTokenizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { RnExecutorchError, parseUnknownError } from '../../errors/errorUtils';
66
import { TokenizerType } from '../../types/tokenizer';
77

88
/**
9+
* React hook for managing a Tokenizer instance.
910
*
1011
* @param tokenizerConfiguration - Configuration object containing `tokenizer` source and optional `preventLoad` flag.
1112
* @returns Ready to use Tokenizer model.

packages/react-native-executorch/src/hooks/natural_language_processing/useVAD.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { ResourceSource } from '../../types/common';
21
import { useModule } from '../useModule';
32
import { VADModule } from '../../modules/natural_language_processing/VADModule';
3+
import { VADType, VADProps } from '../../types/vad';
44

5-
interface Props {
6-
model: { modelSource: ResourceSource };
7-
preventLoad?: boolean;
8-
}
9-
10-
export const useVAD = ({ model, preventLoad = false }: Props) =>
5+
/**
6+
* React hook for managing a VAD model instance.
7+
*
8+
* @param VADConfiguration - Configuration object containing `model` source and optional `preventLoad` flag.
9+
* @returns Ready to use VAD model.
10+
*/
11+
export const useVAD = ({ model, preventLoad = false }: VADProps): VADType =>
1112
useModule({
1213
module: VADModule,
1314
model,

packages/react-native-executorch/src/hooks/useModule.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ export const useModule = <
9393
* Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval.
9494
*/
9595
downloadProgress,
96-
97-
/**
98-
* This function runs the model's forward method with the provided input arguments.
99-
*
100-
* @param input - Input arguments for the model's forward method.
101-
* @returns The output from the model's forward method.
102-
*/
10396
forward,
10497
};
10598
};

packages/react-native-executorch/src/types/textEmbeddings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface TextEmbeddingsType {
3636
/**
3737
* Props for the useTextEmbeddings hook.
3838
*/
39-
export interface Props {
39+
export interface TextEmbeddingsProps {
4040
model: {
4141
/**
4242
* `ResourceSource` that specifies the location of the model binary.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,64 @@
1+
import { ResourceSource } from '../types/common';
2+
import { RnExecutorchError } from '../errors/errorUtils';
3+
4+
/**
5+
* Props for the useVAD hook.
6+
*/
7+
export interface VADProps {
8+
/**
9+
* `ResourceSource` that specifies the location of the VAD model binary.
10+
*/
11+
model: { modelSource: ResourceSource };
12+
13+
/**
14+
* Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
15+
*/
16+
preventLoad?: boolean;
17+
}
18+
19+
/**
20+
* Represents a detected audio segment with start and end timestamps.
21+
*/
122
export interface Segment {
23+
/**
24+
* Start time of the segment in seconds.
25+
*/
226
start: number;
27+
28+
/**
29+
* End time of the segment in seconds.
30+
*/
331
end: number;
432
}
33+
34+
/**
35+
* React hook state and methods for managing a Voice Activity Detection (VAD) model instance.
36+
*/
37+
export interface VADType {
38+
/**
39+
* Contains the error message if the VAD model failed to load or during processing.
40+
*/
41+
error: null | RnExecutorchError;
42+
43+
/**
44+
* Indicates whether the VAD model has successfully loaded and is ready for inference.
45+
*/
46+
isReady: boolean;
47+
48+
/**
49+
* Indicates whether the model is currently processing an inference.
50+
*/
51+
isGenerating: boolean;
52+
53+
/**
54+
* Represents the download progress as a value between 0 and 1.
55+
*/
56+
downloadProgress: number;
57+
58+
/**
59+
* Runs the Voice Activity Detection model on the provided audio waveform.
60+
* @param waveform - The input audio waveform array.
61+
* @returns A promise resolving to an array of detected audio segments (e.g., timestamps for speech).
62+
*/
63+
forward(waveform: Float32Array): Promise<Segment[]>;
64+
}

0 commit comments

Comments
 (0)