MacOS – How to use Defaults to set an element of an array of an array in a preference file

defaultsmacos

I am trying to increase the speed of the Text-To-Speech on my Mac. The GUI Preference pane maxes out at 360 words per minute. I do accessibility development and this is actually a little slow for me.

I have found the preference file for voice settings:
com.apple.speech.voice.prefs.plist

and I know the key:
VoiceRateDataArray

However, when I read the preference I get an array of arrays.

So how do I write the command line command to over-write the specific element of the array to speed up the voice in OS X.

I cannot seem to find an example to deal with arrays and the defaults command.

Best Answer

WARNING: Although this will do what you're asking, it has shown to make the system speech synthesizer incredibly unstable and crash constantly, to the point of making it unusable. I'm posting this here for future reference in regard to setting nested arrays, but I do not recommend anyone actually tries what's shown here.

I've tried changing this setting manually, but it would seem that the speech synthesizer will not speak faster than 360. Here's how you can see this for yourself:

  1. First, we have to get the "VoiceRateDataArray" key, in order to set the things that shouldn't change, back to their original values, when we make our modifications

    defaults read com.apple.speech.voice.prefs VoiceRateDataArray
    

    The output should look something like this: defaults output

  2. Then, we can make our edits. First, we must construct the defaults command, containing the entry we don't wish to change, and the modified version of the entry we do. For this example, I will change the second entry. The basic syntax is -array '(item1, item2, item3)' '(item1, item2, item3)'. This creates an array, with two nested arrays inside it, based on my example:

    defaults write com.apple.speech.voice.prefs VoiceRateDataArray -array '(
        1835364215,
        200,
        205
    )' '(
        1886745202,
        184844493,
        400
    )'
    

    As you can see, the last element of the second second array has changed from 271 to 400.

  3. Now you have to restart the speech synthesizer:

    killall com.apple.speech.speechsynthesisd