3

In my Swift program, I use AVSpeechSynthesizer to pronounce Chinese characters. This is my method:

static var synth = AVSpeechSynthesizer()

static func speak(string: String) 
{        
    let utterance = AVSpeechUtterance(string: string)
    utterance.voice = AVSpeechSynthesisVoice(language: "zh-CN")
    utterance.rate = 0.1

    synth.speak(utterance)
}  

Often, a single character can have multiple pronunciations. Is there a way to use AVSpeechSynthesizer to pronounce a character given the pinyin. In other words, instead of passing the character "高", we would pass the pinyin "gāo". So far, just passing the pinyin has not worked in this method.

Many thanks in advance,

Jon

Jonathan Rachlin
  • 333
  • 3
  • 13

2 Answers2

1

I think I've found the answer, and am posting it in case anybody else might find it useful. The pinyin should be entered in the form "gao1", not "gāo". It appears that it must be lower-case: i.e., "GAO1" doesn't seem to work, but "gao1" does.

Jonathan Rachlin
  • 333
  • 3
  • 13
0

In my view, using the IPA notation (International Phonetic Alphabet) is the best way to reach your goal.

Put an attributedString as incoming parameter of the AVSpeechUtterance instance after declaring its appropriate attribute.

Take a look at this WWDC 2018 video detailed summary that should help to use AVSpeechSynthesizer for Chinese pinyin pronunciation : helpful implementation can be found in this answer as well.

XLE_22
  • 3,693
  • 3
  • 12
  • 51