Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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