Friday, December 29, 2023
HomeiOS Developmentswift - AVSpeechSynthesizer is just not engaged on iOS 17 Xcode 15.1

swift – AVSpeechSynthesizer is just not engaged on iOS 17 Xcode 15.1


I’m making an attempt to make use of text-to-speech characteristic on my app and all of a sudden I feel after updating to iOS 17.2 this perform is disabled as a substitute, and I get these errors whereas making an attempt to make use of speakWord perform.

#FactoryInstall Unable to question outcomes, error: 5
Unable to checklist voice folder
Unable to checklist voice folder
Unable to checklist voice folder
Unable to checklist voice folder
Unable to checklist voice folder
tcp_output [C1.1.1.1:3] flags=[R.] seq=3918325251, ack=3203309855, win=2047 state=CLOSED rcv_nxt=3203309855, snd_una=3918325174

Right here is the total class:

class TextToSpeech {

    static let shared = TextToSpeech()
    non-public let speechSynthesizer = AVSpeechSynthesizer()

    func speakWord(matching textual content: String, from phrases: [String]) {
        // Concatenate the array of phrases right into a single textual content for higher language detection
        let combinedText = phrases.joined(separator: " ")

        // Detect the language of the mixed textual content
        let languageCode = detectLanguage(for: combinedText)

        for phrase in phrases {
            if phrase.lowercased() == textual content.lowercased() {
                // Communicate the matching phrase
                communicate(phrase, withLanguageCode: languageCode)
                break
            }
        }
    }

    non-public func communicate(_ textual content: String, withLanguageCode languageCode: String) {
        // Configure the voice based mostly on the detected language
        let voice = AVSpeechSynthesisVoice(language: languageCode)

        // Create an AVSpeechUtterance occasion
        let utterance = AVSpeechUtterance(string: textual content)
        utterance.voice = voice

        // Use DispatchQueue to make sure speech synthesis does not block the principle thread
        DispatchQueue.essential.async {
            self.speechSynthesizer.communicate(utterance)
        }
    }

    non-public func detectLanguage(for textual content: String) -> String {
        let recognizer = NLLanguageRecognizer()
        recognizer.processString(textual content)
        guard let languageCode = recognizer.dominantLanguage?.rawValue else {
            return "en-US" // Default to English if detection fails
        }
        return languageCode
    }
}

is there any doable resolution to repair this bug?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments