Last active
October 25, 2016 13:17
-
-
Save chernjie/5389395 to your computer and use it in GitHub Desktop.
Mac say in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Declaring variables | |
*/ | |
$output = array(); | |
$return_var = null; | |
/** | |
* Get environment variables | |
*/ | |
$say = array_key_exists('say', $_POST) ? $_POST['say'] : ''; | |
$voice = array_key_exists('voice', $_POST) ? $_POST['voice'] : 'Bruce'; | |
/** | |
* If say exist, execute say | |
*/ | |
empty($say) || exec(escapeshellcmd('echo ' . $say) . ' | say --voice=' . $voice, $output, $return_var); | |
/** | |
* Set types of voices | |
*/ | |
$voices = array( | |
'Female Voices' => array( | |
'Agnes - relatively natural female voice' | |
, 'Kathy - sounds like a computer, kind of like the computer voice' | |
, 'Princess - kind of sounds like an old lady' | |
, 'Vicki - most natural, kind of whispery' | |
, 'Victoria - computery sounding' | |
) | |
, 'Male Voices' => array( | |
'Bruce - most natural male voice' | |
, 'Fred - sounds like a computer' | |
, 'Junior - sounds like a girl' | |
, 'Ralph - deep voice' | |
) | |
, 'Novelty Voices' => array( | |
'Albert - funny weak whispery high pitched voice' | |
, 'Bad News - very slow lo-pitched voice (put "Bad News" in quotes)' | |
, 'Bahh - choppy whispery weak voice' | |
, 'Bells - Melodic bells within voice, relatively slow paced' | |
, 'Boing - Mid-pitched typical computer voice with "boing" sound in each syllable' | |
, 'Bubbles - Whispery voice with bubble sounds in each syllable' | |
, 'Cellos - Melodic voice with cello voice, each syllable is a successive note in a simple tune' | |
, 'Deranged - Old man-ish voice, think Grandpa Simpson' | |
, 'Good News - Says words to the tune of "Pomp and Circumstance" or other tunes' | |
, 'Hysterical - Laughing/chuckling man voice (funny but hard to understand)' | |
, 'Pipe Organ - Low "pipe organ" melodic voice' | |
, 'Trinoids - Monotonous mid-pitched computer voice' | |
, 'Whisper - Whispery, kind of desperate sounding, sounds like it is having trouble breathing' | |
, 'Zarvox - Monotonous mid-pitched computer voice' | |
) | |
); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Mac say</title> | |
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet"> | |
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script> | |
<script type="text/javascript"> | |
</script> | |
<style type="text/css"> | |
body { | |
margin: 2em auto; | |
max-width: 48em; | |
} | |
iframe { | |
display: none; | |
} | |
input[name="say"] { | |
font-size: 3em; | |
height: 1.5em; | |
line-height: 1.5em; | |
} | |
</style> | |
</head> | |
<body> | |
<iframe name="_iframe"></iframe> | |
<form action="" method="post" target="_iframe"> | |
<fieldset> | |
<legend>Mac Say</legend> | |
<div class="control-group"> | |
<input type="text" name="say" value="<?php echo $say?>" placeholder="Type something here" class="span8" /> | |
</div> | |
<div class="control-group"> | |
<select name="voice" class="span8"> | |
<?php foreach ($voices as $group => $types): ?> | |
<optgroup label="<?php echo $group ?>"> | |
<?php foreach ($types as $text): ?> | |
<?php $type = htmlentities(strstr($text, ' - ', 1)); ?> | |
<option value="<?php echo $type ?>" <?php echo $type == $voice ? 'selected="selected"' : ''?>> | |
<?php echo $text ?> | |
</option> | |
<?php endforeach; ?> | |
</optgroup> | |
<?php endforeach; ?> | |
</select> | |
</div> | |
<div class="control-group"> | |
<input type="submit" name="submit" value="Say" class="btn" /> | |
</div> | |
</fieldset> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi chernjie, did you notice that this script, or just running
exec('say "hello"')
stopped working in macOS Sierra? I had a little site for text2audio conversion but it's dead since the upgrade. :(