Inspired by this question (which didn't receive an answer).
Context: I have a (swiftUI) view that has 2 buttons and a textfield. One button turns on the mic and uses SFSpeechrecognizer to turn speech into text (and fills the textfield). This is then sent to my server and my app receives a response, which is spoken through a AVSpeechSynthesizer. The mic is always on because the app is supposed to be conversational. Because of this, the spoken output is being captured by the mic.
Problem: I don't want to disable the mic when the response is spoken because I control my app through the microphone. Is it possible to make the mic (SFSpeechrecognizer ) ignore speech spoken by AVSpeechSynthesizer? Facetime does something similar by ignoring music played by your device.
My speech-to-text code is mostly modified of this.
text-to-speech snippet below:
let utterance = AVSpeechUtterance(string: serverResponse)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.rate = 0.1
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)