whisper.rn 0.3.0-rc.4 → 0.3.0-rc.5
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 -3
- package/android/build.gradle +9 -0
- package/android/src/main/java/com/rnwhisper/RNWhisperPackage.java +33 -13
- package/android/src/main/jni/whisper/Whisper.mk +1 -1
- package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +232 -0
- package/ios/RNWhisper.mm +23 -2
- package/lib/commonjs/NativeRNWhisper.js +10 -0
- package/lib/commonjs/NativeRNWhisper.js.map +1 -0
- package/lib/commonjs/index.js +21 -22
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRNWhisper.js +3 -0
- package/lib/module/NativeRNWhisper.js.map +1 -0
- package/lib/module/index.js +12 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRNWhisper.d.ts +55 -0
- package/lib/typescript/NativeRNWhisper.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +4 -41
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/NativeRNWhisper.ts +67 -0
- package/src/index.ts +10 -60
- /package/android/src/{main → oldarch}/java/com/rnwhisper/RNWhisperModule.java +0 -0
package/README.md
CHANGED
|
@@ -47,8 +47,8 @@ Add the following line to ```android/app/src/main/AndroidManifest.xml```
|
|
|
47
47
|
import { initWhisper } from 'whisper.rn'
|
|
48
48
|
|
|
49
49
|
const whisperContext = await initWhisper({
|
|
50
|
-
filePath: 'file://.../ggml-
|
|
51
|
-
isBundleAsset: false, // Set to true if you want to load the model from bundle resources, the filePath will be like `ggml-
|
|
50
|
+
filePath: 'file://.../ggml-tiny.en.bin',
|
|
51
|
+
isBundleAsset: false, // Set to true if you want to load the model from bundle resources, the filePath will be like `ggml-tiny.en.bin`
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
const sampleFilePath = 'file://.../sample.wav'
|
|
@@ -87,7 +87,7 @@ __*Platform: iOS 15.0+, tvOS 15.0+*__
|
|
|
87
87
|
|
|
88
88
|
To use Core ML on iOS, you will need to have the Core ML model files.
|
|
89
89
|
|
|
90
|
-
The `.mlmodelc` model files is load depend on the ggml model file path. For example, if your ggml model path is `ggml-
|
|
90
|
+
The `.mlmodelc` model files is load depend on the ggml model file path. For example, if your ggml model path is `ggml-tiny.en.bin`, the Core ML model path will be `ggml-tiny.en-encoder.mlmodelc`. Please note that the ggml model is still needed as decoder or encoder fallback.
|
|
91
91
|
|
|
92
92
|
Currently there is no official way to get the Core ML models by URL, you will need to convert Core ML models by yourself. Please see [Core ML Support](https://github.com/ggerganov/whisper.cpp#core-ml-support) of whisper.cpp for more details.
|
|
93
93
|
|
package/android/build.gradle
CHANGED
|
@@ -59,6 +59,15 @@ android {
|
|
|
59
59
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
sourceSets {
|
|
63
|
+
main {
|
|
64
|
+
if (isNewArchitectureEnabled()) {
|
|
65
|
+
java.srcDirs += ['src/newarch']
|
|
66
|
+
} else {
|
|
67
|
+
java.srcDirs += ['src/oldarch']
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
repositories {
|
|
@@ -1,28 +1,48 @@
|
|
|
1
1
|
package com.rnwhisper;
|
|
2
2
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
4
5
|
|
|
5
|
-
import com.facebook.react.ReactPackage;
|
|
6
6
|
import com.facebook.react.bridge.NativeModule;
|
|
7
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
10
|
+
import com.facebook.react.TurboReactPackage;
|
|
9
11
|
|
|
10
|
-
import java.util.ArrayList;
|
|
11
|
-
import java.util.Collections;
|
|
12
12
|
import java.util.List;
|
|
13
|
+
import java.util.HashMap;
|
|
14
|
+
import java.util.Map;
|
|
13
15
|
|
|
14
|
-
public class RNWhisperPackage
|
|
15
|
-
|
|
16
|
+
public class RNWhisperPackage extends TurboReactPackage {
|
|
17
|
+
|
|
18
|
+
@Nullable
|
|
16
19
|
@Override
|
|
17
|
-
public
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
21
|
+
if (name.equals(RNWhisperModule.NAME)) {
|
|
22
|
+
return new com.rnwhisper.RNWhisperModule(reactContext);
|
|
23
|
+
} else {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
@NonNull
|
|
24
28
|
@Override
|
|
25
|
-
public
|
|
26
|
-
return
|
|
29
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
30
|
+
return () -> {
|
|
31
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
32
|
+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
33
|
+
moduleInfos.put(
|
|
34
|
+
RNWhisperModule.NAME,
|
|
35
|
+
new ReactModuleInfo(
|
|
36
|
+
RNWhisperModule.NAME,
|
|
37
|
+
RNWhisperModule.NAME,
|
|
38
|
+
false, // canOverrideExistingModule
|
|
39
|
+
false, // needsEagerInit
|
|
40
|
+
true, // hasConstants
|
|
41
|
+
false, // isCxxModule
|
|
42
|
+
isTurboModule // isTurboModule
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
return moduleInfos;
|
|
46
|
+
};
|
|
27
47
|
}
|
|
28
48
|
}
|
|
@@ -3,7 +3,7 @@ LOCAL_LDLIBS := -landroid -llog
|
|
|
3
3
|
|
|
4
4
|
# Make the final output library smaller by only keeping the symbols referenced from the app.
|
|
5
5
|
ifneq ($(APP_OPTIM),debug)
|
|
6
|
-
LOCAL_CFLAGS += -O3
|
|
6
|
+
LOCAL_CFLAGS += -O3 -DNDEBUG
|
|
7
7
|
LOCAL_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
|
|
8
8
|
LOCAL_CFLAGS += -ffunction-sections -fdata-sections
|
|
9
9
|
LOCAL_LDFLAGS += -Wl,--gc-sections
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
package com.rnwhisper;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import android.os.Handler;
|
|
7
|
+
import android.os.AsyncTask;
|
|
8
|
+
import android.media.AudioRecord;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.bridge.Promise;
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
13
|
+
import com.facebook.react.bridge.LifecycleEventListener;
|
|
14
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
15
|
+
import com.facebook.react.bridge.WritableMap;
|
|
16
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
17
|
+
|
|
18
|
+
import java.util.HashMap;
|
|
19
|
+
import java.util.Random;
|
|
20
|
+
|
|
21
|
+
@ReactModule(name = RNWhisperModule.NAME)
|
|
22
|
+
public class RNWhisperModule extends NativeRNWhisperSpec implements LifecycleEventListener {
|
|
23
|
+
public static final String NAME = "RNWhisper";
|
|
24
|
+
|
|
25
|
+
private ReactApplicationContext reactContext;
|
|
26
|
+
|
|
27
|
+
public RNWhisperModule(ReactApplicationContext reactContext) {
|
|
28
|
+
super(reactContext);
|
|
29
|
+
reactContext.addLifecycleEventListener(this);
|
|
30
|
+
this.reactContext = reactContext;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
@NonNull
|
|
35
|
+
public String getName() {
|
|
36
|
+
return NAME;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public HashMap<String, Object> getTypedExportedConstants() {
|
|
41
|
+
HashMap<String, Object> constants = new HashMap<>();
|
|
42
|
+
|
|
43
|
+
// iOS only constants, put for passing type checks
|
|
44
|
+
constants.put("useCoreML", false);
|
|
45
|
+
constants.put("coreMLAllowFallback", false);
|
|
46
|
+
|
|
47
|
+
return constants;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private HashMap<Integer, WhisperContext> contexts = new HashMap<>();
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
public void initContext(final String modelPath, final boolean isBundleAsset, final Promise promise) {
|
|
54
|
+
new AsyncTask<Void, Void, Integer>() {
|
|
55
|
+
private Exception exception;
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
protected Integer doInBackground(Void... voids) {
|
|
59
|
+
try {
|
|
60
|
+
long context;
|
|
61
|
+
if (isBundleAsset) {
|
|
62
|
+
context = WhisperContext.initContextWithAsset(reactContext.getAssets(), modelPath);
|
|
63
|
+
} else {
|
|
64
|
+
context = WhisperContext.initContext(modelPath);
|
|
65
|
+
}
|
|
66
|
+
if (context == 0) {
|
|
67
|
+
throw new Exception("Failed to initialize context");
|
|
68
|
+
}
|
|
69
|
+
int id = Math.abs(new Random().nextInt());
|
|
70
|
+
WhisperContext whisperContext = new WhisperContext(id, reactContext, context);
|
|
71
|
+
contexts.put(id, whisperContext);
|
|
72
|
+
return id;
|
|
73
|
+
} catch (Exception e) {
|
|
74
|
+
exception = e;
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
protected void onPostExecute(Integer id) {
|
|
81
|
+
if (exception != null) {
|
|
82
|
+
promise.reject(exception);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
promise.resolve(id);
|
|
86
|
+
}
|
|
87
|
+
}.execute();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ReactMethod
|
|
91
|
+
public void transcribeFile(double id, double jobId, String filePath, ReadableMap options, Promise promise) {
|
|
92
|
+
final WhisperContext context = contexts.get((int) id);
|
|
93
|
+
if (context == null) {
|
|
94
|
+
promise.reject("Context not found");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (context.isCapturing()) {
|
|
98
|
+
promise.reject("The context is in realtime transcribe mode");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (context.isTranscribing()) {
|
|
102
|
+
promise.reject("Context is already transcribing");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
new AsyncTask<Void, Void, WritableMap>() {
|
|
106
|
+
private Exception exception;
|
|
107
|
+
|
|
108
|
+
@Override
|
|
109
|
+
protected WritableMap doInBackground(Void... voids) {
|
|
110
|
+
try {
|
|
111
|
+
return context.transcribeFile((int) jobId, filePath, options);
|
|
112
|
+
} catch (Exception e) {
|
|
113
|
+
exception = e;
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Override
|
|
119
|
+
protected void onPostExecute(WritableMap data) {
|
|
120
|
+
if (exception != null) {
|
|
121
|
+
promise.reject(exception);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
promise.resolve(data);
|
|
125
|
+
}
|
|
126
|
+
}.execute();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
public void startRealtimeTranscribe(double id, double jobId, ReadableMap options, Promise promise) {
|
|
131
|
+
final WhisperContext context = contexts.get((int) id);
|
|
132
|
+
if (context == null) {
|
|
133
|
+
promise.reject("Context not found");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (context.isCapturing()) {
|
|
137
|
+
promise.reject("Context is already in capturing");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
int state = context.startRealtimeTranscribe((int) jobId, options);
|
|
141
|
+
if (state == AudioRecord.STATE_INITIALIZED) {
|
|
142
|
+
promise.resolve(null);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
promise.reject("Failed to start realtime transcribe. State: " + state);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
public void abortTranscribe(double contextId, double jobId, Promise promise) {
|
|
150
|
+
WhisperContext context = contexts.get((int) contextId);
|
|
151
|
+
if (context == null) {
|
|
152
|
+
promise.reject("Context not found");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
context.stopTranscribe((int) jobId);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@ReactMethod
|
|
159
|
+
public void releaseContext(double id, Promise promise) {
|
|
160
|
+
final int contextId = (int) id;
|
|
161
|
+
new AsyncTask<Void, Void, Void>() {
|
|
162
|
+
private Exception exception;
|
|
163
|
+
|
|
164
|
+
@Override
|
|
165
|
+
protected Void doInBackground(Void... voids) {
|
|
166
|
+
try {
|
|
167
|
+
WhisperContext context = contexts.get(contextId);
|
|
168
|
+
if (context == null) {
|
|
169
|
+
throw new Exception("Context " + id + " not found");
|
|
170
|
+
}
|
|
171
|
+
context.release();
|
|
172
|
+
contexts.remove(contextId);
|
|
173
|
+
} catch (Exception e) {
|
|
174
|
+
exception = e;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@Override
|
|
180
|
+
protected void onPostExecute(Void result) {
|
|
181
|
+
if (exception != null) {
|
|
182
|
+
promise.reject(exception);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
promise.resolve(null);
|
|
186
|
+
}
|
|
187
|
+
}.execute();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@ReactMethod
|
|
191
|
+
public void releaseAllContexts(Promise promise) {
|
|
192
|
+
new AsyncTask<Void, Void, Void>() {
|
|
193
|
+
private Exception exception;
|
|
194
|
+
|
|
195
|
+
@Override
|
|
196
|
+
protected Void doInBackground(Void... voids) {
|
|
197
|
+
try {
|
|
198
|
+
onHostDestroy();
|
|
199
|
+
} catch (Exception e) {
|
|
200
|
+
exception = e;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@Override
|
|
206
|
+
protected void onPostExecute(Void result) {
|
|
207
|
+
if (exception != null) {
|
|
208
|
+
promise.reject(exception);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
promise.resolve(null);
|
|
212
|
+
}
|
|
213
|
+
}.execute();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@Override
|
|
217
|
+
public void onHostResume() {
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@Override
|
|
221
|
+
public void onHostPause() {
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@Override
|
|
225
|
+
public void onHostDestroy() {
|
|
226
|
+
WhisperContext.abortAllTranscribe();
|
|
227
|
+
for (WhisperContext context : contexts.values()) {
|
|
228
|
+
context.release();
|
|
229
|
+
}
|
|
230
|
+
contexts.clear();
|
|
231
|
+
}
|
|
232
|
+
}
|
package/ios/RNWhisper.mm
CHANGED
|
@@ -3,20 +3,33 @@
|
|
|
3
3
|
#include <stdlib.h>
|
|
4
4
|
#include <string>
|
|
5
5
|
|
|
6
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
7
|
+
#import <RNWhisperSpec/RNWhisperSpec.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
6
10
|
@implementation RNWhisper
|
|
7
11
|
|
|
8
12
|
NSMutableDictionary *contexts;
|
|
9
13
|
|
|
10
14
|
RCT_EXPORT_MODULE()
|
|
11
15
|
|
|
16
|
+
+ (BOOL)requiresMainQueueSetup
|
|
17
|
+
{
|
|
18
|
+
return YES;
|
|
19
|
+
}
|
|
20
|
+
|
|
12
21
|
- (NSDictionary *)constantsToExport
|
|
13
22
|
{
|
|
14
23
|
return @{
|
|
15
24
|
#if WHISPER_USE_COREML
|
|
16
|
-
@"
|
|
25
|
+
@"useCoreML": @YES,
|
|
26
|
+
#else
|
|
27
|
+
@"useCoreML": @NO,
|
|
17
28
|
#endif
|
|
18
29
|
#if WHISPER_COREML_ALLOW_FALLBACK
|
|
19
|
-
@"
|
|
30
|
+
@"coreMLAllowFallback": @YES,
|
|
31
|
+
#else
|
|
32
|
+
@"coreMLAllowFallback": @NO,
|
|
20
33
|
#endif
|
|
21
34
|
};
|
|
22
35
|
}
|
|
@@ -208,4 +221,12 @@ RCT_REMAP_METHOD(releaseAllContexts,
|
|
|
208
221
|
contexts = nil;
|
|
209
222
|
}
|
|
210
223
|
|
|
224
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
225
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
226
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
227
|
+
{
|
|
228
|
+
return std::make_shared<facebook::react::NativeRNWhisperSpecJSI>(params);
|
|
229
|
+
}
|
|
230
|
+
#endif
|
|
231
|
+
|
|
211
232
|
@end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = _reactNative.TurboModuleRegistry.get('RNWhisper');
|
|
9
|
+
exports.default = _default;
|
|
10
|
+
//# sourceMappingURL=NativeRNWhisper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","TurboModuleRegistry","get","exports","default"],"sourceRoot":"../../src","sources":["NativeRNWhisper.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAkD,IAAAC,QAAA,GAiEnCC,gCAAmB,CAACC,GAAG,CAAO,WAAW,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAJ,QAAA"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -8,19 +8,14 @@ exports.initWhisper = initWhisper;
|
|
|
8
8
|
exports.libVersion = exports.isUseCoreML = exports.isCoreMLAllowFallback = void 0;
|
|
9
9
|
exports.releaseAllWhisper = releaseAllWhisper;
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
|
+
var _NativeRNWhisper = _interopRequireDefault(require("./NativeRNWhisper"));
|
|
11
12
|
var _version = require("./version.json");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
default: ''
|
|
15
|
-
})}- You rebuilt the app after installing the package`;
|
|
16
|
-
const RNWhisper = _reactNative.NativeModules.RNWhisper ? _reactNative.NativeModules.RNWhisper : new Proxy({}, {
|
|
17
|
-
get() {
|
|
18
|
-
throw new Error(LINKING_ERROR);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
13
|
+
var _RNWhisper$getConstan;
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
15
|
let EventEmitter;
|
|
22
16
|
if (_reactNative.Platform.OS === 'ios') {
|
|
23
|
-
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
EventEmitter = new _reactNative.NativeEventEmitter(_NativeRNWhisper.default);
|
|
24
19
|
}
|
|
25
20
|
if (_reactNative.Platform.OS === 'android') {
|
|
26
21
|
EventEmitter = _reactNative.DeviceEventEmitter;
|
|
@@ -37,8 +32,8 @@ class WhisperContext {
|
|
|
37
32
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
38
33
|
const jobId = Math.floor(Math.random() * 10000);
|
|
39
34
|
return {
|
|
40
|
-
stop: () =>
|
|
41
|
-
promise:
|
|
35
|
+
stop: () => _NativeRNWhisper.default.abortTranscribe(this.id, jobId),
|
|
36
|
+
promise: _NativeRNWhisper.default.transcribeFile(this.id, jobId, path, options)
|
|
42
37
|
};
|
|
43
38
|
}
|
|
44
39
|
|
|
@@ -46,7 +41,7 @@ class WhisperContext {
|
|
|
46
41
|
async transcribeRealtime() {
|
|
47
42
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
48
43
|
const jobId = Math.floor(Math.random() * 10000);
|
|
49
|
-
await
|
|
44
|
+
await _NativeRNWhisper.default.startRealtimeTranscribe(this.id, jobId, options);
|
|
50
45
|
let lastTranscribePayload;
|
|
51
46
|
const slices = [];
|
|
52
47
|
let sliceIndex = 0;
|
|
@@ -94,7 +89,7 @@ class WhisperContext {
|
|
|
94
89
|
};
|
|
95
90
|
};
|
|
96
91
|
return {
|
|
97
|
-
stop: () =>
|
|
92
|
+
stop: () => _NativeRNWhisper.default.abortTranscribe(this.id, jobId),
|
|
98
93
|
subscribe: callback => {
|
|
99
94
|
let transcribeListener = EventEmitter.addListener(EVENT_ON_REALTIME_TRANSCRIBE, evt => {
|
|
100
95
|
const {
|
|
@@ -140,31 +135,35 @@ class WhisperContext {
|
|
|
140
135
|
};
|
|
141
136
|
}
|
|
142
137
|
async release() {
|
|
143
|
-
return
|
|
138
|
+
return _NativeRNWhisper.default.releaseContext(this.id);
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
141
|
exports.WhisperContext = WhisperContext;
|
|
147
|
-
async function initWhisper() {
|
|
142
|
+
async function initWhisper(_ref) {
|
|
148
143
|
let {
|
|
149
144
|
filePath,
|
|
150
145
|
isBundleAsset
|
|
151
|
-
} =
|
|
152
|
-
const id = await
|
|
146
|
+
} = _ref;
|
|
147
|
+
const id = await _NativeRNWhisper.default.initContext(filePath, !!isBundleAsset);
|
|
153
148
|
return new WhisperContext(id);
|
|
154
149
|
}
|
|
155
150
|
async function releaseAllWhisper() {
|
|
156
|
-
return
|
|
151
|
+
return _NativeRNWhisper.default.releaseAllContexts();
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
/** Current version of whisper.cpp */
|
|
160
155
|
const libVersion = _version.version;
|
|
156
|
+
exports.libVersion = libVersion;
|
|
157
|
+
const {
|
|
158
|
+
useCoreML,
|
|
159
|
+
coreMLAllowFallback
|
|
160
|
+
} = ((_RNWhisper$getConstan = _NativeRNWhisper.default.getConstants) === null || _RNWhisper$getConstan === void 0 ? void 0 : _RNWhisper$getConstan.call(_NativeRNWhisper.default)) || {};
|
|
161
161
|
|
|
162
162
|
/** Is use CoreML models on iOS */
|
|
163
|
-
|
|
164
|
-
const isUseCoreML = !!RNWhisper.WHISPER_USE_COREML;
|
|
163
|
+
const isUseCoreML = !!useCoreML;
|
|
165
164
|
|
|
166
165
|
/** Is allow fallback to CPU if load CoreML model failed */
|
|
167
166
|
exports.isUseCoreML = isUseCoreML;
|
|
168
|
-
const isCoreMLAllowFallback = !!
|
|
167
|
+
const isCoreMLAllowFallback = !!coreMLAllowFallback;
|
|
169
168
|
exports.isCoreMLAllowFallback = isCoreMLAllowFallback;
|
|
170
169
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_NativeRNWhisper","_interopRequireDefault","_version","_RNWhisper$getConstan","obj","__esModule","default","EventEmitter","Platform","OS","NativeEventEmitter","RNWhisper","DeviceEventEmitter","EVENT_ON_REALTIME_TRANSCRIBE","EVENT_ON_REALTIME_TRANSCRIBE_END","WhisperContext","constructor","id","transcribe","path","options","arguments","length","undefined","jobId","Math","floor","random","stop","abortTranscribe","promise","transcribeFile","transcribeRealtime","startRealtimeTranscribe","lastTranscribePayload","slices","sliceIndex","tOffset","putSlice","payload","isUseSlices","_slices$sliceIndex","_segments","segments","data","t1","map","segment","t0","mergeSlicesIfNeeded","mergedPayload","forEach","slice","_mergedPayload$data","_slice$data","_mergedPayload$data2","_slice$data2","result","processTime","recordingTime","subscribe","callback","transcribeListener","addListener","evt","contextId","endListener","lastPayload","isCapturing","remove","release","releaseContext","exports","initWhisper","_ref","filePath","isBundleAsset","initContext","releaseAllWhisper","releaseAllContexts","libVersion","version","useCoreML","coreMLAllowFallback","getConstants","call","isUseCoreML","isCoreMLAllowFallback"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;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7B,OAAO3D,wBAAS,CAAC4D,cAAc,CAAC,IAAI,CAACtD,EAAE,CAAC;EAC1C;AACF;AAACuD,OAAA,CAAAzD,cAAA,GAAAA,cAAA;AAEM,eAAe0D,WAAWA,CAAAC,IAAA,EAEN;EAAA,IADzB;IAAEC,QAAQ;IAAEC;EAA6D,CAAC,GAAAF,IAAA;EAE1E,MAAMzD,EAAE,GAAG,MAAMN,wBAAS,CAACkE,WAAW,CAACF,QAAQ,EAAE,CAAC,CAACC,aAAa,CAAC;EACjE,OAAO,IAAI7D,cAAc,CAACE,EAAE,CAAC;AAC/B;AAEO,eAAe6D,iBAAiBA,CAAA,EAAkB;EACvD,OAAOnE,wBAAS,CAACoE,kBAAkB,EAAE;AACvC;;AAEA;AACO,MAAMC,UAAkB,GAAGC,gBAAO;AAAAT,OAAA,CAAAQ,UAAA,GAAAA,UAAA;AAEzC,MAAM;EAAEE,SAAS;EAAEC;AAAoB,CAAC,GAAG,EAAAhF,qBAAA,GAAAQ,wBAAS,CAACyE,YAAY,cAAAjF,qBAAA,uBAAtBA,qBAAA,CAAAkF,IAAA,CAAA1E,wBAAS,CAAiB,KAAI,CAAC,CAAC;;AAE3E;AACO,MAAM2E,WAAoB,GAAG,CAAC,CAACJ,SAAS;;AAE/C;AAAAV,OAAA,CAAAc,WAAA,GAAAA,WAAA;AACO,MAAMC,qBAA8B,GAAG,CAAC,CAACJ,mBAAmB;AAAAX,OAAA,CAAAe,qBAAA,GAAAA,qBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativeRNWhisper.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAiElD,eAAeA,mBAAmB,CAACC,GAAG,CAAO,WAAW,CAAC"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
var _RNWhisper$getConstan;
|
|
2
|
+
import { NativeEventEmitter, DeviceEventEmitter, Platform } from 'react-native';
|
|
3
|
+
import RNWhisper from './NativeRNWhisper';
|
|
2
4
|
import { version } from './version.json';
|
|
3
|
-
const LINKING_ERROR = `The package 'whisper.rn' doesn't seem to be linked. Make sure: \n\n${Platform.select({
|
|
4
|
-
ios: "- You have run 'pod install'\n",
|
|
5
|
-
default: ''
|
|
6
|
-
})}- You rebuilt the app after installing the package`;
|
|
7
|
-
const RNWhisper = NativeModules.RNWhisper ? NativeModules.RNWhisper : new Proxy({}, {
|
|
8
|
-
get() {
|
|
9
|
-
throw new Error(LINKING_ERROR);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
5
|
let EventEmitter;
|
|
13
6
|
if (Platform.OS === 'ios') {
|
|
7
|
+
// @ts-ignore
|
|
14
8
|
EventEmitter = new NativeEventEmitter(RNWhisper);
|
|
15
9
|
}
|
|
16
10
|
if (Platform.OS === 'android') {
|
|
@@ -134,11 +128,11 @@ export class WhisperContext {
|
|
|
134
128
|
return RNWhisper.releaseContext(this.id);
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
|
-
export async function initWhisper() {
|
|
131
|
+
export async function initWhisper(_ref) {
|
|
138
132
|
let {
|
|
139
133
|
filePath,
|
|
140
134
|
isBundleAsset
|
|
141
|
-
} =
|
|
135
|
+
} = _ref;
|
|
142
136
|
const id = await RNWhisper.initContext(filePath, !!isBundleAsset);
|
|
143
137
|
return new WhisperContext(id);
|
|
144
138
|
}
|
|
@@ -148,10 +142,14 @@ export async function releaseAllWhisper() {
|
|
|
148
142
|
|
|
149
143
|
/** Current version of whisper.cpp */
|
|
150
144
|
export const libVersion = version;
|
|
145
|
+
const {
|
|
146
|
+
useCoreML,
|
|
147
|
+
coreMLAllowFallback
|
|
148
|
+
} = ((_RNWhisper$getConstan = RNWhisper.getConstants) === null || _RNWhisper$getConstan === void 0 ? void 0 : _RNWhisper$getConstan.call(RNWhisper)) || {};
|
|
151
149
|
|
|
152
150
|
/** Is use CoreML models on iOS */
|
|
153
|
-
export const isUseCoreML = !!
|
|
151
|
+
export const isUseCoreML = !!useCoreML;
|
|
154
152
|
|
|
155
153
|
/** Is allow fallback to CPU if load CoreML model failed */
|
|
156
|
-
export const isCoreMLAllowFallback = !!
|
|
154
|
+
export const isCoreMLAllowFallback = !!coreMLAllowFallback;
|
|
157
155
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","DeviceEventEmitter","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","DeviceEventEmitter","Platform","RNWhisper","version","EventEmitter","OS","EVENT_ON_REALTIME_TRANSCRIBE","EVENT_ON_REALTIME_TRANSCRIBE_END","WhisperContext","constructor","id","transcribe","path","options","arguments","length","undefined","jobId","Math","floor","random","stop","abortTranscribe","promise","transcribeFile","transcribeRealtime","startRealtimeTranscribe","lastTranscribePayload","slices","sliceIndex","tOffset","putSlice","payload","isUseSlices","_slices$sliceIndex","_segments","segments","data","t1","map","segment","t0","mergeSlicesIfNeeded","mergedPayload","forEach","slice","_mergedPayload$data","_slice$data","_mergedPayload$data2","_slice$data2","result","processTime","recordingTime","subscribe","callback","transcribeListener","addListener","evt","contextId","endListener","lastPayload","isCapturing","remove","release","releaseContext","initWhisper","_ref","filePath","isBundleAsset","initContext","releaseAllWhisper","releaseAllContexts","libVersion","useCoreML","coreMLAllowFallback","_RNWhisper$getConstan","getConstants","call","isUseCoreML","isCoreMLAllowFallback"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";AAAA,SACEA,kBAAkB,EAClBC,kBAAkB,EAClBC,QAAQ,QAEH,cAAc;AACrB,OAAOC,SAAS,MAAM,mBAAmB;AAEzC,SAASC,OAAO,QAAQ,gBAAgB;AAExC,IAAIC,YAA2D;AAC/D,IAAIH,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;EACzB;EACAD,YAAY,GAAG,IAAIL,kBAAkB,CAACG,SAAS,CAAC;AAClD;AACA,I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S,CAACqE,kBAAkB,EAAE;AACvC;;AAEA;AACA,OAAO,MAAMC,UAAkB,GAAGrE,OAAO;AAEzC,MAAM;EAAEsE,SAAS;EAAEC;AAAoB,CAAC,GAAG,EAAAC,qBAAA,GAAAzE,SAAS,CAAC0E,YAAY,cAAAD,qBAAA,uBAAtBA,qBAAA,CAAAE,IAAA,CAAA3E,SAAS,CAAiB,KAAI,CAAC,CAAC;;AAE3E;AACA,OAAO,MAAM4E,WAAoB,GAAG,CAAC,CAACL,SAAS;;AAE/C;AACA,OAAO,MAAMM,qBAA8B,GAAG,CAAC,CAACL,mBAAmB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
|
|
2
|
+
export type TranscribeOptions = {
|
|
3
|
+
/** Spoken language (Default: 'auto' for auto-detect) */
|
|
4
|
+
language?: string;
|
|
5
|
+
/** Translate from source language to english (Default: false) */
|
|
6
|
+
translate?: boolean;
|
|
7
|
+
/** Number of threads to use during computation (Default: 2 for 4-core devices, 4 for more cores) */
|
|
8
|
+
maxThreads?: number;
|
|
9
|
+
/** Maximum number of text context tokens to store */
|
|
10
|
+
maxContext?: number;
|
|
11
|
+
/** Maximum segment length in characters */
|
|
12
|
+
maxLen?: number;
|
|
13
|
+
/** Enable token-level timestamps */
|
|
14
|
+
tokenTimestamps?: boolean;
|
|
15
|
+
/** Word timestamp probability threshold */
|
|
16
|
+
wordThold?: number;
|
|
17
|
+
/** Time offset in milliseconds */
|
|
18
|
+
offset?: number;
|
|
19
|
+
/** Duration of audio to process in milliseconds */
|
|
20
|
+
duration?: number;
|
|
21
|
+
/** Tnitial decoding temperature */
|
|
22
|
+
temperature?: number;
|
|
23
|
+
temperatureInc?: number;
|
|
24
|
+
/** Beam size for beam search */
|
|
25
|
+
beamSize?: number;
|
|
26
|
+
/** Number of best candidates to keep */
|
|
27
|
+
bestOf?: number;
|
|
28
|
+
/** Speed up audio by x2 (reduced accuracy) */
|
|
29
|
+
speedUp?: boolean;
|
|
30
|
+
/** Initial Prompt */
|
|
31
|
+
prompt?: string;
|
|
32
|
+
};
|
|
33
|
+
export type TranscribeResult = {
|
|
34
|
+
result: string;
|
|
35
|
+
segments: Array<{
|
|
36
|
+
text: string;
|
|
37
|
+
t0: number;
|
|
38
|
+
t1: number;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
export interface Spec extends TurboModule {
|
|
42
|
+
getConstants(): {
|
|
43
|
+
useCoreML: boolean;
|
|
44
|
+
coreMLAllowFallback: boolean;
|
|
45
|
+
};
|
|
46
|
+
initContext(filePath: string, isBundleAsset: boolean): Promise<number>;
|
|
47
|
+
releaseContext(contextId: number): Promise<void>;
|
|
48
|
+
releaseAllContexts(): Promise<void>;
|
|
49
|
+
transcribeFile(contextId: number, jobId: number, path: string, options: TranscribeOptions): Promise<TranscribeResult>;
|
|
50
|
+
startRealtimeTranscribe(contextId: number, jobId: number, options: TranscribeOptions): Promise<void>;
|
|
51
|
+
abortTranscribe(contextId: number, jobId: number): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
declare const _default: Spec;
|
|
54
|
+
export default _default;
|
|
55
|
+
//# sourceMappingURL=NativeRNWhisper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeRNWhisper.d.ts","sourceRoot":"","sources":["../../src/NativeRNWhisper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAA;AAG/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oGAAoG;IACpG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oC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,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClE;;AAED,wBAAiE"}
|
|
@@ -1,34 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
language?: string;
|
|
4
|
-
/** Translate from source language to english (Default: false) */
|
|
5
|
-
translate?: boolean;
|
|
6
|
-
/** Number of threads to use during computation (Default: 2 for 4-core devices, 4 for more cores) */
|
|
7
|
-
maxThreads?: number;
|
|
8
|
-
/** Maximum number of text context tokens to store */
|
|
9
|
-
maxContext?: number;
|
|
10
|
-
/** Maximum segment length in characters */
|
|
11
|
-
maxLen?: number;
|
|
12
|
-
/** Enable token-level timestamps */
|
|
13
|
-
tokenTimestamps?: boolean;
|
|
14
|
-
/** Word timestamp probability threshold */
|
|
15
|
-
wordThold?: number;
|
|
16
|
-
/** Time offset in milliseconds */
|
|
17
|
-
offset?: number;
|
|
18
|
-
/** Duration of audio to process in milliseconds */
|
|
19
|
-
duration?: number;
|
|
20
|
-
/** Tnitial decoding temperature */
|
|
21
|
-
temperature?: number;
|
|
22
|
-
temperatureInc?: number;
|
|
23
|
-
/** Beam size for beam search */
|
|
24
|
-
beamSize?: number;
|
|
25
|
-
/** Number of best candidates to keep */
|
|
26
|
-
bestOf?: number;
|
|
27
|
-
/** Speed up audio by x2 (reduced accuracy) */
|
|
28
|
-
speedUp?: boolean;
|
|
29
|
-
/** Initial Prompt */
|
|
30
|
-
prompt?: string;
|
|
31
|
-
};
|
|
1
|
+
import type { TranscribeOptions, TranscribeResult } from './NativeRNWhisper';
|
|
2
|
+
export type { TranscribeOptions, TranscribeResult };
|
|
32
3
|
export type TranscribeRealtimeOptions = TranscribeOptions & {
|
|
33
4
|
/**
|
|
34
5
|
* Realtime record max duration in seconds.
|
|
@@ -43,14 +14,6 @@ export type TranscribeRealtimeOptions = TranscribeOptions & {
|
|
|
43
14
|
*/
|
|
44
15
|
realtimeAudioSliceSec?: number;
|
|
45
16
|
};
|
|
46
|
-
export type TranscribeResult = {
|
|
47
|
-
result: string;
|
|
48
|
-
segments: Array<{
|
|
49
|
-
text: string;
|
|
50
|
-
t0: number;
|
|
51
|
-
t1: number;
|
|
52
|
-
}>;
|
|
53
|
-
};
|
|
54
17
|
export type TranscribeRealtimeEvent = {
|
|
55
18
|
contextId: number;
|
|
56
19
|
jobId: number;
|
|
@@ -106,8 +69,8 @@ export declare class WhisperContext {
|
|
|
106
69
|
}>;
|
|
107
70
|
release(): Promise<void>;
|
|
108
71
|
}
|
|
109
|
-
export declare function initWhisper({ filePath, isBundleAsset }
|
|
110
|
-
filePath
|
|
72
|
+
export declare function initWhisper({ filePath, isBundleAsset }: {
|
|
73
|
+
filePath: string;
|
|
111
74
|
isBundleAsset?: boolean;
|
|
112
75
|
}): Promise<WhisperContext>;
|
|
113
76
|
export declare function releaseAllWhisper(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAY5E,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;AAKnD,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAC1D;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,oE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pC;IAQD,yFAAyF;IACnF,kBAAkB,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC;QACzE,mCAAmC;QACnC,IAAI,EAAE,MAAM,IAAI,CAAC;QACjB,8CAA8C;QAC9C,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,KAAK,IAAI,CAAC;KACzE,CAAC;IAgGI,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B;AAED,wBAAsB,WAAW,CAC/B,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,GACzE,OAAO,CAAC,cAAc,CAAC,CAGzB;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvD;AAED,qCAAqC;AACrC,eAAO,MAAM,UAAU,EAAE,MAAgB,CAAA;AAIzC,kCAAkC;AAClC,eAAO,MAAM,WAAW,EAAE,OAAqB,CAAA;AAE/C,2DAA2D;AAC3D,eAAO,MAAM,qBAAqB,EAAE,OAA+B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whisper.rn",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.5",
|
|
4
4
|
"description": "React Native binding of whisper.cpp",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -136,5 +136,10 @@
|
|
|
136
136
|
}
|
|
137
137
|
]
|
|
138
138
|
]
|
|
139
|
+
},
|
|
140
|
+
"codegenConfig": {
|
|
141
|
+
"name": "RNWhisperSpec",
|
|
142
|
+
"type": "all",
|
|
143
|
+
"jsSrcsDir": "./src/"
|
|
139
144
|
}
|
|
140
145
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native'
|
|
3
|
+
|
|
4
|
+
export type TranscribeOptions = {
|
|
5
|
+
/** Spoken language (Default: 'auto' for auto-detect) */
|
|
6
|
+
language?: string,
|
|
7
|
+
/** Translate from source language to english (Default: false) */
|
|
8
|
+
translate?: boolean,
|
|
9
|
+
/** Number of threads to use during computation (Default: 2 for 4-core devices, 4 for more cores) */
|
|
10
|
+
maxThreads?: number,
|
|
11
|
+
/** Maximum number of text context tokens to store */
|
|
12
|
+
maxContext?: number,
|
|
13
|
+
/** Maximum segment length in characters */
|
|
14
|
+
maxLen?: number,
|
|
15
|
+
/** Enable token-level timestamps */
|
|
16
|
+
tokenTimestamps?: boolean,
|
|
17
|
+
/** Word timestamp probability threshold */
|
|
18
|
+
wordThold?: number,
|
|
19
|
+
/** Time offset in milliseconds */
|
|
20
|
+
offset?: number,
|
|
21
|
+
/** Duration of audio to process in milliseconds */
|
|
22
|
+
duration?: number,
|
|
23
|
+
/** Tnitial decoding temperature */
|
|
24
|
+
temperature?: number,
|
|
25
|
+
temperatureInc?: number,
|
|
26
|
+
/** Beam size for beam search */
|
|
27
|
+
beamSize?: number,
|
|
28
|
+
/** Number of best candidates to keep */
|
|
29
|
+
bestOf?: number,
|
|
30
|
+
/** Speed up audio by x2 (reduced accuracy) */
|
|
31
|
+
speedUp?: boolean,
|
|
32
|
+
/** Initial Prompt */
|
|
33
|
+
prompt?: string,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type TranscribeResult = {
|
|
37
|
+
result: string,
|
|
38
|
+
segments: Array<{
|
|
39
|
+
text: string,
|
|
40
|
+
t0: number,
|
|
41
|
+
t1: number,
|
|
42
|
+
}>,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Spec extends TurboModule {
|
|
46
|
+
getConstants(): {
|
|
47
|
+
useCoreML: boolean
|
|
48
|
+
coreMLAllowFallback: boolean
|
|
49
|
+
};
|
|
50
|
+
initContext(filePath: string, isBundleAsset: boolean): Promise<number>;
|
|
51
|
+
releaseContext(contextId: number): Promise<void>;
|
|
52
|
+
releaseAllContexts(): Promise<void>;
|
|
53
|
+
transcribeFile(
|
|
54
|
+
contextId: number,
|
|
55
|
+
jobId: number,
|
|
56
|
+
path: string,
|
|
57
|
+
options: TranscribeOptions,
|
|
58
|
+
): Promise<TranscribeResult>;
|
|
59
|
+
startRealtimeTranscribe(
|
|
60
|
+
contextId: number,
|
|
61
|
+
jobId: number,
|
|
62
|
+
options: TranscribeOptions,
|
|
63
|
+
): Promise<void>;
|
|
64
|
+
abortTranscribe(contextId: number, jobId: number): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default TurboModuleRegistry.get<Spec>('RNWhisper') as Spec
|
package/src/index.ts
CHANGED
|
@@ -1,70 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NativeEventEmitter,
|
|
3
3
|
DeviceEventEmitter,
|
|
4
|
-
NativeModules,
|
|
5
4
|
Platform,
|
|
6
5
|
DeviceEventEmitterStatic,
|
|
7
6
|
} from 'react-native'
|
|
7
|
+
import RNWhisper from './NativeRNWhisper'
|
|
8
|
+
import type { TranscribeOptions, TranscribeResult } from './NativeRNWhisper'
|
|
8
9
|
import { version } from './version.json'
|
|
9
10
|
|
|
10
|
-
const LINKING_ERROR =
|
|
11
|
-
`The package 'whisper.rn' doesn't seem to be linked. Make sure: \n\n${Platform.select({ ios: "- You have run 'pod install'\n", default: '' })
|
|
12
|
-
}- You rebuilt the app after installing the package`
|
|
13
|
-
|
|
14
|
-
const RNWhisper = NativeModules.RNWhisper
|
|
15
|
-
? NativeModules.RNWhisper
|
|
16
|
-
: new Proxy(
|
|
17
|
-
{},
|
|
18
|
-
{
|
|
19
|
-
get() {
|
|
20
|
-
throw new Error(LINKING_ERROR)
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
)
|
|
24
|
-
|
|
25
11
|
let EventEmitter: NativeEventEmitter | DeviceEventEmitterStatic
|
|
26
12
|
if (Platform.OS === 'ios') {
|
|
13
|
+
// @ts-ignore
|
|
27
14
|
EventEmitter = new NativeEventEmitter(RNWhisper)
|
|
28
15
|
}
|
|
29
16
|
if (Platform.OS === 'android') {
|
|
30
17
|
EventEmitter = DeviceEventEmitter
|
|
31
18
|
}
|
|
32
19
|
|
|
20
|
+
export type { TranscribeOptions, TranscribeResult }
|
|
21
|
+
|
|
33
22
|
const EVENT_ON_REALTIME_TRANSCRIBE = '@RNWhisper_onRealtimeTranscribe'
|
|
34
23
|
const EVENT_ON_REALTIME_TRANSCRIBE_END = '@RNWhisper_onRealtimeTranscribeEnd'
|
|
35
24
|
|
|
36
|
-
export type TranscribeOptions = {
|
|
37
|
-
/** Spoken language (Default: 'auto' for auto-detect) */
|
|
38
|
-
language?: string,
|
|
39
|
-
/** Translate from source language to english (Default: false) */
|
|
40
|
-
translate?: boolean,
|
|
41
|
-
/** Number of threads to use during computation (Default: 2 for 4-core devices, 4 for more cores) */
|
|
42
|
-
maxThreads?: number,
|
|
43
|
-
/** Maximum number of text context tokens to store */
|
|
44
|
-
maxContext?: number,
|
|
45
|
-
/** Maximum segment length in characters */
|
|
46
|
-
maxLen?: number,
|
|
47
|
-
/** Enable token-level timestamps */
|
|
48
|
-
tokenTimestamps?: boolean,
|
|
49
|
-
/** Word timestamp probability threshold */
|
|
50
|
-
wordThold?: number,
|
|
51
|
-
/** Time offset in milliseconds */
|
|
52
|
-
offset?: number,
|
|
53
|
-
/** Duration of audio to process in milliseconds */
|
|
54
|
-
duration?: number,
|
|
55
|
-
/** Tnitial decoding temperature */
|
|
56
|
-
temperature?: number,
|
|
57
|
-
temperatureInc?: number,
|
|
58
|
-
/** Beam size for beam search */
|
|
59
|
-
beamSize?: number,
|
|
60
|
-
/** Number of best candidates to keep */
|
|
61
|
-
bestOf?: number,
|
|
62
|
-
/** Speed up audio by x2 (reduced accuracy) */
|
|
63
|
-
speedUp?: boolean,
|
|
64
|
-
/** Initial Prompt */
|
|
65
|
-
prompt?: string,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
25
|
export type TranscribeRealtimeOptions = TranscribeOptions & {
|
|
69
26
|
/**
|
|
70
27
|
* Realtime record max duration in seconds.
|
|
@@ -80,15 +37,6 @@ export type TranscribeRealtimeOptions = TranscribeOptions & {
|
|
|
80
37
|
realtimeAudioSliceSec?: number
|
|
81
38
|
}
|
|
82
39
|
|
|
83
|
-
export type TranscribeResult = {
|
|
84
|
-
result: string,
|
|
85
|
-
segments: Array<{
|
|
86
|
-
text: string,
|
|
87
|
-
t0: number,
|
|
88
|
-
t1: number,
|
|
89
|
-
}>,
|
|
90
|
-
}
|
|
91
|
-
|
|
92
40
|
export type TranscribeRealtimeEvent = {
|
|
93
41
|
contextId: number,
|
|
94
42
|
jobId: number,
|
|
@@ -257,7 +205,7 @@ export class WhisperContext {
|
|
|
257
205
|
}
|
|
258
206
|
|
|
259
207
|
export async function initWhisper(
|
|
260
|
-
{ filePath, isBundleAsset }: { filePath
|
|
208
|
+
{ filePath, isBundleAsset }: { filePath: string; isBundleAsset?: boolean }
|
|
261
209
|
): Promise<WhisperContext> {
|
|
262
210
|
const id = await RNWhisper.initContext(filePath, !!isBundleAsset)
|
|
263
211
|
return new WhisperContext(id)
|
|
@@ -270,8 +218,10 @@ export async function releaseAllWhisper(): Promise<void> {
|
|
|
270
218
|
/** Current version of whisper.cpp */
|
|
271
219
|
export const libVersion: string = version
|
|
272
220
|
|
|
221
|
+
const { useCoreML, coreMLAllowFallback } = RNWhisper.getConstants?.() || {}
|
|
222
|
+
|
|
273
223
|
/** Is use CoreML models on iOS */
|
|
274
|
-
export const isUseCoreML: boolean = !!
|
|
224
|
+
export const isUseCoreML: boolean = !!useCoreML
|
|
275
225
|
|
|
276
226
|
/** Is allow fallback to CPU if load CoreML model failed */
|
|
277
|
-
export const isCoreMLAllowFallback: boolean = !!
|
|
227
|
+
export const isCoreMLAllowFallback: boolean = !!coreMLAllowFallback
|
|
File without changes
|