10

I love the text to Speech feature of Mac OS X. Since I'm not a native English speaker I'm very happy about all the additional languages added since Lion came out. However, I do use English as well as my native language (German). Changing voices is a bit of a pain. It just requires too many steps to be comfortable.

Is there any way to make this easy? I was looking for shortcuts, maybe a drop down menu somwhere up in the right corner, anything would be fine.

Since my search was not successful, I hope to find some advice here on SuperUser. Thanks a lot!

cu Roman

  • I'm on Mac, and created Talkie: a text-to-speech browser extension with automatic language detection. It's all open source, but some features are in the commercial distribution Talkie Premium. Easiest to use in the browser (with shortcut keys), but you can use it from any application via the clipboard (premium). Might help you out! https://joelpurra.com/projects/talkie/ – Joel Purra Nov 25 '17 at 12:29

4 Answers4

9

I have used FastScripts to assign a shortcut to this script:

try
    set old to the clipboard as record
end try
try
    tell application "System Events" to keystroke "c" using command down
    delay 0.05
    say (the clipboard) using "Kyoko"
end try
try
    set the clipboard to old
end try

You could also create a service in Automator:

There is a bug in 10.7 and 10.8 where the shortcuts for Automator services don't always work until you hover over the services menu from the menu bar. WorkflowServiceRunner can also use over 100% CPU while speaking text.

Another option would be to use UI scripting to change between two voices:

tell application "System Preferences"
    reveal anchor "TTS" 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
        delay 0.1
        if value is "Alex" then
            click menu item "Victoria" of menu 1
        else
            click menu item "Alex" of menu 1
        end if
    end tell
end tell
quit application "System Preferences"

Changing the SelectedVoiceID key in com.apple.speech.voice.prefs.plist also works, but I don't know how to apply the changes immediately.

Lri
  • 40,894
  • 7
  • 119
  • 157
  • Wow, thanks a lot for this very detailed answer and for showing me so many options. The Automator service works great for me, furthermore now I know about those services. I might want to add some other ones too :) –  Sep 17 '12 at 12:14
  • 1
    Great stuff. As of OSX 10.10: To apply changes to `~/Library/Preferences/com.apple.speech.voice.prefs.plist` immediately, run `pkill com.apple.speech.speechsynthesisd`, which causes the system to automatically restart the process, at which point the changes are picked up. – mklement0 Jun 30 '15 at 02:42
  • 1
    On my OS X 10.10.4, your UI scripting only works if I insert the line "activate" between line 1 and 2. Otherwise I get the error: „tab group 1 of window 1 of process \"System Preferences\"“ cannot be read... Any suggestions why this applies to me but not to others? – Jens Wirth Jul 09 '15 at 08:24
3

Thank you very much Lauryi.

I have extended your UI scripting approach to work properly with german and english voices. The problem is, when your system language is not english, all non system languages are hidden (if not currently selected). You have to select: show more voices.. first to get to the desired language. My code lack a bit of elegance, but works. Here it is (updated):

tell application "System Preferences"
    reveal anchor "TTS" of pane "com.apple.preference.speech"
end tell
set tom to 0
tell application "System Events" to tell process "System Preferences"
    tell pop up button 1 of tab group 1 of window 1
        click
        delay 0.2 -- without this the value was sometimes "Loading Voices…"

        if value is "Tom" then
            click menu item "Anna" of menu 1
        else
            click menu item "Mehr Stimmen anzeigen" of menu 1 -- show up all available voice
            set tom to 1
        end if
    end tell
end tell
if tom is 1 then
    delay 0.5
    tell application "System Events" to tell process "System Preferences"
        tell pop up button 1 of tab group 1 of window 1
            click
            delay 0.2 -- without this the value was sometimes "Loading Voices…"
            click menu item "Tom" of menu 1
        end tell
    end tell
end if
quit application "System Preferences"
kantorde
  • 31
  • 2
0

Direct changes to ~/Library/Preferences/com.apple.speech.voice.prefs.plist are not really needed if you get the bash-script Voices which really adds all the command-line functionality you need.

An Apple Script to change the standard voice to Alex using Voices would simply look like this:

on run
    do shell script "voices -d Alex"
end run

I do prefer the terminal, and instead of testing the polyglot menu-bar intrusion, I made this (admittedly simple-stupid) shell script (which uses voices) for my language-switching needs. With it, All I do to change the default language is to pop into the terminal to type speak swedish or speak french. This fits excellently into my workflow. I hope you can find a solution that fits yours.

# Choose a voice in one of some selected languages
# Use "voices" from https://github.com/mklement0/voices#manual-installation

if [[ $1 = "" ]]
then
    echo "ERROR. No language specified. Type a language as in 'speak hebrew'"
fi
if [[ $1 = "swedish" || $1 = "Swedish" ]]
then
    voices -d Klara
fi
if [[ $1 = "english" || $1 = "English" ]]
then
    voices -d Daniel
fi
if [[ $1 = "american" || $1 = "American" ]]
then
    voices -d Alex
fi
if [[ $1 = "french" || $1 = "French" ]]
then
    voices -d Aurelie
fi
if [[ $1 = "spanish" || $1 = "Spanish" ]]
then
    voices -d Jorge
fi

I save it to my scripts as "speak.command", chmod it +x, and add the appropriate alias to my .bash_profile to evoke it by typing speak.

-1

I Wrote a Status Bar Tool for that:

https://github.com/Fredmf/polyglott

Apperantly it still works in Sierra

  • 1
    Could you expand your answer to include an example use case that would solve the OP's issue. Please see http://meta.superuser.com/questions/5329/how-do-i-recommend-software-in-my-answers – Burgi Sep 27 '16 at 15:51