Created
May 1, 2016 01:34
-
-
Save kddlb/bb403df656e2daa78f43fd714ab303dd to your computer and use it in GitHub Desktop.
Get all voices on an OS X system as a JSON
This file contains hidden or 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
#!/usr/bin/swift | |
import Foundation | |
import Cocoa | |
var voices = NSSpeechSynthesizer.availableVoices(); | |
var locale = NSLocale.init(localeIdentifier: "en-us"); | |
var voicesInfo = [String:AnyObject](); | |
for voice in voices { | |
var currentVoice = NSSpeechSynthesizer.attributesForVoice(voice); | |
var cvInfo = [String:AnyObject](); | |
cvInfo["name"] = currentVoice[NSVoiceName]!; | |
cvInfo["gender"] = currentVoice[NSVoiceGender]!; | |
cvInfo["language"] = currentVoice[NSVoiceLocaleIdentifier]!; | |
cvInfo["languageName"] = locale.displayNameForKey(NSLocaleIdentifier, value: cvInfo["language"]!); | |
cvInfo["demoText"] = currentVoice[NSVoiceDemoText]!; | |
voicesInfo[currentVoice[NSVoiceIdentifier]! as! String] = cvInfo; | |
} | |
var data = try NSJSONSerialization.dataWithJSONObject(voicesInfo, options: NSJSONWritingOptions.PrettyPrinted); | |
var dataString = NSString.init(data: data, encoding: NSUTF8StringEncoding) | |
print(dataString!); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment