react-native-sherpa-onnx 0.3.0 → 0.3.1

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.
@@ -1,5 +1,5 @@
1
1
  // Prebuilt versions (sherpa-onnx, FFmpeg, libarchive) from prebuilt-versions.gradle.
2
- // Resolution: env ANDROID_RELEASE_TAG files project property default.
2
+ // Resolution: env --> ANDROID_RELEASE_TAG files --> project property --> default.
3
3
  apply from: file("${project.projectDir}/prebuilt-versions.gradle")
4
4
 
5
5
  // Used by dependencies below and by prebuilt-download.gradle (extractSherpaOnnxClasses, downloadNativeLibsIfNeeded).
@@ -39,13 +39,7 @@ buildscript {
39
39
 
40
40
  apply plugin: "com.android.library"
41
41
  apply plugin: "kotlin-android"
42
-
43
- // Standalone AAR build: set in root build.gradle (ext.standaloneAarBuild = true) or via -PstandaloneAarBuild=true
44
- def isStandaloneAarBuild = rootProject.findProperty("standaloneAarBuild") in [true, "true"]
45
- // Only apply React Native plugin when building inside a React Native app (e.g. example app).
46
- if (!isStandaloneAarBuild) {
47
- apply plugin: "com.facebook.react"
48
- }
42
+ apply plugin: "com.facebook.react"
49
43
 
50
44
  android {
51
45
  namespace "com.sherpaonnx"
@@ -55,10 +49,6 @@ android {
55
49
  // Native .so and headers: filled by prebuilt-download.gradle (local jniLibs, Maven AAR, or GitHub release).
56
50
  // Alternatively by third_party/*/copy_prebuilts_to_sdk.js or shipped in npm package.
57
51
 
58
- // Codegen Java output: always use the flat path. For app builds RNGP writes here directly;
59
- // for standalone AAR builds the codegen task normalises the nested output to this path.
60
- sourceSets.main.java.srcDirs += file("${buildDir}/generated/source/codegen/java")
61
-
62
52
  defaultConfig {
63
53
  minSdkVersion getExtOrDefault("minSdkVersion")
64
54
  targetSdkVersion getExtOrDefault("targetSdkVersion")
@@ -119,7 +109,7 @@ repositories {
119
109
  maven { url "https://xdcobra.github.io/maven" }
120
110
  }
121
111
 
122
- // Configurations used by prebuilt-download.gradle: downloadNativeLibsIfNeeded (AAR jniLibs + headers),
112
+ // Configurations used by prebuilt-download.gradle: downloadNativeLibsIfNeeded (AAR --> jniLibs + headers),
123
113
  // extractSherpaOnnxClasses (sherpa-onnx classes.jar), extractOnnxruntimeClasses (onnxruntime classes.jar).
124
114
  configurations { sherpaOnnxAar; ffmpegAar; libarchiveAar; onnxruntimeAar }
125
115
 
@@ -129,8 +119,7 @@ apply from: file("${project.projectDir}/prebuilt-download.gradle")
129
119
  def kotlin_version = getExtOrDefault("kotlinVersion")
130
120
 
131
121
  dependencies {
132
- // React Native dependency: explicit version ensures IDE (VS Code Kotlin LSP) and standalone
133
- // AAR builds can resolve com.facebook.react types. When consumed by a React Native app,
122
+ // React Native dependency: explicit version for IDE (VS Code Kotlin LSP). When consumed by a React Native app,
134
123
  // Gradle's dependency resolution picks the app's react-android version (typically higher).
135
124
  implementation "com.facebook.react:react-android:0.83.0"
136
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -155,13 +144,10 @@ dependencies {
155
144
  implementation "com.google.android.play:asset-delivery:2.3.0"
156
145
  }
157
146
 
158
- // TurboModule codegen; separate script to avoid Gradle 9 Groovy "source is null" with NodeTask.
159
- apply from: file("${project.projectDir}/codegen.gradle")
160
-
161
- // Wire prebuilt tasks: extractSherpaOnnxClasses → downloadNativeLibsIfNeeded when not standalone;
147
+ // Wire prebuilt tasks: extractSherpaOnnxClasses --> downloadNativeLibsIfNeeded;
162
148
  // CMake/compile tasks depend on extractSherpaOnnxClasses and checkJniLibs.
163
149
  afterEvaluate {
164
- if (!isStandaloneAarBuild && tasks.findByName("downloadNativeLibsIfNeeded") != null) {
150
+ if (tasks.findByName("downloadNativeLibsIfNeeded") != null) {
165
151
  tasks.named("extractSherpaOnnxClasses").configure { dependsOn tasks.named("downloadNativeLibsIfNeeded") }
166
152
  tasks.named("extractOnnxruntimeClasses").configure { dependsOn tasks.named("downloadNativeLibsIfNeeded") }
167
153
  }
@@ -170,14 +156,8 @@ afterEvaluate {
170
156
  dependsOn tasks.named("extractOnnxruntimeClasses")
171
157
  dependsOn tasks.named("checkJniLibs")
172
158
  }
173
-
174
- // With includesGeneratedCode=false, codegen is always run by our custom task (not RNGP).
175
- // Kotlin compile must depend on it for both standalone AAR and app-dependency builds.
176
- def codegenJavaDir = project.file("${project.buildDir}/generated/source/codegen/java")
177
159
  tasks.matching { it.name == "compileReleaseKotlin" || it.name == "compileDebugKotlin" }.configureEach {
178
160
  dependsOn tasks.named("extractSherpaOnnxClasses")
179
161
  dependsOn tasks.named("extractOnnxruntimeClasses")
180
- dependsOn tasks.named('generateCodegenSpec')
181
- inputs.dir(codegenJavaDir)
182
162
  }
183
163
  }
@@ -105,7 +105,7 @@ add_library(sherpaonnx SHARED
105
105
  # sherpa-onnx C-API: link by directory + library name only (no IMPORTED target).
106
106
  # The .so and headers land in jniLibs and cpp/include/sherpa-onnx via:
107
107
  # (1) local third_party build, (2) Maven AAR extraction (libs + c-api headers), or (3) GitHub release zip (last resort).
108
- # If we used IMPORTED here, AGP would also copy .so from CMake duplicate in mergeNativeLibs.
108
+ # If we used IMPORTED here, AGP would also copy .so from CMake --> duplicate in mergeNativeLibs.
109
109
  set(SHERPA_ONNX_PREBUILT_BASE "${PROJECT_ROOT}/../third_party/sherpa-onnx-prebuilt/android")
110
110
  set(SHERPA_ONNX_ABI_LIB "${SHERPA_ONNX_PREBUILT_BASE}/${ANDROID_ABI}/lib")
111
111
  set(SHERPA_C_API_LIB_DIR "")
@@ -7,7 +7,6 @@ import com.facebook.react.bridge.ReadableMap
7
7
  import com.facebook.react.bridge.Arguments
8
8
  import com.facebook.react.module.annotations.ReactModule
9
9
  import com.facebook.react.modules.core.DeviceEventManagerModule
10
- import com.facebook.fbreact.specs.NativeSherpaOnnxSpec
11
10
 
12
11
  @ReactModule(name = SherpaOnnxModule.NAME)
13
12
  class SherpaOnnxModule(reactContext: ReactApplicationContext) :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-sherpa-onnx",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Offline Speech-to-text, text-to-speech, speaker diarization, speech enhancement, source separation, and VAD with sherpa-onnx for React NativeSpeech-to-Text with sherpa-onnx for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -185,7 +185,6 @@
185
185
  "name": "SherpaOnnxSpec",
186
186
  "type": "modules",
187
187
  "jsSrcsDir": "src",
188
- "includesGeneratedCode": false,
189
188
  "android": {
190
189
  "javaPackageName": "com.sherpaonnx"
191
190
  }
@@ -1,57 +0,0 @@
1
- // With includesGeneratedCode=false, RNGP does not run codegen for this library when it
2
- // is built as a dependency (e.g. example app). Run codegen whenever this module is built
3
- // (standalone AAR or as part of an app) so that NativeSherpaOnnxSpec exists for Kotlin compile.
4
- // Uses Exec + node (no Node Gradle plugin) to avoid classloader/DSL issues in applied script.
5
- def libraryRoot = project.projectDir.parentFile
6
- def outDir = file("${project.buildDir}/generated/source/codegen")
7
- def codegenJavaDir = file("${project.buildDir}/generated/source/codegen/java")
8
-
9
- codegenJavaDir.mkdirs()
10
-
11
- def codegenScript = file("${libraryRoot}/node_modules/react-native/scripts/generate-codegen-artifacts.js")
12
- def outDirPath = outDir.absolutePath.replace("\\", "/")
13
- def libraryRootPath = libraryRoot.absolutePath.replace("\\", "/")
14
-
15
- tasks.register("generateCodegenSpecNode", Exec) {
16
- onlyIf { !project.hasProperty('useNpx') || project.property('useNpx') != 'true' }
17
- workingDir = libraryRoot
18
- inputs.dir(file("${libraryRoot}/src"))
19
- inputs.file(file("${libraryRoot}/package.json"))
20
- outputs.dir(codegenJavaDir)
21
-
22
- doFirst {
23
- if (!file("${libraryRoot}/node_modules/react-native").exists()) {
24
- throw new RuntimeException(
25
- "Codegen requires node_modules at library root. Run 'yarn install' (or npm install) in ${libraryRoot}, then rebuild."
26
- )
27
- }
28
- outDir.mkdirs()
29
- }
30
-
31
- commandLine(
32
- 'node',
33
- codegenScript.absolutePath,
34
- '-p', libraryRootPath,
35
- '-t', 'android',
36
- '-o', outDirPath,
37
- '-s', 'library'
38
- )
39
- environment 'CI': 'true'
40
-
41
- doLast {
42
- def nestedJava = file("${outDir}/android/app/build/generated/source/codegen/java")
43
- if (nestedJava.exists()) {
44
- project.copy {
45
- from nestedJava
46
- into codegenJavaDir
47
- }
48
- println "[codegen] Normalised spec output -> ${codegenJavaDir}"
49
- } else {
50
- println "[codegen] WARNING: expected nested output at ${nestedJava} not found"
51
- }
52
- }
53
- }
54
-
55
- tasks.register('generateCodegenSpec') {
56
- dependsOn tasks.named('generateCodegenSpecNode')
57
- }