whisper.rn 0.1.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.
Files changed (29) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +82 -0
  3. package/android/build.gradle +85 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/rnwhisper/RNWhisperModule.java +175 -0
  7. package/android/src/main/java/com/rnwhisper/RNWhisperPackage.java +28 -0
  8. package/android/src/main/java/com/rnwhisper/WhisperContext.java +186 -0
  9. package/android/src/main/jni/whisper/Android.mk +26 -0
  10. package/android/src/main/jni/whisper/Application.mk +1 -0
  11. package/android/src/main/jni/whisper/Whisper.mk +18 -0
  12. package/android/src/main/jni/whisper/jni.c +159 -0
  13. package/ios/RNWhisper.h +9 -0
  14. package/ios/RNWhisper.mm +199 -0
  15. package/ios/RNWhisper.xcodeproj/project.pbxproj +278 -0
  16. package/ios/RNWhisper.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  17. package/ios/RNWhisper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  18. package/ios/RNWhisper.xcodeproj/project.xcworkspace/xcuserdata/jhen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  19. package/ios/RNWhisper.xcodeproj/xcuserdata/jhen.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  20. package/jest/mock.js +12 -0
  21. package/lib/commonjs/index.js +42 -0
  22. package/lib/commonjs/index.js.map +1 -0
  23. package/lib/module/index.js +35 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/typescript/index.d.ts +28 -0
  26. package/lib/typescript/index.d.ts.map +1 -0
  27. package/package.json +132 -0
  28. package/src/index.tsx +63 -0
  29. package/whisper-rn.podspec +41 -0
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initWhisper = initWhisper;
7
+ exports.releaseAllWhisper = releaseAllWhisper;
8
+ var _reactNative = require("react-native");
9
+ const LINKING_ERROR = `The package 'whisper.rn' doesn't seem to be linked. Make sure: \n\n${_reactNative.Platform.select({
10
+ ios: "- You have run 'pod install'\n",
11
+ default: ''
12
+ })}- You rebuilt the app after installing the package`;
13
+ const RNWhisper = _reactNative.NativeModules.RNWhisper ? _reactNative.NativeModules.RNWhisper : new Proxy({}, {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ });
18
+ class WhisperContext {
19
+ constructor(id) {
20
+ this.id = id;
21
+ }
22
+ async transcribe(path) {
23
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24
+ return RNWhisper.transcribe(this.id, path, options).then(result => ({
25
+ result
26
+ }));
27
+ }
28
+ async release() {
29
+ return RNWhisper.releaseContext(this.id);
30
+ }
31
+ }
32
+ async function initWhisper() {
33
+ let {
34
+ filePath
35
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
36
+ const id = await RNWhisper.initContext(filePath);
37
+ return new WhisperContext(id);
38
+ }
39
+ async function releaseAllWhisper() {
40
+ return RNWhisper.releaseAllContexts();
41
+ }
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","RNWhisper","NativeModules","Proxy","get","Error","WhisperContext","constructor","id","transcribe","path","options","arguments","length","undefined","then","result","release","releaseContext","initWhisper","filePath","initContext","releaseAllWhisper","releaseAllContexts"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,sEAAqEC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAC3I,oDAAmD;AAEtD,MAAMC,SAAS,GAAGC,0BAAa,CAACD,SAAS,GACrCC,0BAAa,CAACD,SAAS,GACvB,IAAIE,KAAK,CACT,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAoBH,MAAMU,cAAc,CAAC;EAGnBC,WAAWA,CAACC,EAAU,EAAE;IACtB,IAAI,CAACA,EAAE,GAAGA,EAAE;EACd;EAEA,MAAMC,UAAUA,CAACC,IAAY,EAA8D;IAAA,IAA5DC,OAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAC5D,OAAOX,SAAS,CAACQ,UAAU,CAAC,IAAI,CAACD,EAAE,EAAEE,IAAI,EAAEC,OAAO,CAAC,CAACI,IAAI,CAAEC,MAAc,KAAM;MAC5EA;IACF,CAAC,CAAC,CAAC;EACL;EAEA,MAAMC,OAAOA,CAAA,EAAG;IACd,OAAOhB,SAAS,CAACiB,cAAc,CAAC,IAAI,CAACV,EAAE,CAAC;EAC1C;AACF;AAEO,eAAeW,WAAWA,CAAA,EAEN;EAAA,IADzB;IAAEC;EAAgC,CAAC,GAAAR,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAExC,MAAMJ,EAAE,GAAG,MAAMP,SAAS,CAACoB,WAAW,CAACD,QAAQ,CAAC;EAChD,OAAO,IAAId,cAAc,CAACE,EAAE,CAAC;AAC/B;AAEO,eAAec,iBAAiBA,CAAA,EAAkB;EACvD,OAAOrB,SAAS,CAACsB,kBAAkB,EAAE;AACvC"}
@@ -0,0 +1,35 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ const LINKING_ERROR = `The package 'whisper.rn' doesn't seem to be linked. Make sure: \n\n${Platform.select({
3
+ ios: "- You have run 'pod install'\n",
4
+ default: ''
5
+ })}- You rebuilt the app after installing the package`;
6
+ const RNWhisper = NativeModules.RNWhisper ? NativeModules.RNWhisper : new Proxy({}, {
7
+ get() {
8
+ throw new Error(LINKING_ERROR);
9
+ }
10
+ });
11
+ class WhisperContext {
12
+ constructor(id) {
13
+ this.id = id;
14
+ }
15
+ async transcribe(path) {
16
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ return RNWhisper.transcribe(this.id, path, options).then(result => ({
18
+ result
19
+ }));
20
+ }
21
+ async release() {
22
+ return RNWhisper.releaseContext(this.id);
23
+ }
24
+ }
25
+ export async function initWhisper() {
26
+ let {
27
+ filePath
28
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
29
+ const id = await RNWhisper.initContext(filePath);
30
+ return new WhisperContext(id);
31
+ }
32
+ export async function releaseAllWhisper() {
33
+ return RNWhisper.releaseAllContexts();
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","RNWhisper","Proxy","get","Error","WhisperContext","constructor","id","transcribe","path","options","arguments","length","undefined","then","result","release","releaseContext","initWhisper","filePath","initContext","releaseAllWhisper","releaseAllContexts"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GAChB,sEAAqED,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAC3I,oDAAmD;AAEtD,MAAMC,SAAS,GAAGN,aAAa,CAACM,SAAS,GACrCN,aAAa,CAACM,SAAS,GACvB,IAAIC,KAAK,CACT,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAoBH,MAAMQ,cAAc,CAAC;EAGnBC,WAAWA,CAACC,EAAU,EAAE;IACtB,IAAI,CAACA,EAAE,GAAGA,EAAE;EACd;EAEA,MAAMC,UAAUA,CAACC,IAAY,EAA8D;IAAA,IAA5DC,OAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAC5D,OAAOV,SAAS,CAACO,UAAU,CAAC,IAAI,CAACD,EAAE,EAAEE,IAAI,EAAEC,OAAO,CAAC,CAACI,IAAI,CAAEC,MAAc,KAAM;MAC5EA;IACF,CAAC,CAAC,CAAC;EACL;EAEA,MAAMC,OAAOA,CAAA,EAAG;IACd,OAAOf,SAAS,CAACgB,cAAc,CAAC,IAAI,CAACV,EAAE,CAAC;EAC1C;AACF;AAEA,OAAO,eAAeW,WAAWA,CAAA,EAEN;EAAA,IADzB;IAAEC;EAAgC,CAAC,GAAAR,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAExC,MAAMJ,EAAE,GAAG,MAAMN,SAAS,CAACmB,WAAW,CAACD,QAAQ,CAAC;EAChD,OAAO,IAAId,cAAc,CAACE,EAAE,CAAC;AAC/B;AAEA,OAAO,eAAec,iBAAiBA,CAAA,EAAkB;EACvD,OAAOpB,SAAS,CAACqB,kBAAkB,EAAE;AACvC"}
@@ -0,0 +1,28 @@
1
+ export type TranscribeOptions = {
2
+ maxThreads?: number;
3
+ maxContext?: number;
4
+ maxLen?: number;
5
+ offset?: number;
6
+ duration?: number;
7
+ wordThold?: number;
8
+ temperature?: number;
9
+ temperatureInc?: number;
10
+ beamSize?: number;
11
+ bestOf?: number;
12
+ speedUp?: boolean;
13
+ };
14
+ export type TranscribeResult = {
15
+ result: string;
16
+ };
17
+ declare class WhisperContext {
18
+ id: number;
19
+ constructor(id: number);
20
+ transcribe(path: string, options?: TranscribeOptions): Promise<TranscribeResult>;
21
+ release(): Promise<any>;
22
+ }
23
+ export declare function initWhisper({ filePath }?: {
24
+ filePath?: string;
25
+ }): Promise<WhisperContext>;
26
+ export declare function releaseAllWhisper(): Promise<void>;
27
+ export {};
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAiBA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,cAAM,cAAc;IAClB,EAAE,EAAE,MAAM,CAAA;gBAEE,EAAE,EAAE,MAAM;IAIhB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAMpF,OAAO;CAGd;AAED,wBAAsB,WAAW,CAC/B,EAAE,QAAQ,EAAE,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACvC,OAAO,CAAC,cAAc,CAAC,CAGzB;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvD"}
package/package.json ADDED
@@ -0,0 +1,132 @@
1
+ {
2
+ "name": "whisper.rn",
3
+ "version": "0.1.0",
4
+ "description": "React Native binding of whisper.cpp",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "jest",
14
+ "android",
15
+ "ios",
16
+ "cpp",
17
+ "*.podspec",
18
+ "!lib/typescript/example",
19
+ "!ios/build",
20
+ "!android/build",
21
+ "!android/gradle",
22
+ "!android/gradlew",
23
+ "!android/gradlew.bat",
24
+ "!android/local.properties",
25
+ "!**/__tests__",
26
+ "!**/__fixtures__",
27
+ "!**/__mocks__",
28
+ "!**/.*"
29
+ ],
30
+ "scripts": {
31
+ "bootstrap": "./scripts/bootstrap.sh",
32
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
+ "typecheck": "tsc --noEmit",
34
+ "prepack": "bob build",
35
+ "test": "jest",
36
+ "example": "yarn --cwd example",
37
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "ios",
42
+ "android",
43
+ "whisper",
44
+ "whisper.cpp",
45
+ "speech recognition"
46
+ ],
47
+ "repository": "https://github.com/mybigday/whisper.rn",
48
+ "author": "Jhen <developer@jhen.me> (https://github.com/jhen0409)",
49
+ "license": "MIT",
50
+ "bugs": {
51
+ "url": "https://github.com/mybigday/whisper.rn/issues"
52
+ },
53
+ "homepage": "https://github.com/mybigday/whisper.rn#readme",
54
+ "devDependencies": {
55
+ "@commitlint/config-conventional": "^17.0.2",
56
+ "@evilmartians/lefthook": "^1.2.2",
57
+ "@fugood/eslint-config-react": "^0.5.0",
58
+ "@release-it/conventional-changelog": "^5.0.0",
59
+ "@types/jest": "^29.4.4",
60
+ "@types/react": "~17.0.21",
61
+ "@types/react-native": "0.70.0",
62
+ "@typescript-eslint/eslint-plugin": "^5.55.0",
63
+ "@typescript-eslint/parser": "^5.55.0",
64
+ "commitlint": "^17.0.2",
65
+ "del-cli": "^5.0.0",
66
+ "eslint": "^8.36.0",
67
+ "metro-react-native-babel-preset": "0.73.8",
68
+ "pod-install": "^0.1.38",
69
+ "react": "18.2.0",
70
+ "react-native": "0.71.4",
71
+ "react-native-builder-bob": "^0.20.4",
72
+ "release-it": "^15.8.0",
73
+ "typescript": "^4.9.5"
74
+ },
75
+ "resolutions": {
76
+ "@types/react": "17.0.21"
77
+ },
78
+ "peerDependencies": {
79
+ "react": "*",
80
+ "react-native": "*"
81
+ },
82
+ "engines": {
83
+ "node": ">= 16.0.0"
84
+ },
85
+ "jest": {
86
+ "preset": "react-native",
87
+ "modulePathIgnorePatterns": [
88
+ "<rootDir>/example/node_modules",
89
+ "<rootDir>/lib/",
90
+ "<rootDir>/whisper.cpp/"
91
+ ]
92
+ },
93
+ "commitlint": {
94
+ "extends": [
95
+ "@commitlint/config-conventional"
96
+ ]
97
+ },
98
+ "release-it": {
99
+ "git": {
100
+ "commitMessage": "chore: release ${version}",
101
+ "tagName": "v${version}"
102
+ },
103
+ "npm": {
104
+ "publish": true
105
+ },
106
+ "github": {
107
+ "release": true
108
+ },
109
+ "plugins": {
110
+ "@release-it/conventional-changelog": {
111
+ "preset": "angular"
112
+ }
113
+ }
114
+ },
115
+ "react-native-builder-bob": {
116
+ "source": "src",
117
+ "output": "lib",
118
+ "targets": [
119
+ "commonjs",
120
+ "module",
121
+ [
122
+ "typescript",
123
+ {
124
+ "project": "tsconfig.build.json"
125
+ }
126
+ ]
127
+ ]
128
+ },
129
+ "dependencies": {
130
+ "jest": "^29.5.0"
131
+ }
132
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,63 @@
1
+ import { NativeModules, Platform } from 'react-native'
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'whisper.rn' doesn't seem to be linked. Make sure: \n\n${Platform.select({ ios: "- You have run 'pod install'\n", default: '' })
5
+ }- You rebuilt the app after installing the package`
6
+
7
+ const RNWhisper = NativeModules.RNWhisper
8
+ ? NativeModules.RNWhisper
9
+ : new Proxy(
10
+ {},
11
+ {
12
+ get() {
13
+ throw new Error(LINKING_ERROR)
14
+ },
15
+ },
16
+ )
17
+
18
+ export type TranscribeOptions = {
19
+ maxThreads?: number,
20
+ maxContext?: number,
21
+ maxLen?: number,
22
+ offset?: number,
23
+ duration?: number,
24
+ wordThold?: number,
25
+ temperature?: number,
26
+ temperatureInc?: number,
27
+ beamSize?: number,
28
+ bestOf?: number,
29
+ speedUp?: boolean,
30
+ }
31
+
32
+ export type TranscribeResult = {
33
+ result: string,
34
+ }
35
+
36
+ class WhisperContext {
37
+ id: number
38
+
39
+ constructor(id: number) {
40
+ this.id = id
41
+ }
42
+
43
+ async transcribe(path: string, options: TranscribeOptions = {}): Promise<TranscribeResult> {
44
+ return RNWhisper.transcribe(this.id, path, options).then((result: string) => ({
45
+ result
46
+ }))
47
+ }
48
+
49
+ async release() {
50
+ return RNWhisper.releaseContext(this.id)
51
+ }
52
+ }
53
+
54
+ export async function initWhisper(
55
+ { filePath }: { filePath?: string } = {}
56
+ ): Promise<WhisperContext> {
57
+ const id = await RNWhisper.initContext(filePath)
58
+ return new WhisperContext(id)
59
+ }
60
+
61
+ export async function releaseAllWhisper(): Promise<void> {
62
+ return RNWhisper.releaseAllContexts()
63
+ }
@@ -0,0 +1,41 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ base_compiler_flags = '-DGGML_USE_ACCELERATE -Wno-shorten-64-to-32'
5
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
6
+
7
+ Pod::Spec.new do |s|
8
+ s.name = "whisper-rn"
9
+ s.version = package["version"]
10
+ s.summary = package["description"]
11
+ s.homepage = package["homepage"]
12
+ s.license = package["license"]
13
+ s.authors = package["author"]
14
+
15
+ s.platforms = { :ios => "11.0" }
16
+ s.source = { :git => "https://github.com/mybigday/whisper.rn.git", :tag => "#{s.version}" }
17
+
18
+ s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp,c}"
19
+
20
+ s.dependency "React-Core"
21
+
22
+ s.compiler_flags = base_compiler_flags
23
+ s.xcconfig = {
24
+ 'OTHER_LDFLAGS' => '-framework Accelerate'
25
+ }
26
+
27
+ # Don't install the dependencies when we run `pod install` in the old architecture.
28
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
29
+ s.compiler_flags = base_compiler_flags + " " + folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
30
+ s.pod_target_xcconfig = {
31
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
32
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
33
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
34
+ }
35
+ s.dependency "React-Codegen"
36
+ s.dependency "RCT-Folly"
37
+ s.dependency "RCTRequired"
38
+ s.dependency "RCTTypeSafety"
39
+ s.dependency "ReactCommon/turbomodule/core"
40
+ end
41
+ end