Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
Created January 31, 2018 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgreenlee/a7dd8494a83d20dcdfce76a33bad1752 to your computer and use it in GitHub Desktop.
Save bgreenlee/a7dd8494a83d20dcdfce76a33bad1752 to your computer and use it in GitHub Desktop.
<?php
if (strpos(`uname`, 'Darwin') === false) {
fwrite(STDERR, "This only works on macOS, sorry.\n");
exit(1);
}
$voices = array_map(
function($voice) {
return (explode(' ', $voice))[0];
},
explode("\n", trim(`say -v ?`))
);
$words = explode("\n", trim(file_get_contents('/usr/share/dict/words')));
$num_voices = intval($argv[1]) ?: 10;
$num_words = intval($argv[2]) ?: 10;
for ($i=0; $i < $num_voices ; $i++) {
$voice = $voices[array_rand($voices)];
$word_list = join(" ", array_map(function() use ($words) { return $words[array_rand($words)]; }, range(1, $num_words)));
$wpm = rand(80, 120);
exec("say -v {$voice} -r {$wpm} {$word_list} > /dev/null 2>/dev/null &");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment