Monday, April 1, 2024
HomeiOS Developmentios - Textual content-To-Speech: Thread operating at Person-interactive quality-of-service class ready on...

ios – Textual content-To-Speech: Thread operating at Person-interactive quality-of-service class ready on a decrease QoS thread operating at Default quality-of-service class


I created an app with text-to-speech assist. And Xcode gave me this “Thread Efficiency warning” as soon as app is launched or begin communicate a textual content, I am utilizing an actual iPhone. It appears like thread concerning AVSpeechSynthesizer has the upper precedence than the thread to attract the UI.

Easy methods to repair this, please recommendation? Under is a few code snippet from my app.

@principal
struct SpeakhbyApp: App {
    @StateObject var voiceManager = VoiceManager()
    @StateObject var textViewModel = TextViewModel()
    @StateObject var homeViewState = HomeViewState.shared
    
    var physique: some Scene {
        WindowGroup {
            HomeScreenView()
                .environmentObject(voiceManager)
                .environmentObject(textViewModel)
                .environmentObject(homeViewState)
        }
    }
}
class VoiceManager: NSObject, ObservableObject, AVSpeechSynthesizerDelegate {
    // Create a speech synthesizer.
    personal let synthesizer = AVSpeechSynthesizer()
    // Used as spotlight phrase of Textual content-to-Speech
    @Printed var attributedText: NSAttributedString?
    
    
    override init() {
        tremendous.init()
        synthesizer.delegate = self
    }
    
    personal func createUtterance(_ textual content: String) -> AVSpeechUtterance {
        // Create an utterance.
        let utterance = AVSpeechUtterance(string: textual content)

        // Configure the utterance.
        utterance.charge = 0.5
        utterance.pitchMultiplier = 0.8
        utterance.postUtteranceDelay = 0.2
        utterance.quantity = 0.8

        // Retrieve the British English voice.
        let voice = AVSpeechSynthesisVoice(language: "en-US")

        // Assign the voice to the utterance.
        utterance.voice = voice
        
        return utterance
    }
    
    func communicate(_ textual content: String) {
        let utterance = createUtterance(textual content)
        synthesizer.communicate(utterance)
    }
    
    func pauseSpeaking(at boundary: AVSpeechBoundary = .phrase) {
        synthesizer.pauseSpeaking(at: boundary)
    }
    
    func continueSpeaking() {
        synthesizer.continueSpeaking()
    }
    
    func stopSpeaking() {
        synthesizer.stopSpeaking(at: .phrase)
    }

    var isSpeaking: Bool {
        synthesizer.isSpeaking
    }
    
    var isPaused: Bool {
        synthesizer.isPaused
    }
    
    var isNotStarted: Bool {
        !synthesizer.isSpeaking
    }
    
    // MARK: Delegate features to spotlight textual content
    func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) {
        let mutableAttributedString = NSMutableAttributedString(string: utterance.speechString)
//        mutableAttributedString.addAttribute(.foregroundColor, worth: UIColor.blue, vary: characterRange)
        mutableAttributedString.addAttribute(.backgroundColor, worth: UIColor.yellow, vary: characterRange)
        
        attributedText = mutableAttributedString
    }
    
    func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
        attributedText = NSAttributedString(string: utterance.speechString)
        HomeViewState.shared.isSpeaking = false
    }
}
struct TextView: UIViewRepresentable {
    @EnvironmentObject personal var textViewModel: TextViewModel
    @EnvironmentObject personal var voiceManager: VoiceManager
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
        
    func makeUIView(context: Context) -> UITextView {
        let textView = UITextView()
        textView.delegate = context.coordinator
        
        textView.font = UIFont(identify: "Instances New Roman", dimension: 18)
        textView.textContainerInset = .init(prime: 10, left: 10, backside: 10, proper: 10)
        textView.isScrollEnabled = true
        textView.isEditable = true
        textView.isUserInteractionEnabled = true
        textView.backgroundColor = .lightGreen20
        
        return textView
    }
    
    func updateUIView(_ uiView: UITextView, context: Context) {
        if !voiceManager.isSpeaking {
            let attStr = NSMutableAttributedString(string: textViewModel.textual content)
            let pStyle = NSMutableParagraphStyle()
            pStyle.lineSpacing = 3
            attStr.addAttribute(.paragraphStyle, worth: pStyle, vary: NSMakeRange(0, attStr.size))
            attStr.addAttribute(.font, worth: UIFont(identify: "TimesNewRomanPS-BoldMT", dimension: 18)!, vary: NSMakeRange(0, attStr.size))
            
            uiView.attributedText = attStr
        } else {
            let attStr = NSMutableAttributedString(attributedString: voiceManager.attributedText!)
            let pStyle = NSMutableParagraphStyle()
            pStyle.lineSpacing = 3
            attStr.addAttribute(.paragraphStyle, worth: pStyle, vary: NSMakeRange(0, attStr.size))
            attStr.addAttribute(.font, worth: UIFont(identify: "TimesNewRomanPS-BoldMT", dimension: 18)!, vary: NSMakeRange(0, attStr.size))
            
            uiView.attributedText = attStr
        }
    }
Thread Efficiency Checker: Thread operating at Person-interactive quality-of-service class ready on a decrease QoS thread operating at Default quality-of-service class. Examine methods to keep away from precedence inversions
PID: 624, TID: 32010
Backtrace
=================================================================
3   Basis                          0x00000001957e5370 31D526A2-AB5C-3B1D-BCA5-B1E082D94712 + 7668592
4   Basis                          0x0000000195170820 31D526A2-AB5C-3B1D-BCA5-B1E082D94712 + 899104
5   Basis                          0x00000001951920bc 31D526A2-AB5C-3B1D-BCA5-B1E082D94712 + 1036476
6   TextToSpeech                        0x00000001b74d2268 TTSSpeechTransformTextWithLanguageAndVoiceIdentifier + 5132
7   TextToSpeech                        0x00000001b74d7910 AXAVSpeechSynthesisVoiceFromTTSSpeechVoice + 13132
8   TextToSpeech                        0x00000001b74cfa10 _TTSIdentifierForVoiceInformation + 17508
9   Speakhby                            0x0000000100fa7ffc $s8Speakhby12VoiceManagerC10isSpeakingSbvg + 60
10  Speakhby                            0x0000000100f94be0 $s8Speakhby8TextViewV12updateUIView_7contextySo06UITextC0C_7SwiftUI0E20RepresentableContextVyACGtF + 228
11  Speakhby                            0x0000000100f96148 $s8Speakhby8TextViewV7SwiftUI19UIViewRepresentableAadEP06updateF0_7contexty0F4TypeQz_AD0fG7ContextVyxGtFTW + 28
12  SwiftUI                             0x000000019b88593c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25483580
13  SwiftUI                             0x000000019b78d998 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24467864
14  SwiftUI                             0x000000019b78d854 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24467540
15  SwiftUI                             0x000000019b76c744 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24332100
16  SwiftUI                             0x000000019b78d6dc 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24467164
17  SwiftUI                             0x000000019b78d3c4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24466372
18  SwiftUI                             0x000000019b78c05c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24461404
19  SwiftUI                             0x000000019a178bf8 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 1313784
20  AttributeGraph                      0x00000001becdc240 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 49728
21  AttributeGraph                      0x00000001becd2f38 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 12088
22  AttributeGraph                      0x00000001becd2810 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 10256
23  AttributeGraph                      0x00000001becd23a4 AGGraphGetValue + 228
24  SwiftUI                             0x000000019b78e3ac 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24470444
25  SwiftUI                             0x000000019b78e59c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24470940
26  SwiftUI                             0x000000019a178bf8 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 1313784
27  AttributeGraph                      0x00000001becdc240 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 49728
28  AttributeGraph                      0x00000001becd2f38 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 12088
29  AttributeGraph                      0x00000001becd2630 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 9776
30  AttributeGraph                      0x00000001becdcf9c AGGraphGetInputValue + 248
31  SwiftUI                             0x000000019aad4bf8 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 11127800
32  SwiftUI                             0x000000019ac49a38 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12655160
33  SwiftUI                             0x000000019ac4a294 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12657300
34  SwiftUI                             0x000000019af54168 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 15843688
35  SwiftUI                             0x000000019af53fec 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 15843308
36  SwiftUI                             0x000000019af53c90 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 15842448
37  SwiftUI                             0x000000019b8cc940 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25774400
38  SwiftUI                             0x000000019b8ce350 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25781072
39  SwiftUI                             0x000000019aec804c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 15269964
40  SwiftUI                             0x000000019ad20494 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13534356
41  SwiftUI                             0x000000019ad1fc90 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13532304
42  SwiftUI                             0x000000019ad20c3c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13536316
43  SwiftUI                             0x000000019ad1e8b0 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13527216
44  SwiftUI                             0x000000019ac329b4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12560820
45  SwiftUI                             0x000000019ac330c4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12562628
46  SwiftUI                             0x000000019b2813a4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 19174308
47  SwiftUI                             0x000000019b281170 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 19173744
48  SwiftUI                             0x000000019b8ce2ac 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25780908
49  SwiftUI                             0x000000019aad501c 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 11128860
50  SwiftUI                             0x000000019b8f8674 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25953908
51  SwiftUI                             0x000000019b2813a4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 19174308
52  SwiftUI                             0x000000019b281170 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 19173744
53  SwiftUI                             0x000000019b8ce2ac 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 25780908
54  SwiftUI                             0x000000019acbcf14 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13127444
55  SwiftUI                             0x000000019afc1fc0 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 16293824
56  AttributeGraph                      0x00000001becdc240 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 49728
57  AttributeGraph                      0x00000001becd2f38 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 12088
58  AttributeGraph                      0x00000001becd2810 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 10256
59  AttributeGraph                      0x00000001becd23a4 AGGraphGetValue + 228
60  SwiftUI                             0x000000019ac00dfc 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12357116
61  SwiftUI                             0x000000019ac01044 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12357700
62  SwiftUI                             0x000000019a2630ac 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 2273452
63  AttributeGraph                      0x00000001becdc240 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 49728
64  AttributeGraph                      0x00000001becd2f38 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 12088
65  AttributeGraph                      0x00000001becd2810 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 10256
66  AttributeGraph                      0x00000001becd23a4 AGGraphGetValue + 228
67  SwiftUI                             0x000000019b73bd60 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24132960
68  SwiftUI                             0x000000019a5b1ae8 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 5741288
69  AttributeGraph                      0x00000001becdc240 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 49728
70  AttributeGraph                      0x00000001becd2f38 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 12088
71  AttributeGraph                      0x00000001becdd948 8E86675A-D6CF-38E1-818E-4C09C7294F17 + 55624
72  SwiftUI                             0x000000019acba918 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 13117720
73  SwiftUI                             0x000000019b76b674 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24327796
74  SwiftUI                             0x000000019b76b028 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24326184
75  SwiftUI                             0x000000019b769170 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24318320
76  SwiftUI                             0x000000019b7d9164 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24777060
77  SwiftUI                             0x000000019b7d91c4 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 24777156
78  UIKitCore                           0x00000001984ad0f8 86B7C8DD-E910-31BD-B8FE-28962256DEE3 + 209144
79  QuartzCore                          0x00000001978d7e30 F6A8231B-CB24-3EAE-BA29-0E9E675213A3 + 421424
80  QuartzCore                          0x00000001978d79b4 F6A8231B-CB24-3EAE-BA29-0E9E675213A3 + 420276
81  QuartzCore                          0x00000001978ddbb4 F6A8231B-CB24-3EAE-BA29-0E9E675213A3 + 445364
82  QuartzCore                          0x00000001978d71bc F6A8231B-CB24-3EAE-BA29-0E9E675213A3 + 418236
83  UIKitCore                           0x0000000198793d40 86B7C8DD-E910-31BD-B8FE-28962256DEE3 + 3251520
84  CoreFoundation                      0x00000001962356b8 7A70D5D4-0550-38DC-AB33-71B72AFF1F5F + 227000
85  CoreFoundation                      0x0000000196233eac 7A70D5D4-0550-38DC-AB33-71B72AFF1F5F + 220844
86  CoreFoundation                      0x0000000196231d9c 7A70D5D4-0550-38DC-AB33-71B72AFF1F5F + 212380
87  CoreFoundation                      0x0000000196231968 CFRunLoopRunSpecific + 608
88  GraphicsServices                    0x00000001da52f4e0 GSEventRunModal + 164
89  UIKitCore                           0x00000001986a4edc 86B7C8DD-E910-31BD-B8FE-28962256DEE3 + 2272988
90  UIKitCore                           0x00000001986a4518 UIApplicationMain + 340
91  SwiftUI                             0x000000019b06b860 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 16988256
92  SwiftUI                             0x000000019b06b6a8 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 16987816
93  SwiftUI                             0x000000019ac879fc 9B6AC5DA-C8CE-3B73-8B29-487E9281983F + 12909052
94  Speakhby                            0x0000000100fa4488 $s8Speakhby0A3AppV5$mainyyFZ + 40
95  Speakhby                            0x0000000100fa48ec principal + 12
96  dyld                                0x00000001b9752d84 960A7452-3178-3C9D-8CE5-FE40FDE8DBC8 + 23940



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments