Skip to content

Instantly share code, notes, and snippets.

@rijieli
Created November 17, 2023 09:53
Show Gist options
  • Save rijieli/ff6591599b3af1ec3c6e4ead83a7261d to your computer and use it in GitHub Desktop.
Save rijieli/ff6591599b3af1ec3c6e4ead83a7261d to your computer and use it in GitHub Desktop.
Test the built-in voice speech on iOS
let allVoices = AVSpeechSynthesisVoice.speechVoices().filter { theVoice in
theVoice.language.contains("zh")
}
for idx in allVoices.indices {
let theVoice = allVoices[idx]
let lang = theVoice.language
let gender: String
if theVoice.gender == .male {
gender = "male"
} else if theVoice.gender == .female {
gender = "famale"
} else {
gender = "none"
}
print(".... [\(idx)] = \(gender) \(theVoice.identifier) \(lang)")
let utterance = AVSpeechUtterance(string: "归零归零清除归零 1 2 3 4 5 6 7 8 9 十 百 千 万 亿 + - * /")
utterance.voice = AVSpeechSynthesisVoice(identifier: theVoice.identifier)
synthesizer.speak(utterance)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment