Switch voice on AVSpeechSynthesizer is causing "[AXTTSCommon] Invalid rule"

Simplifying, if I implement a code like the following

let utterance = AVSpeechUtterance(string: "Hello world.")
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
self.synthesizer.speak(utterance)

let utterance = AVSpeechUtterance(string: "Hola mundo.")
utterance.voice = AVSpeechSynthesisVoice(language: "es-ES")
self.synthesizer.speak(utterance)

After the second speak, I get the following error messages from the console

[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(1\/2\s?)(mm|cm|m|m²|m2|m³|m3|km|km²|km2|km³|km3|mg|g|kg|l|ml)\b/i --> "M_FRACTION_OF_$1 EXPANSION_SG_OF_$2" # 1/2 mm --> medio milímetro
[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(\d\/\d\s?)(mm|cm|m|m²|m2|m³|m3|km|km²|km2|km³|km3|mg|g|kg|l|ml)\b/i --> "M_FRACTION_OF_$1 de EXPANSION_SG_OF_$2" # 1/4 km² --> un cuarto de kilómetro cuadrado"
[AXTTSCommon] Invalid rule: /(?<=\d\s)(\d\/\d\s?)(mm|cm|m|m²|m2|m³|m3|km|km²|km2|km³|km3|mg|g|kg|l|ml)\b/i --> "$2 y M_FRACTION_OF_$1" # 1/6m --> un sexto de metro
[AXTTSCommon] Invalid rule: /(1\/2\s)(milímetro|centímetro|metro|metro cuadrado|metro cúbico|kilómetro|kilómetro cuadrado|kilómetro cúbico|miligramo|gramo|kilo|kilogramo|mililitro|litro)\b/i --> "M_FRACTION_OF_$1 $2" # 1/2 milímetro --> medio milímetro
[AXTTSCommon] Invalid rule: /(milímetros?|centímetros?|metros?|metros? cuadrados?|metros? cúbicos?|kilómetros?|kilómetros? cuadrados?|kilómetros? cúbicos?|miligramos?|gramos?|kilos?|kilogramos?|mililitros?|litros?)\sy?\s?(1\/2)\b/i --> "$1 y M_FRACTION_OF_$2" # 3 metros y 1/2 --> tres metros y medio
[AXTTSCommon] Invalid rule: /M_FRACTION_OF_1\/2/ --> "medio" # 1/2 m --> medio metro
[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(\d\/\d\s?)(milímetros?|centímetros?|metros?|metros? cuadrados?|metros? cúbicos?|kilómetros?|kilómetros? cuadrados?|kilómetros? cúbicos?|miligramoS?|gramos?|kilos?|kilogramos?|mililitros?|litros?)\b/i --> "M_FRACTION_OF_$1 de $2" # 1/4 kilómetro --> un cuarto de kilómetro
[AXTTSCommon] Invalid rule: /(?<=\d\s)(\d\/\d\s?)(milímetros?|centímetros?|metros?|metros? cuadrados?|metro cúbicos?|kilómetros?|kilómetros? cuadrados?|kilómetros? cúbicos?|miligramos?|gramos?|kilos?|kilogramos?|mililitros?|litros?)\b/i --> "$2 y M_FRACTION_OF_$1" # 2 1/4 kilómetros --> dos kilómetros y un cuarto
[AXTTSCommon] Invalid rule: /(milímetros?|centímetros?|metros?|metro cuadrados?|metro cúbicos?|kilómetros?|kilómetro cuadrados?|kilómetro cúbicos?|miligramos?|gramos?|kilos?|kilogramos?|mililitros?|litros?)\sy?\s?(\d\/\d\s?)/ --> "$1 y M_FRACTION_OF_$2" # 2 milímetros y 1/2 --> dos milímetros y medio
[AXTTSCommon] Invalid rule: /M_FRACTION_OF_(\d\/\d)/ --> "\e\\tn=fraction\\$1\e\\tn=normal\\" # 1/4 --> un cuarto
[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(\d\/\d\s)(?=de (pan|masa|taza|hora)\b)/i --> "\e\\tn=fraction\\$1\e\\tn=normal\\" # 1/4 de pan --> un cuarto de pan
[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(\d\/\d\s)(?=de (milímetros?|centímetros?|metros?|metro cuadrados?|metro cúbicos?|kilómetros?|kilómetro cuadrados?|kilómetro cúbicos?|miligramos?|gramos?|kilos?|kilogramos?|mililitros?|litros?)\b)/i --> "\e\\tn=fraction\\$1\e\\tn=normal\\" # 1/4 de metro --> un cuarto de metro
[AXTTSCommon] Invalid rule: /(?<!\d|\d\s)(\d\/\d\s)/ --> "\e\\tn=fraction\\$1\e\\tn=normal\\" # catch-all rule for fractions, to avoid "1/4" --> "uno cuatro"

The final behavior is correct, the expression is reproduced despite de console messages. However, after approximately 400 iterations the application consumes all memory resources in processes related to AXTTSCommon and Regex.

Problem solved. I was returning the wrong type in a method within the context of my code's logic.

Can you elaborate more on what it is you fixed? I'm currently running into the same issue

@computerdude Same here. What exactly did you do wrong in the first place, and how did you fix the issue?

First of all thank you all for downvoting me, it really improves the chances of me leaving an answer.

In my case it was a Flutter custom plugin issue, the problem was solved by changing:

func speak(_ text: String) {
           textToSpeech.speak(text)
       }

by

func speak(_ text: String, result: @escaping FlutterResult) {
        textToSpeech.speak(text, result: result)
}
Switch voice on AVSpeechSynthesizer is causing "[AXTTSCommon] Invalid rule"
 
 
Q