I have tried integrating in my App TTS, but there is no audio-output if I click the Button. Here is the Button code:
struct VocabDetailView: View {
//...
var body: some View {
//...
HStack{
Button("Play") {
readOut(text: "test")
}
}
}
}
//The code from readOut is:
func readOut(text: String) {
let utterance = AVSpeechUtterance(string: text)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
let synth = AVSpeechSynthesizer()
synth.speak(utterance)
}
In the Output field of Xcode is each time I click the button:
2022-11-12 09:53:08.349877+0100 Vocab-learner[2394:64531] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600000354580> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2022-11-12 09:53:19.528945+0100 Vocab-learner[2394:64592] [catalog] Unable to list voice folder
2022-11-12 09:53:19.539617+0100 Vocab-learner[2394:64592] [catalog] Unable to list voice folder
2022-11-12 09:53:19.543384+0100 Vocab-learner[2394:64592] [catalog] Unable to list voice folder
2022-11-12 09:53:19.551385+0100 Vocab-learner[2394:64592] [catalog] Unable to list voice folder
2022-11-12 09:53:19.566548+0100 Vocab-learner[2394:64916] [AXTTSCommon] File file:///System/Library/PrivateFrameworks/TextToSpeechMauiSupport.framework/Resources/TTSResources/en-US/Samantha/Contents/user_rules.txt contained data that was not null terminated
2022-11-12 09:53:19.573183+0100 Vocab-learner[2394:64916] [AXTTSCommon] File file:///tmp/com.apple.mobileassetd/AssetsV2/com_apple_MobileAsset_Trial_Siri_SiriTextToSpeech/purpose_auto/253115073e2b38c109deaac3e52d26ad44a84148.asset/AssetData/vocalizer-user-dict.dat contained data that was not null terminated
What does that mean? What do I need to do?
I changed language but it does not work either.
AVSpeechSynthesizer
is going out of scope and being deallocated. It needs to live at least as long as your utterance takes to be spoken, so assignsynth
to a member variable.