AVSpeechSynthesizer pulls words out of thin air.

Hi,

I'm working on a project that uses the AVSpeechSynthesizer and AVSpeechUtterance.

I discovered by chance that the AVSpeechSynthesizer automatically completes some words instead of just outputting what it's supposed to.

These are abbreviations for days of the week or months, but not all of them. I don't want either of them automatically completed, but only the specified text. The completion transcends languages.

I have written a short example program for demonstration purposes.

import SwiftUI
import AVFoundation
import Foundation

let synthesizer: AVSpeechSynthesizer = AVSpeechSynthesizer()

struct ContentView: View {
    var body: some View {
        VStack {
            Button {
                utter("mon")
            } label: {
                Text("mon")
            }
            .buttonStyle(.borderedProminent)
            
            Button {
                utter("tue")
            } label: {
                Text("tue")
            }
            .buttonStyle(.borderedProminent)
            
            Button {
                utter("thu")
            } label: {
                Text("thu")
            }
            .buttonStyle(.borderedProminent)
            
            Button {
                utter("feb")
            } label: {
                Text("feb")
            }
            .buttonStyle(.borderedProminent)
            
            Button {
                utter("feb", lang: "de-DE")
            } label: {
                Text("feb DE")
            }
            .buttonStyle(.borderedProminent)
            
            Button {
                utter("wed")
            } label: {
                Text("wed")
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }
    
    private func utter(_ text: String, lang: String = "en-US") {
        let utterance = AVSpeechUtterance(string: text)
        let voice = AVSpeechSynthesisVoice(language: lang)
        
        utterance.voice = voice
        synthesizer.speak(utterance)
    }
   
}

#Preview {
    ContentView()
}

Thank you

Christian

AVSpeechSynthesizer pulls words out of thin air.
 
 
Q