如何动态改变听写语言?


4

由于英语不是我的第一语言,在使用自动纠正和听写等功能时,我通常需要支持至少两种语言。

是否可以通过快捷方式切换用于听写的语言?

截至目前,我总是需要手动浏览系统偏好设置中的菜单,如果不方便的话。我试图看看Automator中是否有任何预先定义的操作,但没有找到。

Answers:


4

您可以编辑存储设置的属性列表并重新打开DictationIM进程:

#!/bin/bash

k="com.apple.speech.recognition.AppleSpeechRecognition.prefs DictationIMLocaleIdentifier"
if [[ "$(defaults read $k)" == en-US ]]; then
  defaults write $k fr-FR
  defaults write com.apple.assistant "Session Language" fr-FR
else
  defaults write $k en-US 
  defaults write com.apple.assistant "Session Language" en-US
fi
killall -HUP DictationIM

或者使用UI脚本:

tell application "System Preferences"
    reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events" to tell process "System Preferences"
    tell pop up button 1 of tab group 1 of window 1
        click
        if value is "English (United States)" then
            click menu item "French" of menu 1
        else
            click menu item "English (United States)" of menu 1
        end if
    end tell
end tell
quit application "System Preferences"

这两个脚本都是从我的答案复制而来的 如何使用applescript切换新听写工具的语言设置(10.8) - Stack Overflow


语法似乎有错误。 “,”或“]”预期。
gentmatt

1
-eq 不适用于字符串IIRC。
Daniel Beck

@DanielBeck你是对的。我编辑了脚本并删除了 activate 来自AppleScript。
Lri

2

不确定这是否有帮助,但有人开发了一个“听写切换器”一个小实用程序,位于Mac的菜单栏中,使得使用听写更容易。在这里能找到它: http://fouquet.me/apps/dictationswitcher/

明白你有幸编写自己的脚本,但为了以防万一,我认为这可能会有所帮助... :-)


1

我发现了一个 线 其中包含以下Applescript:

tell application "System Events" to set p to (path to frontmost application) as string
tell application "System Preferences"
    activate
    reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events"
    tell process "System Preferences"
        tell pop up button 1 of tab group 1 of window "Dictation & Speech"
            click
            if (get value of attribute "AXValue") contains "English (United States)" then
                click menu item "German" of menu 1
                say "Dictation set to German"
            else if (get value of attribute "AXValue") contains "German" then
                click menu item "English (United States)" of menu 1
                say "Dictation set to English"
            end if
        end tell
    end tell
end tell
quit application "System Preferences"
activate application p

我测试了它,它的工作原理。您所要做的就是将“德语”更改为您选择的语言。

另外,我可以建议一个名为的应用程序 FastScripts ,允许您从顶部菜单栏或键盘快捷键运行applescript。

希望这能解决你的问题!


说实话,这个解决方案不是很漂亮(我不喜欢看到打开的偏好和所有......),但它确实有效,所以我会用这个去了解。谢谢你分享这个!我已经在使用FastScripts,所以这很好。
gentmatt

2
你可以省略 activate,它也会工作,而不是显示窗口。
Daniel Beck


1

在OSX El Capitan上,我很难通过user495470获取脚本,同样使用pasawaya的代码。我最终修改了pasawaya的代码,包括:

repeat until exists tab group 1 of window "Dictation & Speech"
end repeat

这是完全略微修改的脚本,对我来说非常适合:

tell application "System Events" to set currentWindow to (path to frontmost application) as string
tell application "System Preferences"
    reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events"
    tell process "System Preferences"
        repeat until exists tab group 1 of window "Dictation & Speech"
        end repeat
        tell pop up button 1 of tab group 1 of window "Dictation & Speech"
            click
            if (get value of attribute "AXValue") contains "English" then
                click menu item "Danish (Denmark)" of menu 1
                say "Dictation Danish"
            else if (get value of attribute "AXValue") contains "Danish" then
                click menu item "English (United Kingdom)" of menu 1
                say "Dictation English"
            end if
        end tell
    end tell
end tell
quit application "System Preferences"
activate application currentWindow

0

好吧,当我想要更改语言时,我只需点击小听写小部件中当前语言的名称并获得一个菜单:
Language menu for MacOS Dictation

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.