如何使用 AppleScript 下载用于 say 功能的新语音? [英] How to download a new voice for say's function with AppleScript?
问题描述
我正在寻找一种在系统首选项上安装不同声音(准确地说是 2 个)的方法.语音是英语语音的Alex"和法语语音的Thomas".
I'm searching a method to install different voices (2 to be exact) on the system preferences. The voices are "Alex" for an english voice and "Thomas" for a french voice.
我直接通过控制台尝试但没有成功,这就是为什么我转向 AppleScript 语言,但我从未使用过这种语言.
I've tried directly by console but didn't succeed, that's why I've turned to the AppleScript language, but I never used this language.
我现在的代码是
set osver to system version of (system info)
if osver is equal to "10.6.8" then
display dialog ("Downloading voices is only available in OS X Lion and higher")
else
tell application "System Preferences"
activate
reveal (pane id "com.apple.preference.speech")
end tell
try
tell application "System Events"
click radio button 2 of tab group 1 of window 1 of process "System Preferences"
repeat until (exists pop up button of tab group 1 of window 1 of process "System Preferences")
delay 2
end repeat
delay 2
click pop up button 1 of tab group 1 of window 1 of process "System Preferences"
delay 2
click menu item -1 of menu 1 of pop up button of tab group 1 of window 1 of process "System Preferences"
delay 2
end tell
on error
display dialog ("An error happend")
end try
end if
这个程序正在打开语音窗口,但每次我输入什么索引都会出现显示对话框.
This program is opening the voice window but the display dialog appears every time whatever the index I put.
如果您有其他下载声音的想法,或者您能帮助我了解什么不起作用,我将不胜感激.
If you have another idea to download the voices, or if you can help me to understand what is not working, I will be grateful.
推荐答案
这在 10.9 中对我有用:
This worked for me in 10.9:
tell application "System Preferences"
reveal anchor "TTS" of pane id "com.apple.preference.speech"
activate
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
tell pop up button 1 of tab group 1
click
click menu item "Customize..." of menu 1
end tell
delay 1
repeat with r in UI element 1 of rows of table 1 of scroll area 1 of sheet 1
if exists static text 1 of r then
if {"Alex", "Thomas"} contains value of static text 1 of r then
if value of checkbox 1 of r is 0 then click checkbox 1 of r
end if
end if
end repeat
click button "OK" of sheet 1
end tell
虽然运行脚本需要几秒钟.
It took multiple seconds to run the script though.
这篇关于如何使用 AppleScript 下载用于 say 功能的新语音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!