Error with Text-To-Speech function on iPhone13 iOS16.4.1 app

I am experiencing an error with the Text-To-Speech function on my iPhone13 iOS16.4.1 app. The error message is "Unable to list voice folder" and "Failure starting audio queue". The audio output works fine on the simulator, but not on the actual device. I have included the full source code of the AVSpeechSynthesizer.swift file. Could you please help me resolve this issue?

Source code:

//
//  AVSpeechSynthesizer.swift
//  talkWithGPT
//
//  Created by AIEN on 2023/04/24.
//

// AVSpeechSynthesizer.swift

import AVFoundation
import SwiftUI

class TextToSpeech: NSObject, ObservableObject, AVSpeechSynthesizerDelegate {
    private let speechSynthesizer = AVSpeechSynthesizer()
    private var completion: (() -> Void)?
    
    override init() {
        super.init()
        speechSynthesizer.delegate = self
        configureAudioSession()
    }
    
    private func configureAudioSession() {
        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .duckOthers])
            try audioSession.setActive(true)
        } catch {
            print("Failed to set up audio session: \(error.localizedDescription)")
        }
    }
    
    func speak(text: String, completion: @escaping () -> Void) {
        if !speechSynthesizer.isSpeaking {
            let utterance = AVSpeechUtterance(string: text)
            utterance.voice = AVSpeechSynthesisVoice(language: "ja-JP")
            utterance.volume = 0.8
            utterance.rate = AVSpeechUtteranceDefaultSpeechRate
            self.completion = completion
            print("嗚呼あ")
            speechSynthesizer.speak(utterance)
        }
    }
    
    func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
        // ここに読み上げが終わった後の処理を記述します
        completion?() // コールバックを実行
    }
    
    func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didStart utterance: AVSpeechUtterance) {
        print("音声合成が開始されました。")
    }
    
}

error message

2023-04-25 19:55:00.895677+0900 talkWithGPT[460:13481] [catalog] Unable to list voice folder
2023-04-25 19:55:00.910741+0900 talkWithGPT[460:13481] [catalog] Unable to list voice folder
2023-04-25 19:55:00.914461+0900 talkWithGPT[460:13481] [catalog] Unable to list voice folder
2023-04-25 19:55:00.932377+0900 talkWithGPT[460:13481] [catalog] Unable to list voice folder
2023-04-25 19:55:00.948172+0900 talkWithGPT[460:13481] [catalog] Query for com.apple.MobileAsset.VoiceServices.VoiceResources failed: 2
2023-04-25 19:55:00.984112+0900 talkWithGPT[460:13571] [AXTTSCommon] MauiVocalizer: 11016 (Ruleset parse failed: Ignoring unknown option): option=/
音声合成が開始されました。
2023-04-25 19:55:01.066629+0900 talkWithGPT[460:13571] [AXTTSCommon] Failure starting audio queue \M-3<…>
2023-04-25 19:55
1 Like

Have you deal with this problem?
I meet the same problem with you last week, and now my project worked!

this is the way you can try:
my device is iphone13pro system:17.0.3

设置 -> 辅助功能 -> 实时语音 -> 声音 , 然后 随便下载几个语音。

i download siri(en-us, en-gb)