csdcorp / speech_to_text

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

Haptic feedback does not work when recording #465

Closed bbader-kada closed 2 months ago

bbader-kada commented 4 months ago

Hello!

First of all, thank you for developing this fantastic package!

I came across an issue, like when I am listening to a SpeechToText recorder, the haptic feedbacks are not triggered.

Tested on real device: IOS 16.5, Iphone 13.

Screenshot 2023-12-03 at 20 21 50
sowens-csd commented 4 months ago

Are you using the HapticFeedback Dart class or a plugin? Does it stop working as soon as you initialize or only while a listen is active?

bbader-kada commented 4 months ago

The dart class. And after initialize.

sowens-csd commented 4 months ago

Turns out this is a known issue, with a possible resolution. Apple disables haptic feedback while the microphone is captured to prevent the haptics from interfering with speech recognition or other audio capture. There is a way to override this but I'm not sure whether it's a good idea in general.

How do you feel about the trade off between better audio quality and being able to trigger haptics?

https://stackoverflow.com/questions/44582128/how-can-i-play-a-haptic-feedback-while-avcapture-session-is-running

bbader-kada commented 4 months ago

I think it depends on the use case. In my for example, there is no way that user would use the speech recognition and receive haptic feedback at the same time. But I agree that in many cases it could lead to degradation in sound quality.

What about an option at initialization, to let everybody decide how would they like to do so based on their usage?

sowens-csd commented 4 months ago

Interesting, based on my reading of the issue it should only be true while listen is active, not after initialize. I think you've confirmed that Haptics are inactive immediately after initialize and before any listen call?

If the haptics were disabled only during an active listen session would that be a good solution for you?

bbader-kada commented 4 months ago

No sorry. I meant no matter what, it is disabled. So I have a listen section as well, but there I cannot use haptic also. So for me the perfect would be the option to enable the haptics while listening

sowens-csd commented 4 months ago

I just tried this on an iPhone Xs running iOS 16.7.1 and Haptics seems to work after initialize. The only time it does not work is when STT is actively listening. I tested this by adding a button in the example app that triggers a HapticFeedback.heavyImpact() call. I can feel the haptics before initialize, after initialize and after stopping a listen. I cannot feel haptics after clicking listen and before clicking stop.

I don't think that's the same behaviour that you're seeing? I think you were saying that haptics never works after STT has been initialized?

bbader-kada commented 4 months ago

Yes I am sorry, you are right. I dont know what happened back then. So yes, I cannot access haptic feedback only while there is an active listening. After just simply initilaize it works

bbader-kada commented 3 months ago

Hello @sowens-csd ! Happy new year!

Maybe any ideas on this?

sowens-csd commented 3 months ago

Happy New Year. Yes, it is on the list, probably for the next release.

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 haptics on iOS during recognition. I've changed the listen method to optionally use alistenOptions parameter instead of other individual parameters for the options. It is a SpeechListenOptions type which has enableHaptics 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.

bbader-kada commented 3 months ago

I tested it out, it works perfectly! Thank you so much again!