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: When audio is used by another app, STT stops working, but "SpeechRecognitionError" shows no errors and "isListening" shows true #470

Open kodjima33 opened 4 months ago

kodjima33 commented 4 months ago

Steps to reproduce 1) Copy the code from the official guide or code example that I use, that I copied from here with ErrorListener and add "isListening" status check 2) Start Speech recognition process in IOS app 3) Hover/collapse app (speech recording is still active) 4) Open any app that uses audio or start music on same device 5) Speech-to-text stops functioning

Note: if you skip steps 3&4, result will be same

Expected:

Actual result SpeechRecognitionError will show no errors isListening status shows "True"

Example screenshot in Xcode: https://share.cleanshot.com/wYNyM1qs

Environment: iPhone 15, iOS 17

speech_to_text version: latest

What I tried to do: researched 20+ topics and issues regarding continuous use like this but didn't find anything that solves my usecase

I'm not very technical, but If anyone has dealt with this before and could help - would love to pay. My email is kodjima33@gmail.com and telegram is @kodjima33

OmAr-Kader commented 4 months ago

Upwork

Actually STT still working for your app audio(which it stopped) but it is isolated from device sound(other app's audio).

developer.apple

Screenshot 2024-01-02 073013

Unfortunately, it is not a trivial task to get access to the system sound output (which is probably a good thing, from a security standpoint).

The solutions will generally involve setting up a 'fake' audio device that audio can get played through instead of the default output device you've chosen, and you need "Method channel" for that (Not Flutter)

But if you just want to detect "isListening," you can handle audio interruptions separately

Kaival-Patel commented 3 months ago

Came from Upwork :) Have you tried this package https://pub.dev/packages/audio_service

For overriding the default settings for the audio services for iPhone as I have worked with this in past and working fine? My usecase was to record the sound from mic when video is playing. (Recording the voiceover)

sowens-csd commented 3 months ago

If you add a step 6 and bring the STT app back to the foreground does the active listening session still work? Or does it only work once a new listening session is started?

kodjima33 commented 3 months ago

@sowens-csd

If you add a step 6 and bring the STT app back to the foreground does the active listening session still work? Or does it only work once a new listening session is started?

I think it only works once we kill STT and then start a new listening session, but the problem is that we cannot even restart it because we don't know if the speech STT stopped listening or is still active. Because there are no errors.

However we found a trick with looking at invokeFlutter: soundlevel change

sowens-csd commented 3 months ago

Thanks for the clarification. I'll have a look at detecting that error. Hopefully doable.

hassanrazzaq8 commented 1 month ago

@Kaival-Patel my use case is same to yours like I want to use speech to text in iOS while running music but starting speechtotext effect on music and when I try to stop speech to text it also stops the music I am using just_audio ignorer to play the music @sowens-csd