Im building an app that translate audio in background on live. I display a overlay over apps and i want to record the audio to translate in real time. But in android 13 the audio recording stops after a few secods recording. I guess that the problem is for the security of the user, but im looking for a second opinion
Im using the SpeechRecognizer library. But I receive recommendations
Added a piece of code
AndroidManifiest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<service
            android:name=".feature.overlay.OverlayService"
            android:exported="false"
            android:foregroundServiceType="microphone"/>
OverlayService
override fun onCreate() {
        super.onCreate()
        windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
        configureSpeechToText()
        windowManager.addView(layoutText,params)
    }
fun configureSpeechToText() {
        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
        speechRecognizerIntent.putExtra(
            RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
        )
        speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
        speechRecognizer?.setRecognitionListener(object : RecognitionListener {
            override fun onReadyForSpeech(bundle: Bundle) {}
            override fun onBeginningOfSpeech() {}
            override fun onRmsChanged(v: Float) {}
            override fun onBufferReceived(bytes: ByteArray) {}
            override fun onEndOfSpeech() {}
            override fun onError(i: Int) {
                val errorMessage = getErrorText(i)
                Log.d("Error", "FAILED: $errorMessage")
            }
            override fun onResults(bundle: Bundle) {
                val data = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
                dataVoiceText = data!![0]
                run(dataVoiceText)//The function that translate the text
            }
            override fun onPartialResults(bundle: Bundle) {}
            override fun onEvent(i: Int, bundle: Bundle) {}
        })
        handler.postDelayed(Runnable {//Run this code every few seconds to translate every few seconds
            handler.postDelayed(runnable!!, delay.toLong())
            speechRecognizer?.stopListening()
            speechRecognizer?.startListening(speechRecognizerIntent)
        }.also { runnable = it }, delay.toLong())
    }
Im trying to record audio in background with a service, im expecting to it continously record the audio. but right now it is stoping