Skip to content

Commit 0801c82

Browse files
author
Mateusz Kopciński
committed
hopefully final changes
1 parent 0ee1490 commit 0801c82

File tree

19 files changed

+301
-156
lines changed

19 files changed

+301
-156
lines changed

android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.swmansion.rnexecutorch
33
import com.facebook.react.bridge.Promise
44
import com.facebook.react.bridge.ReactApplicationContext
55
import com.facebook.react.bridge.ReadableArray
6-
import com.facebook.react.bridge.WritableArray
76
import com.swmansion.rnexecutorch.models.speechToText.BaseS2TModule
87
import com.swmansion.rnexecutorch.models.speechToText.Moonshine
98
import com.swmansion.rnexecutorch.models.speechToText.MoonshineDecoder
@@ -12,10 +11,8 @@ import com.swmansion.rnexecutorch.models.speechToText.Whisper
1211
import com.swmansion.rnexecutorch.models.speechToText.WhisperDecoder
1312
import com.swmansion.rnexecutorch.models.speechToText.WhisperEncoder
1413
import com.swmansion.rnexecutorch.utils.ArrayUtils
15-
import com.swmansion.rnexecutorch.utils.ArrayUtils.Companion.createFloatArray
14+
import com.swmansion.rnexecutorch.utils.ArrayUtils.Companion.writableArrayToEValue
1615
import com.swmansion.rnexecutorch.utils.ETError
17-
import org.pytorch.executorch.EValue
18-
import org.pytorch.executorch.Tensor
1916

2017
class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSpec(reactContext) {
2118

@@ -38,6 +35,8 @@ class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSp
3835
this.speechToTextModule.decoder = WhisperDecoder(reactApplicationContext)
3936
}
4037
} catch(e: Exception){
38+
promise.reject(e.message!!, ETError.InvalidModelSource.toString())
39+
return
4140
}
4241

4342

@@ -50,7 +49,7 @@ class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSp
5049
}
5150

5251
override fun generate(waveform: ReadableArray, promise: Promise) {
53-
val encoding = this.writableArrayToEValue(this.speechToTextModule.encode(waveform))
52+
val encoding = writableArrayToEValue(this.speechToTextModule.encode(waveform))
5453
val generatedTokens = mutableListOf(this.speechToTextModule.START_TOKEN)
5554
var lastToken = 0
5655
Thread {
@@ -66,12 +65,6 @@ class SpeechToText(reactContext: ReactApplicationContext) : NativeSpeechToTextSp
6665
}.start()
6766
}
6867

69-
private fun writableArrayToEValue(input: WritableArray): EValue {
70-
val size = input.size()
71-
val preprocessorInputShape = longArrayOf(1, size.toLong())
72-
return EValue.from(Tensor.fromBlob(createFloatArray(input), preprocessorInputShape))
73-
}
74-
7568
override fun encode(waveform: ReadableArray, promise: Promise) {
7669
promise.resolve(this.speechToTextModule.encode(waveform))
7770
}

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

3-
import android.util.Log
43
import com.swmansion.rnexecutorch.models.BaseModel
54
import org.pytorch.executorch.EValue
65
import com.facebook.react.bridge.ReactApplicationContext

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.ReadableArray
44
import com.facebook.react.bridge.WritableArray

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.ReadableArray
44
import com.swmansion.rnexecutorch.utils.ArrayUtils

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.ReactApplicationContext
44
import com.facebook.react.bridge.ReadableArray
@@ -8,6 +8,7 @@ import org.pytorch.executorch.Tensor
88

99
class MoonshineDecoder(reactApplicationContext: ReactApplicationContext) : BaseS2TDecoder(reactApplicationContext) {
1010
private lateinit var generatedTokens: LongArray
11+
private var innerDim = 288;
1112

1213
override var methodName: String
1314
get() = "forward_cached"
@@ -22,6 +23,6 @@ class MoonshineDecoder(reactApplicationContext: ReactApplicationContext) : BaseS
2223
}
2324

2425
override fun getInputShape(inputLength: Int): LongArray {
25-
return longArrayOf(1, inputLength.toLong()/288, 288)
26+
return longArrayOf(1, inputLength.toLong()/innerDim, innerDim)
2627
}
2728
}

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.Arguments
44
import com.facebook.react.bridge.ReactApplicationContext

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.ReadableArray
44
import com.swmansion.rnexecutorch.utils.ArrayUtils

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import com.facebook.react.bridge.ReactApplicationContext
44
import com.facebook.react.bridge.ReadableArray

android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.swmansion.rnexecutorch.models.speechToText
1+
package com.swmansion.rnexecutorch.models.speechtotext
22

33
import android.util.Log
44
import com.facebook.react.bridge.Arguments

android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt

+5
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,10 @@ class ArrayUtils {
9191
return resultArray
9292
}
9393

94+
fun writableArrayToEValue(input: WritableArray): EValue {
95+
val size = input.size()
96+
val preprocessorInputShape = longArrayOf(1, size.toLong())
97+
return EValue.from(Tensor.fromBlob(createFloatArray(input), preprocessorInputShape))
98+
}
9499
}
95100
}

examples/speech-to-text/android/app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
55
<uses-permission android:name="android.permission.VIBRATE"/>
66
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
7+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
78
<queries>
89
<intent>
910
<action android:name="android.intent.action.VIEW"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import React from 'react';
2+
import {
3+
View,
4+
Text,
5+
Modal,
6+
TextInput,
7+
StyleSheet,
8+
TouchableOpacity,
9+
} from 'react-native';
10+
11+
const InputPrompt = ({
12+
value,
13+
onChangeText,
14+
modalVisible,
15+
setModalVisible,
16+
}: {
17+
value: string;
18+
onChangeText: (_: string) => void;
19+
modalVisible: boolean;
20+
setModalVisible: (_: boolean) => void;
21+
}) => {
22+
return (
23+
<View style={styles.centeredView}>
24+
<Modal
25+
animationType="slide"
26+
transparent={true}
27+
visible={modalVisible}
28+
onRequestClose={() => {
29+
setModalVisible(!modalVisible);
30+
}}
31+
>
32+
<TouchableOpacity
33+
style={styles.centeredView}
34+
activeOpacity={1}
35+
onPressOut={() => {
36+
setModalVisible(false);
37+
}}
38+
>
39+
<View style={styles.centeredView}>
40+
<View style={styles.modalView}>
41+
<TextInput
42+
placeholder="Enter audio url"
43+
style={styles.textInputStyle}
44+
onChangeText={(text) => onChangeText(text)}
45+
value={value}
46+
/>
47+
<TouchableOpacity
48+
style={styles.confirmButton}
49+
onPress={() => setModalVisible(!modalVisible)}
50+
>
51+
<Text style={styles.confirmText}>Confirm</Text>
52+
</TouchableOpacity>
53+
</View>
54+
</View>
55+
</TouchableOpacity>
56+
</Modal>
57+
</View>
58+
);
59+
};
60+
61+
const styles = StyleSheet.create({
62+
confirmText: {
63+
fontSize: 20,
64+
color: 'white',
65+
fontWeight: '400',
66+
},
67+
confirmButton: {
68+
backgroundColor: '#001A72',
69+
justifyContent: 'center',
70+
alignItems: 'center',
71+
width: '100%',
72+
height: 40,
73+
borderRadius: 40,
74+
paddingRight: 15,
75+
paddingLeft: 15,
76+
},
77+
centeredView: {
78+
flex: 1,
79+
justifyContent: 'center',
80+
alignItems: 'center',
81+
},
82+
modalView: {
83+
margin: 20,
84+
backgroundColor: 'white',
85+
borderRadius: 20,
86+
padding: 35,
87+
alignItems: 'center',
88+
shadowColor: '#000',
89+
shadowOffset: {
90+
width: 0,
91+
height: 2,
92+
},
93+
shadowOpacity: 0.25,
94+
shadowRadius: 4,
95+
elevation: 5,
96+
},
97+
textInputStyle: {
98+
textAlign: 'center',
99+
height: 40,
100+
width: 200,
101+
marginBottom: 20,
102+
borderRadius: 20,
103+
borderWidth: 1,
104+
padding: 10,
105+
borderColor: '#ccc',
106+
},
107+
});
108+
109+
export default InputPrompt;

examples/speech-to-text/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ PODS:
12781278
- ReactCommon/turbomodule/bridging
12791279
- ReactCommon/turbomodule/core
12801280
- Yoga
1281-
- react-native-executorch (0.3.268):
1281+
- react-native-executorch (0.3.271):
12821282
- DoubleConversion
12831283
- glog
12841284
- hermes-engine
@@ -2134,7 +2134,7 @@ SPEC CHECKSUMS:
21342134
React-logger: 26155dc23db5c9038794db915f80bd2044512c2e
21352135
React-Mapbuffer: ad1ba0205205a16dbff11b8ade6d1b3959451658
21362136
React-microtasksnativemodule: e771eb9eb6ace5884ee40a293a0e14a9d7a4343c
2137-
react-native-executorch: 66a8be0ed60c910199346e9765e2cbae2903614b
2137+
react-native-executorch: 37c37144e4ea442ac1ed968f8964bc56342790f9
21382138
react-native-image-picker: e7331948589e764ecd5a9c715c3fc14d4e6187e6
21392139
react-native-safe-area-context: 26a64672a8d76556e54682ab5aa0a6b6798d8a8e
21402140
React-nativeconfig: aeed6e2a8ac02b2df54476afcc7c663416c12bf7

examples/speech-to-text/ios/speechtotext.xcodeproj/project.pbxproj

+28-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -31,7 +31,7 @@
3131
7E2F4A0A999B4D66B0D04576 /* speechtotext-Bridging-Header.h */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.c.h; name = "speechtotext-Bridging-Header.h"; path = "speechtotext/speechtotext-Bridging-Header.h"; sourceTree = "<group>"; };
3232
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = speechtotext/SplashScreen.storyboard; sourceTree = "<group>"; };
3333
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
34-
C4D875486D112A3239CE6AB1 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = speechtotext/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
34+
C4D875486D112A3239CE6AB1 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = speechtotext/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3535
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
3636
F52C8F6606CD43269C90280F /* noop-file.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "noop-file.swift"; path = "speechtotext/noop-file.swift"; sourceTree = "<group>"; };
3737
FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ExpoModulesProvider.swift; path = "Pods/Target Support Files/Pods-speechtotext/ExpoModulesProvider.swift"; sourceTree = "<group>"; };
@@ -173,7 +173,9 @@
173173
LastUpgradeCheck = 1130;
174174
TargetAttributes = {
175175
13B07F861A680F5B00A75B9A = {
176+
DevelopmentTeam = ND24MXDQ9M;
176177
LastSwiftMigration = 1250;
178+
ProvisioningStyle = Automatic;
177179
};
178180
};
179181
};
@@ -348,23 +350,29 @@
348350
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
349351
CLANG_ENABLE_MODULES = YES;
350352
CODE_SIGN_ENTITLEMENTS = speechtotext/speechtotext.entitlements;
353+
CODE_SIGN_IDENTITY = "Apple Development";
354+
CODE_SIGN_STYLE = Automatic;
351355
CURRENT_PROJECT_VERSION = 1;
356+
DEVELOPMENT_TEAM = ND24MXDQ9M;
352357
ENABLE_BITCODE = NO;
353358
GCC_PREPROCESSOR_DEFINITIONS = (
354359
"$(inherited)",
355360
"FB_SONARKIT_ENABLED=1",
356361
);
357362
INFOPLIST_FILE = speechtotext/Info.plist;
358363
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
359-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
364+
LD_RUNPATH_SEARCH_PATHS = (
365+
"$(inherited)",
366+
"@executable_path/Frameworks",
367+
);
360368
MARKETING_VERSION = 1.0;
361369
OTHER_LDFLAGS = (
362370
"$(inherited)",
363371
"-ObjC",
364372
"-lc++",
365373
);
366374
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG";
367-
PRODUCT_BUNDLE_IDENTIFIER = com.mkopcins.speechtotext;
375+
PRODUCT_BUNDLE_IDENTIFIER = com.anonymous.speechtotexts;
368376
PRODUCT_NAME = speechtotext;
369377
SWIFT_OBJC_BRIDGING_HEADER = "speechtotext/speechtotext-Bridging-Header.h";
370378
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -381,18 +389,24 @@
381389
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
382390
CLANG_ENABLE_MODULES = YES;
383391
CODE_SIGN_ENTITLEMENTS = speechtotext/speechtotext.entitlements;
392+
CODE_SIGN_IDENTITY = "Apple Development";
393+
CODE_SIGN_STYLE = Automatic;
384394
CURRENT_PROJECT_VERSION = 1;
395+
DEVELOPMENT_TEAM = ND24MXDQ9M;
385396
INFOPLIST_FILE = speechtotext/Info.plist;
386397
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
387-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
398+
LD_RUNPATH_SEARCH_PATHS = (
399+
"$(inherited)",
400+
"@executable_path/Frameworks",
401+
);
388402
MARKETING_VERSION = 1.0;
389403
OTHER_LDFLAGS = (
390404
"$(inherited)",
391405
"-ObjC",
392406
"-lc++",
393407
);
394408
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE";
395-
PRODUCT_BUNDLE_IDENTIFIER = com.mkopcins.speechtotext;
409+
PRODUCT_BUNDLE_IDENTIFIER = com.anonymous.speechtotexts;
396410
PRODUCT_NAME = speechtotext;
397411
SWIFT_OBJC_BRIDGING_HEADER = "speechtotext/speechtotext-Bridging-Header.h";
398412
SWIFT_VERSION = 5.0;
@@ -449,7 +463,10 @@
449463
GCC_WARN_UNUSED_FUNCTION = YES;
450464
GCC_WARN_UNUSED_VARIABLE = YES;
451465
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
452-
LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
466+
LD_RUNPATH_SEARCH_PATHS = (
467+
/usr/lib/swift,
468+
"$(inherited)",
469+
);
453470
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
454471
MTL_ENABLE_DEBUG_INFO = YES;
455472
ONLY_ACTIVE_ARCH = YES;
@@ -505,7 +522,10 @@
505522
GCC_WARN_UNUSED_FUNCTION = YES;
506523
GCC_WARN_UNUSED_VARIABLE = YES;
507524
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
508-
LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited)";
525+
LD_RUNPATH_SEARCH_PATHS = (
526+
/usr/lib/swift,
527+
"$(inherited)",
528+
);
509529
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
510530
MTL_ENABLE_DEBUG_INFO = NO;
511531
OTHER_LDFLAGS = (

0 commit comments

Comments
 (0)