Skip to content

Commit 151d62d

Browse files
mkopcinsmichaldudekMateusz Kopciński
authored
chore: 0.5.11 (#649)
Bump to 0.5.11 S2T bug fix --------- Co-authored-by: Michał Pałys-Dudek <michal@pnd.io> Co-authored-by: Mateusz Kopciński <mateusz.kopcinski@swmansnion.com>
1 parent 6fa4139 commit 151d62d

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

docs/docs/02-hooks/01-natural-language-processing/useSpeechToText.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ For more information on loading resources, take a look at [loading models](../..
7878
| Field | Type | Description |
7979
| --------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8080
| `transcribe` | `(waveform: Float32Array \| number[], options?: DecodingOptions \| undefined) => Promise<string>` | Starts a transcription process for a given input array, which should be a waveform at 16kHz. The second argument is an options object, e.g. `{ language: 'es' }` for multilingual models. Resolves a promise with the output transcription when the model is finished. Passing `number[]` is deprecated. |
81-
| `stream` | `() => Promise<string>` | Starts a streaming transcription process. Use in combination with `streamInsert` to feed audio chunks and `streamStop` to end the stream. Updates `committedTranscription` and `nonCommittedTranscription` as transcription progresses. |
82-
| `streamInsert` | `(waveform: Float32Array \| number[]) => Promise<void>` | Inserts a chunk of audio data (sampled at 16kHz) into the ongoing streaming transcription. Call this repeatedly as new audio data becomes available. Passing `number[]` is deprecated. |
83-
| `streamStop` | `() => Promise<void>` | Stops the ongoing streaming transcription process. |
81+
| `stream` | `(options?: DecodingOptions \| undefined) => Promise<string>` | Starts a streaming transcription process. Use in combination with `streamInsert` to feed audio chunks and `streamStop` to end the stream. The argument is an options object, e.g. `{ language: 'es' }` for multilingual models. Updates `committedTranscription` and `nonCommittedTranscription` as transcription progresses. |
82+
| `streamInsert` | `(waveform: Float32Array \| number[]) => void` | Inserts a chunk of audio data (sampled at 16kHz) into the ongoing streaming transcription. Call this repeatedly as new audio data becomes available. Passing `number[]` is deprecated. |
83+
| `streamStop` | `() => void` | Stops the ongoing streaming transcription process. |
8484
| `encode` | `(waveform: Float32Array \| number[]) => Promise<Float32Array>` | Runs the encoding part of the model on the provided waveform. Passing `number[]` is deprecated. |
8585
| `decode` | `(tokens: number[] \| Int32Array, encoderOutput: Float32Array \| number[]) => Promise<Float32Array>` | Runs the decoder of the model. Passing `number[]` is deprecated. |
8686
| `committedTranscription` | `string` | Contains the part of the transcription that is finalized and will not change. Useful for displaying stable results during streaming. |

packages/react-native-executorch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-executorch",
3-
"version": "0.5.10",
3+
"version": "0.5.11",
44
"description": "An easy way to run AI models in React Native with ExecuTorch",
55
"source": "./src/index.ts",
66
"main": "./lib/module/index.js",

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useCallback, useState } from 'react';
22
import { ETError, getError } from '../../Error';
33
import { SpeechToTextModule } from '../../modules/natural_language_processing/SpeechToTextModule';
4-
import { SpeechToTextModelConfig } from '../../types/stt';
4+
import { DecodingOptions, SpeechToTextModelConfig } from '../../types/stt';
55

66
export const useSpeechToText = ({
77
model,
@@ -65,24 +65,29 @@ export const useSpeechToText = ({
6565
[isReady, isGenerating, modelInstance]
6666
);
6767

68-
const stream = useCallback(async () => {
69-
if (!isReady) throw new Error(getError(ETError.ModuleNotLoaded));
70-
if (isGenerating) throw new Error(getError(ETError.ModelGenerating));
71-
setIsGenerating(true);
72-
setCommittedTranscription('');
73-
setNonCommittedTranscription('');
74-
let transcription = '';
75-
try {
76-
for await (const { committed, nonCommitted } of modelInstance.stream()) {
77-
setCommittedTranscription((prev) => prev + committed);
78-
setNonCommittedTranscription(nonCommitted);
79-
transcription += committed;
68+
const stream = useCallback(
69+
async (options?: DecodingOptions) => {
70+
if (!isReady) throw new Error(getError(ETError.ModuleNotLoaded));
71+
if (isGenerating) throw new Error(getError(ETError.ModelGenerating));
72+
setIsGenerating(true);
73+
setCommittedTranscription('');
74+
setNonCommittedTranscription('');
75+
let transcription = '';
76+
try {
77+
for await (const { committed, nonCommitted } of modelInstance.stream(
78+
options
79+
)) {
80+
setCommittedTranscription((prev) => prev + committed);
81+
setNonCommittedTranscription(nonCommitted);
82+
transcription += committed;
83+
}
84+
} finally {
85+
setIsGenerating(false);
8086
}
81-
} finally {
82-
setIsGenerating(false);
83-
}
84-
return transcription;
85-
}, [isReady, isGenerating, modelInstance]);
87+
return transcription;
88+
},
89+
[isReady, isGenerating, modelInstance]
90+
);
8691

8792
const wrapper = useCallback(
8893
<T extends (...args: any[]) => any>(fn: T) => {

0 commit comments

Comments
 (0)