AppleScript名:TTS Voiceを言語と性別で抽出 |
— Created 2017-03-28 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set aLoc to (current application’s NSLocale’s currentLocale()’s identifier()) as string –> "ja_JP" set vList to getTTSVoiceNameWithLanguageAndGender(aLoc, "Male") of me –> {"Otoya"} set vList to getTTSVoiceNameWithLanguageAndGender(aLoc, "Female") of me –> {"Kyoko"} set vList to getTTSVoiceNameWithLanguageAndGender("en_US", "Male") of me –> {"Alex", "Bruce", "Fred", "Junior", "Ralph", "Tom"} on getTTSVoiceNameWithLanguageAndGender(voiceLang, aGen) if aGen = "Male" then set aGender to "VoiceGenderMale" else if aGen = "Female" then set aGender to "VoiceGenderFemale" end if set outArray to current application’s NSMutableArray’s new() set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@ && VoiceGender== %@", voiceLang, aGender) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguageAndGender |
More from my site
(Visited 58 times, 1 visits today)