csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
351 stars 218 forks source link

Support automatic punctuation #430

Closed marwan-at-work closed 3 months ago

marwan-at-work commented 8 months ago

Hi there,

Thank you for this very helpful package!

The iOS implementation has the following option which I don't see in Dart: https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation?changes=_9

Would it be possible to add this option to the Dart side? I'm not familiar enough with either languages but happy to help however I can.

Thanks

sowens-csd commented 8 months ago

Good suggestion, thank you.

TomTom101 commented 5 months ago

Just noticed myself that dictation on macOS 14 (Sonoma) has become really excellent (everyone has their eyes on Whisper and friends) and also recognizes questions on the spot. However, very unfortunately not the package here. Would love to see the same punctation as macOS does! 🙏🏼

andida commented 5 months ago

Hi there,

Thank you for this very helpful package!

The iOS implementation has the following option which I don't see in Dart: https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation?changes=_9

Would it be possible to add this option to the Dart side? I'm not familiar enough with either languages but happy to help however I can.

Thanks

you can add this feature at SwiftSpeechToTextPlugin.swift. add the code in listenForSpeech function: if #available(iOS 16, *) { currentRequest.addsPunctuation = true }

filippkowalski commented 3 months ago

I understand that the idea is to have the library as unified as possible, but it would be awesome to have a flag that enables punctuation for iOS devices without having to fork the library and add it separately 🙏

sowens-csd commented 3 months ago

There is a new version in pub.dev now, 6.6.0-dev which supports an option to enable automatic punctuation on iOS during recognition. I've changed the listen method to optionally use a listenOptions parameter instead of other individual parameters for the options. It is a SpeechListenOptions type which has autoPunctuation as an available option. So it would look like this:

    final options = SpeechListenOptions(
        onDevice: _onDevice,
        listenMode: ListenMode.confirmation,
        cancelOnError: true,
        partialResults: true,
        autoPunctuation: true,
        enableHapticFeedback: true);
    speech.listen(
      onResult: resultListener,
      listenFor: Duration(seconds: listenFor ?? 30),
      pauseFor: Duration(seconds: pauseFor ?? 3),
      localeId: _currentLocaleId,
      onSoundLevelChange: soundLevelListener,
      listenOptions: options,
    );

Please let me know if you have a chance to try it.

filippkowalski commented 3 months ago

@sowens-csd thank you very much 🙏 I was about to fork the repo this/next week so I'm super stoked that you took your time to add it to your library

btw. I'd love to buy you a virtual coffee if you have a website set up for it

filippkowalski commented 3 months ago

I might be biased but it feels like the recent update made the initialization process much slower @sowens-csd

I'm using 6.6.0-dev

sowens-csd commented 3 months ago

Interesting, it shouldn't have changed at all. I can't think of anything recent that would have affected the initialization. What kind of time difference are you seeing?

filippkowalski commented 3 months ago

If there is no clear change on your side that should affect this then let me measure it on both versions and report back to you , maybe it's a mistake on my side @sowens-csd

filippkowalski commented 3 months ago

Ok, works ok now. Sorry, false alarm.

sowens-csd commented 3 months ago

Thanks for verifying and for letting me know.