Created
November 17, 2023 09:53
-
-
Save rijieli/ff6591599b3af1ec3c6e4ead83a7261d to your computer and use it in GitHub Desktop.
Test the built-in voice speech on iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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