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

iOS: After several minutes of use, error_listen_failed errors may occur #481

Closed kakobayashi closed 1 month ago

kakobayashi commented 3 months ago

Thank you for providing us with a great package.

I have confirmed with Crashlytics that the error_listen_failed error may occur.

Device information

Flutter version

I'm in trouble understanding the cause of this error. I have forked this package, so I can log it into SwiftSpeechToTextPlugin.swift and provide the information.

Thank you.

sowens-csd commented 2 months ago

Thanks for the very thorough problem report. That's an interesting issue. I wonder if I'm leaking channels.

  1. Does the application use any other sound input, like WebRTC, sound recorder, etc?
  2. Do you have any idea how many sound recognition sessions did/could happen during the 10-15 minute period?
  3. Can you reproduce the problem?
kakobayashi commented 2 months ago

Thank you for your reply.

  1. My application includes the record package.

  2. I will add the logs in my app and check it. I am also asking the user who is getting this error.

  3. I have tried my iPhone15 Pro and could not get it to occur. However, I can confirm that it is occurring on the iPhone15 Pro on Crashlytics. I don't think it is a device issue.


Here is what I have tried to do

  1. The error did not change when AudioSession was regenerated when channelCount was 0, as shown below. https://github.com/kakobayashi/speech_to_text/blob/v6.4.1/autoPunctuation/speech_to_text/ios/Classes/SwiftSpeechToTextPlugin.swift#L397

  2. I have removed the "Not enough available inputs." error throw process so that the details of the error can be checked on the Flutter side, as shown below. https://github.com/kakobayashi/speech_to_text/blob/v6.4.1/autoPunctuation_v4/speech_to_text/ios/Classes/SwiftSpeechToTextPlugin.swift#L451-L452

I have checked the following logs

SpeechRecognitionError msg: error_listen_failed, permanent: true, detail: Error Domain=Try Code=1 "(null)" UserInfo={exception=required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat)} 0 48000.0

The audioSession.sampleRate was confirmed only at 48000. I have confirmed over 100 cases at 48000, but not occurring at other times.

I tried setting sampleRate to 48000 as shown below, but this did not fix this error.

      await _speechToText.listen(
        localeId: localeId,
        listenMode: ListenMode.dictation,
        onDevice: false,
        onResult: onResult,
        sampleRate: 48000,  // add
      );
sowens-csd commented 2 months ago

My first thought, since you're also using the record package in the app, is that the microphone is in use at the time STT is trying to install the tap. I don't know whether in your app it would be possible for the user to not enable or at least not use the record functionality and see if they can still reproduce the issue? If not perhaps you could get them on TestFlight and get them a version that allows for that test?

kakobayashi commented 2 months ago

I can ask the user who is experiencing this error to test the app without the record package for testing. I will try to distribute the app to this user on TestFlight.

Thank you.

kakobayashi commented 2 months ago

I distributed the app on TestFlight with the Record package removed. However, that app is getting the same error. I would like to know if you have any other thoughts.

kakobayashi commented 1 month ago

This error was occurring when the interstitial ads were not disposed properly. Thank you very much.