From 335bd07489d314c93060e6357a94b29985999943 Mon Sep 17 00:00:00 2001 From: chmjkb Date: Mon, 24 Feb 2025 14:14:05 +0100 Subject: [PATCH] fix: remove duplicated function, add tensor import --- .../swmansion/rnexecutorch/models/BaseModel.kt | 1 + .../swmansion/rnexecutorch/utils/ArrayUtils.kt | 3 --- src/SpeechToTextController.ts | 18 +++++------------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt b/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt index 19921443c8..764827f542 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt @@ -4,6 +4,7 @@ import android.content.Context import com.swmansion.rnexecutorch.utils.ETError import org.pytorch.executorch.EValue import org.pytorch.executorch.Module +import org.pytorch.executorch.Tensor import java.net.URL diff --git a/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt b/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt index 9c295499e3..36a0a1a101 100644 --- a/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +++ b/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt @@ -19,9 +19,6 @@ class ArrayUtils { fun createCharArray(input: ReadableArray): CharArray { return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toChar() }.toCharArray() } - fun createByteArray(input: ReadableArray): ByteArray { - return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index).toByte() }.toByteArray() - } fun createIntArray(input: ReadableArray): IntArray { return createTypedArrayFromReadableArray(input) { array, index -> array.getInt(index) }.toIntArray() } diff --git a/src/SpeechToTextController.ts b/src/SpeechToTextController.ts index 3f9b031694..ec16eb3c62 100644 --- a/src/SpeechToTextController.ts +++ b/src/SpeechToTextController.ts @@ -4,9 +4,10 @@ import { AudioBuffer, } from 'react-native-audio-api'; import { _SpeechToTextModule } from './native/RnExecutorchModules'; -import { EventSubscription, Image } from 'react-native'; +import { EventSubscription } from 'react-native'; import { SpeechToText } from './native/RnExecutorchModules'; import * as FileSystem from 'expo-file-system'; +import { fetchResource } from './utils/fetchResource'; import decoder from './decoders/WhisperDecodings'; type ModelSource = string | number; @@ -50,20 +51,11 @@ export class SpeechToTextController { encoderSource: ModelSource, decoderSource: ModelSource ) { - let preprocessorPath = preprocessorSource; - let encoderPath = encoderSource; - let decoderPath = decoderSource; - if ( - typeof encoderSource === 'number' && - typeof decoderSource === 'number' && - typeof preprocessorSource === 'number' - ) { - encoderPath = Image.resolveAssetSource(encoderSource).uri; - decoderPath = Image.resolveAssetSource(decoderSource).uri; - preprocessorPath = Image.resolveAssetSource(preprocessorSource).uri; - } try { this.isReady = false; + const preprocessorPath = await fetchResource(preprocessorSource); + const encoderPath = await fetchResource(encoderSource); + const decoderPath = await fetchResource(decoderSource); await this.nativeModule.loadModule( preprocessorPath, encoderPath,