react-native-wakeword-sid 1.1.205 → 1.1.207

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 +1 @@
1
- 13fe069bbd5879f49a4ac72d819bb550 keyworddetection-1.0.0.aar
1
+ f1b7db1a656e5f5e984a669235479be2 keyworddetection-1.0.0.aar
@@ -1 +1 @@
1
- 84d3a2d0f926a3369afa202996e8e36747664f26 keyworddetection-1.0.0.aar
1
+ f03917f37522ffd7dfab8dcba18e2b20584223a7 keyworddetection-1.0.0.aar
@@ -17,6 +17,10 @@ import androidx.annotation.Nullable;
17
17
  import android.util.Log;
18
18
  import java.util.HashMap;
19
19
  import java.util.Map;
20
+ import java.util.concurrent.ExecutorService;
21
+ import java.util.concurrent.Executors;
22
+ import java.util.concurrent.atomic.AtomicInteger;
23
+
20
24
 
21
25
  public class KeyWordRNBridge extends ReactContextBaseJavaModule {
22
26
 
@@ -38,6 +42,13 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
38
42
  private final Map<String, SVEngineHolder> svEngines = new HashMap<>();
39
43
 
40
44
  private final Map<String, SpeakerVerification.SpeakerVerificationMicController> svMicControllers = new HashMap<>();
45
+ private final Map<String, Boolean> svAutoOnboarding = new HashMap<>();
46
+ private final Map<String, Integer> svAutoTarget = new HashMap<>();
47
+ private final Map<String, Integer> svAutoCollected = new HashMap<>();
48
+ private final Map<String, String> svAutoEnrollmentId = new HashMap<>();
49
+ // IMPORTANT: serialize ALL SV ops to avoid races with mic frames / onboarding state.
50
+ private final ExecutorService svExec = Executors.newSingleThreadExecutor();
51
+ private final AtomicInteger svJobN = new AtomicInteger(0);
41
52
 
42
53
  // VAD API:
43
54
  private final Map<String, Float> vadThresholdByInstance = new HashMap<>();
@@ -718,7 +729,19 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
718
729
  }
719
730
 
720
731
  private void sendEventUi(String eventName, WritableMap params) {
721
- reactContext.runOnUiQueueThread(() -> sendEvent(eventName, params));
732
+ final ReactApplicationContext rc = reactContext;
733
+ if (rc == null) return;
734
+ if (!rc.hasActiveCatalystInstance()) return;
735
+ rc.runOnUiQueueThread(() -> {
736
+ try {
737
+ if (!rc.hasActiveCatalystInstance()) return;
738
+ rc.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
739
+ .emit(eventName, params);
740
+ } catch (Throwable t) {
741
+ // don't crash native if RN is tearing down
742
+ Log.w(SV_TAG, "sendEventUi failed event=" + eventName + " err=" + t);
743
+ }
744
+ });
722
745
  }
723
746
  @ReactMethod
724
747
  public void createSpeakerVerificationMicController(String controllerId,
@@ -794,6 +817,7 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
794
817
  out.putString("controllerId", controllerId);
795
818
  promise.resolve(out);
796
819
  }
820
+
797
821
  @ReactMethod
798
822
  public void svBeginOnboarding(String controllerId,
799
823
  String enrollmentId,
@@ -806,20 +830,21 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
806
830
  return;
807
831
  }
808
832
 
809
- new Thread(() -> {
833
+ final int job = svJobN.incrementAndGet();
834
+ svExec.execute(() -> {
810
835
  try {
811
836
  ctrl.beginOnboarding(enrollmentId, targetEmbeddingCount, reset);
812
-
813
837
  WritableMap out = Arguments.createMap();
814
838
  out.putBoolean("ok", true);
815
839
  out.putString("controllerId", controllerId);
816
840
  out.putString("enrollmentId", enrollmentId);
817
841
  out.putInt("target", targetEmbeddingCount);
842
+ out.putInt("job", job);
818
843
  promise.resolve(out);
819
844
  } catch (Throwable t) {
820
845
  promise.reject("SVMicBeginError", String.valueOf(t.getMessage()), t);
821
846
  }
822
- }).start();
847
+ });
823
848
  }
824
849
 
825
850
  @ReactMethod
@@ -830,17 +855,20 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
830
855
  return;
831
856
  }
832
857
 
833
- new Thread(() -> {
858
+ final int job = svJobN.incrementAndGet();
859
+ svExec.execute(() -> {
834
860
  try {
835
861
  ctrl.getNextEmbeddingFromMic();
836
862
  WritableMap out = Arguments.createMap();
837
863
  out.putBoolean("ok", true);
838
864
  out.putString("controllerId", controllerId);
865
+ out.putInt("job", job);
839
866
  promise.resolve(out);
840
867
  } catch (Throwable t) {
841
868
  promise.reject("SVMicGetNextError", String.valueOf(t.getMessage()), t);
842
869
  }
843
- }).start();
870
+ });
871
+
844
872
  }
845
873
 
846
874
  @ReactMethod
@@ -851,17 +879,19 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
851
879
  return;
852
880
  }
853
881
 
854
- new Thread(() -> {
882
+ final int job = svJobN.incrementAndGet();
883
+ svExec.execute(() -> {
855
884
  try {
856
885
  ctrl.finalizeOnboardingNow();
857
886
  WritableMap out = Arguments.createMap();
858
887
  out.putBoolean("ok", true);
859
888
  out.putString("controllerId", controllerId);
889
+ out.putInt("job", job);
860
890
  promise.resolve(out);
861
891
  } catch (Throwable t) {
862
892
  promise.reject("SVMicFinalizeError", String.valueOf(t.getMessage()), t);
863
893
  }
864
- }).start();
894
+ });
865
895
  }
866
896
 
867
897
  @ReactMethod
@@ -871,18 +901,20 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
871
901
  promise.reject("SVMicNotFound", "No speaker mic controller with ID: " + controllerId);
872
902
  return;
873
903
  }
874
-
875
- new Thread(() -> {
904
+ final int job = svJobN.incrementAndGet();
905
+ svExec.execute(() -> {
876
906
  try {
877
907
  ctrl.setEnrollmentJson(enrollmentJson);
878
908
  WritableMap out = Arguments.createMap();
879
909
  out.putBoolean("ok", true);
880
910
  out.putString("controllerId", controllerId);
911
+ out.putInt("job", job);
881
912
  promise.resolve(out);
882
913
  } catch (Throwable t) {
883
914
  promise.reject("SVMicSetEnrollError", String.valueOf(t.getMessage()), t);
884
915
  }
885
- }).start();
916
+ });
917
+
886
918
  }
887
919
 
888
920
  @ReactMethod
@@ -893,18 +925,21 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
893
925
  return;
894
926
  }
895
927
 
896
- new Thread(() -> {
928
+ final int job = svJobN.incrementAndGet();
929
+ svExec.execute(() -> {
897
930
  try {
898
931
  ctrl.startVerifyFromMic(resetState);
899
932
  WritableMap out = Arguments.createMap();
900
933
  out.putBoolean("ok", true);
901
934
  out.putString("controllerId", controllerId);
902
935
  out.putBoolean("resetState", resetState);
936
+ out.putInt("job", job);
903
937
  promise.resolve(out);
904
938
  } catch (Throwable t) {
905
939
  promise.reject("SVMicStartVerifyError", String.valueOf(t.getMessage()), t);
906
940
  }
907
- }).start();
941
+ });
942
+
908
943
  }
909
944
 
910
945
  @ReactMethod
@@ -915,7 +950,8 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
915
950
  return;
916
951
  }
917
952
 
918
- new Thread(() -> {
953
+ final int job = svJobN.incrementAndGet();
954
+ svExec.execute(() -> {
919
955
  try {
920
956
  ctrl.startEndlessVerifyFromMic((float) hopSeconds, stopOnMatch, resetState);
921
957
  WritableMap out = Arguments.createMap();
@@ -924,11 +960,12 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
924
960
  out.putDouble("hopSeconds", hopSeconds);
925
961
  out.putBoolean("stopOnMatch", stopOnMatch);
926
962
  out.putBoolean("resetState", resetState);
963
+ out.putInt("job", job);
927
964
  promise.resolve(out);
928
965
  } catch (Throwable t) {
929
966
  promise.reject("SVMicStartEndlessVerifyError", String.valueOf(t.getMessage()), t);
930
967
  }
931
- }).start();
968
+ });
932
969
  }
933
970
 
934
971
  @ReactMethod
@@ -949,5 +986,15 @@ public class KeyWordRNBridge extends ReactContextBaseJavaModule {
949
986
  promise.reject("SVMicStopError", String.valueOf(t.getMessage()), t);
950
987
  }
951
988
  }
989
+ @ReactMethod
990
+ public void startVerifyContinuousFromMic(String controllerId, boolean resetState, double hopSeconds, Promise promise) {
991
+ // parity: continuous verify == endless verify
992
+ // choose stopOnMatch=false by default (continuous)
993
+ svStartEndlessVerifyFromMic(controllerId, hopSeconds, false, resetState, promise);
994
+ }
952
995
 
996
+ @ReactMethod
997
+ public void stopVerifyContinuousFromMic(String controllerId, Promise promise) {
998
+ svStopMic(controllerId, promise);
999
+ }
953
1000
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wakeword-sid",
3
- "version": "1.1.205",
3
+ "version": "1.1.207",
4
4
  "description": "Voice/Wake-word detection library for React Native",
5
5
  "main": "wakewords/index.js",
6
6
  "types": "wakewords/index.d.ts",