AppleScript名:OSにインストールされている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 getTTSVoiceNameWithLanguage(aLoc) of me –> {"Kyoko", "Otoya"} set vIDs to getTTSVoiceIDWithLanguage(aLoc) of me –> {"com.apple.speech.synthesis.voice.kyoko.premium", "com.apple.speech.synthesis.voice.otoya.premium"} set anID to getTTSVoiceIDWithName("Kyoko") of me –> {"com.apple.speech.synthesis.voice.kyoko.premium"} set anAge to getTTSVoiceAgeWithName("Otoya") of me –> 35 on getTTSVoiceNameWithLanguage(voiceLang) set outArray to current application’s NSMutableArray’s arrayWithObject:{} –Make Installed Voice List 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 == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguage on getTTSVoiceIDWithLanguage(voiceLang) set outArray to current application’s NSMutableArray’s arrayWithObject:{} 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 == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceIdentifier") as list return aResList end getTTSVoiceIDWithLanguage on getTTSVoiceIDWithName(voiceName) set outArray to current application’s NSMutableArray’s arrayWithObject:{} 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_("VoiceName == %@", voiceName) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceIdentifier") as list return aResList end getTTSVoiceIDWithName on getTTSVoiceAgeWithName(voiceName) set outArray to current application’s NSMutableArray’s arrayWithObject:{} 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_("VoiceName == %@", voiceName) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceAge") as list set anItem to first item of aResList if anItem = missing value then return 0 return anItem as integer end getTTSVoiceAgeWithName |
More from my site
(Visited 102 times, 1 visits today)