react-native-voice / voice

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

Automatic Punctuation #355

Open ilyakar opened 2 years ago

ilyakar commented 2 years ago

Is there a way to have the punctuation automatically added to the text? e.g., "question mark".

mauricekenji commented 1 year ago

+100. How might we get this functionality?

DraghiciAdrian commented 1 year ago

I am also looking for a solution for this. Any ideas?

Tom-Standen commented 9 months ago

Me too! Would be great for voice notes, longer dictations

comontes commented 6 months ago

I think this would help for iOS https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation

comontes commented 6 months ago

Ok, so using patch-package I changed:


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..6f13745 100644
--- a/node_modules/@react-native-voice/voice/ios/Voice/Voice.m
+++ b/node_modules/@react-native-voice/voice/ios/Voice/Voice.m
@@ -153,6 +153,11 @@ - (void) setupAndStartRecognizing:(NSString*)localeStr {
     // Configure request so that results are returned before audio recording is finished
     self.recognitionRequest.shouldReportPartialResults = YES;

+    // Configure request to add punctuation to speech recognition results.
+    if (@available(iOS 16.0, *)) {
+        self.recognitionRequest.addsPunctuation = YES;
+    }
+
     if (self.recognitionRequest == nil) {
         [self sendResult:@{@"code": @"recognition_init"} :nil :nil :nil];
         [self teardown];

Steps using Yarn:

  1. Install packages:

    yarn add --dev patch-package postinstall-postinstall
  2. In package.json add a script:

    "scripts": {
    +  "postinstall": "patch-package"
    }
  3. Modify file, open node_modules/@react-native-voice/voice/ios/Voice/Voice.m:

Add these lines after self.recognitionRequest.shouldReportPartialResults = YES;

    // Configure request to add punctuation to speech recognition results.
    if (@available(iOS 16.0, *)) {
        self.recognitionRequest.addsPunctuation = YES;
    }
  1. Create patch file running:

    yarn patch-package @react-native-voice/voice
  2. Build app again, I used eas build.

  3. Enjoy

tigerjiang commented 6 months ago

Is there any update? I want to get the proper punctuation on Android, Thanks