建立基本的文字到語音
使用 AVSpeechSynthesizer
的 speakUtterance:
方法將文字轉換為語音。你需要將 AVSpeechUtterance
物件傳遞給此方法,該方法包含你要說出的文字。
目標 C.
AVSpeechSynthesizer *speaker = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *speech = [AVSpeechUtterance speechUtteranceWithString:@"Hello World"];
[speaker speakUtterance:speech];
迅速
let speaker = AVSpeechSynthesizer()
let speech = AVSpeechUtterance(string: "Hello World")
speaker.speakUtterance(speech)