react-native-voice / voice

:microphone: React Native Voice Recognition library for iOS and Android (Online and Offline Support)
MIT License
1.84k stars 495 forks source link

React native 0.75 support #518

Open SolankiYogesh3500 opened 2 months ago

SolankiYogesh3500 commented 2 months ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch @react-native-voice/voice@3.2.4 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@react-native-voice/voice/android/build.gradle b/node_modules/@react-native-voice/voice/android/build.gradle
index 8fce879..bda4ee1 100644
--- a/node_modules/@react-native-voice/voice/android/build.gradle
+++ b/node_modules/@react-native-voice/voice/android/build.gradle
@@ -62,6 +62,5 @@ def supportVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     testImplementation 'junit:junit:4.12'
-    implementation "com.android.support:appcompat-v7:${supportVersion}"
     implementation 'com.facebook.react:react-native:+'
 }
diff --git a/node_modules/@react-native-voice/voice/android/src/main/java/com/wenkesj/voice/VoiceModule.java b/node_modules/@react-native-voice/voice/android/src/main/java/com/wenkesj/voice/VoiceModule.java
index f22833e..1ab1fea 100644
--- a/node_modules/@react-native-voice/voice/android/src/main/java/com/wenkesj/voice/VoiceModule.java
+++ b/node_modules/@react-native-voice/voice/android/src/main/java/com/wenkesj/voice/VoiceModule.java
@@ -322,10 +322,17 @@ public class VoiceModule extends ReactContextBaseJavaModule implements Recogniti
     WritableArray arr = Arguments.createArray();

     ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
-    for (String result : matches) {
-      arr.pushString(result);
+    if (matches != null) {
+      for (String result : matches) {
+        arr.pushString(result);
+      }
+
     }

+       if (results == null || results.isEmpty()) {
+         return;
+       }
+
     WritableMap event = Arguments.createMap();
     event.putArray("value", arr);
     sendEvent("onSpeechPartialResults", event);
@@ -345,10 +352,18 @@ public class VoiceModule extends ReactContextBaseJavaModule implements Recogniti
     WritableArray arr = Arguments.createArray();

     ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
-    for (String result : matches) {
-      arr.pushString(result);
+    if (matches != null) {
+      for (String result : matches) {
+        arr.pushString(result);
+      }
+
     }

+    if (results == null || results.isEmpty()) {
+      return;
+    }
+
+
     WritableMap event = Arguments.createMap();
     event.putArray("value", arr);
     sendEvent("onSpeechResults", event);
diff --git a/node_modules/@react-native-voice/voice/ios/Voice/Voice.m b/node_modules/@react-native-voice/voice/ios/Voice/Voice.m
index fd9dad8..4fae8e3 100644
--- a/node_modules/@react-native-voice/voice/ios/Voice/Voice.m
+++ b/node_modules/@react-native-voice/voice/ios/Voice/Voice.m
@@ -224,6 +224,7 @@ - (void) setupAndStartRecognizing:(NSString*)localeStr {
     @try {
         [mixer installTapOnBus:0 bufferSize:1024 format:recordingFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
             //Volume Level Metering
+            [buffer setFrameLength:buffer.frameCapacity];
             UInt32 inNumberFrames = buffer.frameLength;
             float LEVEL_LOWPASS_TRIG = 0.5;
             if(buffer.format.channelCount>0)

This issue body was partially generated by patch-package.

TowhidKashem commented 1 month ago

hey @SolankiYogesh3500 , would this patch make it compatible with the New Architecture (Fabric/Turbo-modules)? I think thats what you meant but just wanted to confirm..

SolankiYogesh3500 commented 1 month ago

No, it just fixes issues for React Native 0.75 (with the new architecture disabled). not yet tested with newArch

chqamarali commented 2 days ago

This package is not compatible with react-native 0.76 its working fine with react-native 0.75