Question

Problem

I'd like to generate an AppleScript that perform the equivalent of "Start Speaking," which exists in the context menu of my Mavericks 10.9.2 system. Currently if I select an English selection, the OS will speak English.

Start Speaking

I want to create an AppleScript that produces audio text-to-speech service but using Mandarin Chinese. I initially suspected that my language locale might have something to do with OSX responding in a particular language, but I am no longer certain (since changing locale on my system had no effect). I've looked into the issue and have found that the following preferences need to be set to enable the text to speech functionality. Once enabled I can select text in Safari and some other apps to use the Start Speaking Service. I am interested in the following approaches:

  1. Use of defaults (can I use defaults to get OSX to recognize the selected Chinese characters?)
  2. Use of some other internal settings that can help me accomplish text-to-speech (Chinese)
  3. Use of an external link that will add the selected text to a query string which can then be opened via Safari to a translation site (I'm leaning more towards this option with translate.google.com)

Number (3) three seems promising and I'd appreciate if anyone could provide a practical use-case for any of the approaches above.

NB:

I've tried a few items already including setting up an Automator Service with speak text and an AppleScript to open a web location with the uri encoded data.

on run {input, parameters}

    set targetURI to urlEncode(input)

    open location "http://translate.google.com/#zh-CN/en/" & targetURI --input
end run

on urlEncode(str)

    local str

    try
        return (do shell script "/bin/echo " & quoted form of str & ¬
            " | perl -MURI::Escape -lne 'print uri_escape($_)'")
    on error eMsg number eNum
        error "Can't urlEncode: " & eMsg number eNum
    end try

end urlEncode

Update

After incorporating the following instructions I was able to use the built in Speech > Start Speaking context menu in Safari/Notes to accomplish the needed functionality. Full credit and thanks for the info that led me to an appropriate solution.

  1. Navigate to System Preferences > Dictation & Speech
  2. Select the Text to Speech tab
  3. Select the System voice popup button
  4. Select Customize...
  5. Search "chin" (no quotes)
  6. Select the available Chinese voices (Sin-ji speaks Cantonese, Ting-Ting speaks Beijing Mandarin, Mei-jia speaks Taiwanese Mandarin)
  7. Change the System Voice to the Appropriate Chinese dialect you want
  8. In Safari and elsewhere, use the default context menu on highlighted Chinese text and system will speak in the current Chinese dialect selected
Was it helpful?

Solution

You just need to open automator and create a new service. Set the automator service to "service receives text from any application". Then add a "speak text" action. In the list of voices choose whatever language you want to hear. Hopefully you have a Chinese language speaking voice. Save it.

Now when you highlight some text, right-click on it, go to the services menu, and choose your automator service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top