You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current behavior:
Error when trying to read text when in background mode
Expected behavior:
Read text
Steps to reproduce:
I'm trying to read a remote notification as soon as received, this works flawlessly in active mode, but when the app is in foreground it rejects the speak method with the message "session activation failed"
BTW category is set to 'playback'
I'm assuming, as the app receives the remote notification, it turns the app into active mode and the notification has a higher AV priority, so the request to setActive fails. With the snippet provided it works as expected, but since I'm not an expert, I would like you to address it (if you can)
Related code:
This is my workaround, added some tweaks...
@objc public func speak(_ text: String, _ lang: String, _ rate: Float, _ pitch: Float, _ category: String, _ volume: Float, _ voice : Int, _ call: CAPPluginCall) throws {
self.synthesizer.stopSpeaking(at: .immediate)
var avAudioSessionCategory = AVAudioSession.Category.ambient
if category != "ambient" {
avAudioSessionCategory = AVAudioSession.Category.playback
}
if #available(iOS 13.0, *) {
self.synthesizer.usesApplicationAudioSession = false
}
do {
try AVAudioSession.sharedInstance().setCategory(avAudioSessionCategory, mode: .default, options: AVAudioSession.CategoryOptions.duckOthers)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
// print(error)
}
self.calls.append(call)
let utterance = AVSpeechUtterance(string: text)
utterance.voice = AVSpeechSynthesisVoice(language: lang)
utterance.rate = adjustRate(rate)
utterance.pitchMultiplier = pitch
utterance.volume = volume
//Find the voice associated with the voice parameter if a voice specified.
//If the specified voice is not available we will fall back to default voice rather than raising an error.
if (voice >= 0) {
let allVoices = AVSpeechSynthesisVoice.speechVoices()
if (voice < allVoices.count) {
utterance.voice = allVoices[voice]
}
}
synthesizer.speak(utterance)
try AVAudioSession.sharedInstance().setActive(false)
}
Other information:
Capacitor doctor:
insert the output from `npx cap doctor` here
The text was updated successfully, but these errors were encountered:
@nemoneph I just updated the plug-in fn code to the ode I posted. To test it, just send the app to foreground and send a notification to read it aloud (I think you can simulate it)
Plugin version:
2.1.0
Platform(s):
iOS
Current behavior:
Error when trying to read text when in background mode
Expected behavior:
Read text
Steps to reproduce:
I'm trying to read a remote notification as soon as received, this works flawlessly in active mode, but when the app is in foreground it rejects the speak method with the message "session activation failed"
BTW category is set to 'playback'
I'm assuming, as the app receives the remote notification, it turns the app into active mode and the notification has a higher AV priority, so the request to setActive fails. With the snippet provided it works as expected, but since I'm not an expert, I would like you to address it (if you can)
Related code:
This is my workaround, added some tweaks...
Other information:
Capacitor doctor:
The text was updated successfully, but these errors were encountered: