macOS 13でTTS(Text To Speech)キャラクタが追加され、日本語環境では各種読み上げ機能で「O-Ren」(女性)と「Hattori」(男性)というSiriの音声が使えるようになりました。
macOS 13の「システム設定」(System Settings.app)の「アクセシビリティ」>「読み上げコンテンツ」で、「システムの声」(TTS読み上げキャラクタ)を選択、追加できるわけですが……
ただし、AppleScriptのsayコマンド(音声読み上げ、音声ファイルへのレンダリング)で、「Hattori」「O-Ren」が使えるというわけではありません。逆に、OSのサービス経由で音声名称を取得すると、
{"Kyoko", "Kyoko(拡張)", "Otoya", "Otoya(拡張)"}
などと結果が返ってくるものの、”Kyoko(拡張)”, “Otoya(拡張)”をsayコマンドで指定するとエラーになります。
say "こんにちは" using "Kyoko(拡張)" --> AppleScript Execution Error
AppleScript名:TTS Voiceを言語で抽出.scpt |
— 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"}–macOS 12まで –> {"Kyoko", "Kyoko(拡張)", "Otoya", "Otoya(拡張)"}–macOS 13 on getTTSVoiceNameWithLanguage(voiceLang) 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 == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguage |
TTS Voiceの環境に合わせて何かこれらのTTS Voiceのファミリー名称などを返すようにしないとダメなのかも???
AppleScript名:TTS Voiceを言語で抽出 v2.scpt |
— Created 2017-03-28 by Takaaki Naganoya — Modified 2022-11-12 by Takaaki Naganoya — 2022 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"}–macOS 12まで –> {"Kyoko", "Otoya"}–macOS 13 on getTTSVoiceNameWithLanguage(voiceLang) 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 == %@", voiceLang) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceNameRoot") –Voice Rootを取得 –要素をユニーク化 set theSet to current application’s NSOrderedSet’s orderedSetWithArray:aResList return (theSet’s array()) as list end getTTSVoiceNameWithLanguage |
More from my site
(Visited 385 times, 1 visits today)
返信なし says:
こんにちは
私の日本語はひどいです。しかし、あなたのコードは素晴らしく、「enhanced」と「premium」の音声を使用する方法を見つけるのに役立ちました
use framework "Foundation"
prononcer("モントリオール、ラヴァル、ガティノー", "com.apple.voice.enhanced.ja-JP.Kyoko")
prononcer("Montréal, Laval, Gatineau", "com.apple.voice.premium.fr-CA.Amelie")
on prononcer(texte, nom_voix)
set voix to current application's NSSpeechSynthesizer's new
set voix's voice to nom_voix
set voix's volume to 0.5
if voix's startSpeakingString:texte then
repeat while voix's isSpeaking as boolean
delay 1
end repeat
end if
end prononcer
Takaaki Naganoya says:
I wish I could detect if each TTS voice character is installed…
返信なし says:
完璧でなくても、考えられる解決策が1つあります:
set voix_installes to {}
set texte to do shell script "say -v ? | awk -F \" \" '{print $1}'"
set noms_voix to paragraphs of texte
repeat with nom_voix in noms_voix
if nom_voix contains "(Enhanced)" or nom_voix contains "(Premium)" then
set voix_installes to voix_installes & nom_voix
end if
end repeat
voix_installes
私のコンピュータでは、インストールしたフランス語と日本語の音声が正しく一覧表示されます:
{"Amélie (Enhanced)", "Amélie (Premium)", "Aude (Enhanced)", "Audrey (Enhanced)", "Audrey (Premium)", "Aurélie (Enhanced)", "Chantal (Enhanced)", "Kyoko (Enhanced)", "Nicolas (Enhanced)", "Otoya (Enhanced)", "Thomas (Enhanced)"}