Skip to content

Commit ae72c0d

Browse files
committed
fetch latest phonemis version
1 parent 89bdd17 commit ae72c0d

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎apps/speech/screens/SpeechToTextScreen.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const SpeechToTextScreen = ({ onBack }: { onBack: () => void }) => {
5353

5454
const model = useSpeechToText({
5555
model: selectedModel,
56-
vad: vad.fsmn_vad()
56+
vad: vad.fsmn_vad(),
5757
});
5858

5959
const [transcription, setTranscription] =
@@ -117,7 +117,6 @@ export const SpeechToTextScreen = ({ onBack }: { onBack: () => void }) => {
117117

118118
Keyboard.dismiss();
119119

120-
const uri = await getAudioFile(audioURL);
121120
// Reset previous states
122121
setTranscription(null);
123122
setLiveResult(null);

‎docs/docs/04-typescript-api/01-natural-language-processing/SpeechToTextModule.md‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ The `SpeechToTextModule` class provides a direct interface to the library's spee
1414
You can transcribe audio in two ways: **one-shot** (for files/short clips) and **streaming** (for live microphone input).
1515

1616
```typescript
17-
import {
18-
SpeechToTextModule,
19-
WHISPER_TINY_EN,
20-
FSMN_VAD,
21-
} from 'react-native-executorch';
17+
import { SpeechToTextModule, models } from 'react-native-executorch';
2218

2319
// Initialize the model with VAD submodule
2420
const model = await SpeechToTextModule.fromModelName(
25-
WHISPER_TINY_EN,
26-
FSMN_VAD, // Optional VAD submodule
21+
models.speech_to_text.whisper_tiny_en(),
22+
models.vad.fsmn_vad(), // Optional VAD submodule
2723
(progress) => {
2824
console.log(`Loading: ${progress * 100}%`);
2925
}
@@ -90,14 +86,13 @@ The `stream()` function accepts several optional parameters:
9086
In this example, we use [`react-native-audio-api`](https://docs.swmansion.com/react-native-audio-api/) to feed live audio into the model.
9187

9288
```tsx
93-
import {
94-
SpeechToTextModule,
95-
WHISPER_TINY_EN,
96-
FSMN_VAD,
97-
} from 'react-native-executorch';
89+
import { SpeechToTextModule, models } from 'react-native-executorch';
9890
import { AudioManager, AudioRecorder } from 'react-native-audio-api';
9991

100-
const model = await SpeechToTextModule.fromModelName(WHISPER_TINY_EN, FSMN_VAD);
92+
const model = await SpeechToTextModule.fromModelName(
93+
models.speech_to_text.whisper_tiny_en(),
94+
models.vad.fsmn_vad()
95+
);
10196

10297
// 1. Configure audio session & permissions
10398
AudioManager.setAudioSessionOptions({
@@ -150,8 +145,8 @@ To use it, provide the VAD model configuration when loading the module and enabl
150145

151146
```typescript
152147
const model = await SpeechToTextModule.fromModelName(
153-
WHISPER_TINY_EN,
154-
FSMN_VAD // Optional VAD submodule
148+
models.speech_to_text.whisper_tiny_en(),
149+
models.vad.fsmn_vad()
155150
);
156151

157152
// Enable VAD logic in the stream context

‎packages/react-native-executorch/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.cpp‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,16 @@ void VoiceActivityDetection::stream(std::shared_ptr<jsi::Function> callback,
142142
// Send result to the JS side.
143143
nativeCallback(speaking);
144144

145-
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
145+
std::unique_lock<std::mutex> lock(streamCvMutex_);
146+
streamCv_.wait_for(lock, std::chrono::milliseconds(timeout),
147+
[this] { return !isStreaming_.load(); });
146148
}
147149
}
148150

149-
void VoiceActivityDetection::streamStop() { isStreaming_ = false; }
151+
void VoiceActivityDetection::streamStop() {
152+
isStreaming_ = false;
153+
streamCv_.notify_all();
154+
}
150155

151156
void VoiceActivityDetection::streamInsert(std::span<float> audio) {
152157
std::scoped_lock lock(audioBufferMutex_);

‎packages/react-native-executorch/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <condition_variable>
34
#include <cstddef>
45
#include <executorch/extension/module/module.h>
56
#include <executorch/extension/tensor/tensor.h>
@@ -64,6 +65,8 @@ class VoiceActivityDetection : public BaseModel {
6465
mutable std::mutex audioBufferMutex_;
6566
// Streaming state
6667
std::atomic<bool> isStreaming_ = false;
68+
std::condition_variable streamCv_;
69+
std::mutex streamCvMutex_;
6770
};
6871

6972
} // namespace models::voice_activity_detection

0 commit comments

Comments
 (0)