<?php
// local_say_help.php
// RJM Programming
// November, 2026
// Post execname execcont to URL /tmp/* place from local web server

$sayis="<select title=\"Text to audio via macOS say\" name=\"execname\" id=\"execname\" value=\"en_US Alex\"><option value=\" \">&#x1F4AC; Optionally select voice name to suit ...</option><option value=\"en_US Alex\">Alex en_US Most people recognize me by my voice.</option><option value=\"en_GB Daniel\">Daniel en_GB Hello, my name is Daniel. I am a British-English voice.</option><option value=\"en_scotland Fiona\">Fiona en_scotland Hello, my name is Fiona. I am a Scottish-English voice.</option><option value=\"en_US Fred\">Fred en_US I sure like being inside this fancy computer</option><option value=\"en_AU Karen\">Karen en_AU Hello, my name is Karen. I am an Australian-English voice.</option><option value=\"en_IE Moira\">Moira en_IE Hello, my name is Moira. I am an Irish-English voice.</option><option value=\"en_US Samantha\">Samantha en_US Hello, my name is Samantha. I am an American-English voice.</option><option value=\"en_ZA Tessa\">Tessa en_ZA Hello, my name is Tessa. I am a South African-English voice.</option><option value=\"en_IN Veena\">Veena en_IN Hello, my name is Veena. I am an Indian-English voice.</option><option value=\"en_US Victoria\">Victoria en_US Isn't it nice to have a computer that will talk to you?</option><option value=\"ar_SA Maged\">Maged ar_SA مرحبًا اسمي Maged. أنا عربي من السعودية.</option><option value=\"cs_CZ Zuzana\">Zuzana cs_CZ Dobrý den, jmenuji se Zuzana. Jsem český hlas.</option><option value=\"da_DK Sara\">Sara da_DK Hej, jeg hedder Sara. Jeg er en dansk stemme.</option><option value=\"de_DE Anna\">Anna de_DE Hallo, ich heiße Anna und ich bin eine deutsche Stimme.</option><option value=\"el_GR Melina\">Melina el_GR Γεια σας, ονομάζομαι Melina. Είμαι μια ελληνική φωνή.</option><option value=\"es_AR Diego\">Diego es_AR Hola, me llamo Diego y soy una voz española.</option><option value=\"es_ES Jorge\">Jorge es_ES Hola, me llamo Jorge y soy una voz española.</option><option value=\"es_MX Juan\">Juan es_MX Hola, me llamo Juan y soy una voz mexicana.</option><option value=\"es_ES Monica\">Monica es_ES Hola, me llamo Monica y soy una voz española.</option><option value=\"es_MX Paulina\">Paulina es_MX Hola, me llamo Paulina y soy una voz mexicana.</option><option value=\"fi_FI Satu\">Satu fi_FI Hei, minun nimeni on Satu. Olen suomalainen ääni.</option><option value=\"fr_CA Amelie\">Amelie fr_CA Bonjour, je m’appelle Amelie. Je suis une voix canadienne.</option><option value=\"fr_FR Thomas\">Thomas fr_FR Bonjour, je m’appelle Thomas. Je suis une voix française.</option><option value=\"he_IL Carmit\">Carmit he_IL שלום. קוראים לי כרמית, ואני קול בשפה העברית.</option><option value=\"hi_IN Lekha\">Lekha hi_IN नमस्कार, मेरा नाम लेखा है. मैं हिन्दी में बोलने वाली आवाज़ हूँ.</option><option value=\"hu_HU Mariska\">Mariska hu_HU Üdvözlöm! Mariska vagyok. Én vagyok a magyar hang.</option><option value=\"id_ID Damayanti\">Damayanti id_ID Halo, nama saya Damayanti. Saya berbahasa Indonesia.</option><option value=\"it_IT Alice\">Alice it_IT Salve, mi chiamo Alice e sono una voce italiana.</option><option value=\"it_IT Luca\">Luca it_IT Salve, mi chiamo Luca e sono una voce italiana.</option><option value=\"ja_JP Kyoko\">Kyoko ja_JP こんにちは、私の名前はKyokoです。日本語の音声をお届けします。</option><option value=\"ko_KR Yuna\">Yuna ko_KR 안녕하세요. 제 이름은 Yuna입니다. 저는 한국어 음성입니다.</option><option value=\"nl_BE Ellen\">Ellen nl_BE Hallo, mijn naam is Ellen. Ik ben een Belgische stem.</option><option value=\"nl_NL Xander\">Xander nl_NL Hallo, mijn naam is Xander. Ik ben een Nederlandse stem.</option><option value=\"pl_PL Zosia\">Zosia pl_PL Witaj. Mam na imię Zosia, jestem głosem kobiecym dla języka polskiego.</option><option value=\"pt_PT Joana\">Joana pt_PT Olá, chamo-me Joana e dou voz ao português falado em Portugal.</option><option value=\"pt_BR Luciana\">Luciana pt_BR Olá, o meu nome é Luciana e a minha voz corresponde ao português que é falado no Brasil</option><option value=\"ro_RO Ioana\">Ioana ro_RO Bună, mă cheamă Ioana . Sunt o voce românească.</option><option value=\"ru_RU Milena\">Milena ru_RU Здравствуйте, меня зовут Milena. Я – русский голос системы.</option><option value=\"ru_RU Yuri\">Yuri ru_RU Здравствуйте, меня зовут Yuri. Я – русский голос системы.</option><option value=\"sk_SK Laura\">Laura sk_SK Ahoj. Volám sa Laura . Som hlas v slovenskom jazyku.</option><option value=\"sv_SE Alva\">Alva sv_SE Hej, jag heter Alva. Jag är en svensk röst.</option><option value=\"th_TH Kanya\">Kanya th_TH สวัสดีค่ะ ดิฉันชื่อKanya</option><option value=\"tr_TR Yelda\">Yelda tr_TR Merhaba, benim adım Yelda. Ben Türkçe bir sesim.</option><option value=\"zh_TW Mei-Jia\">Mei-Jia zh_TW 您好，我叫美佳。我說國語。</option><option value=\"zh_HK Sin-ji\">Sin-ji zh_HK 您好，我叫 Sin-ji。我講廣東話。</option><option value=\"zh_CN Ting-Ting\">Ting-Ting zh_CN 您好，我叫Ting-Ting。我讲中文普通话。</option><option value=\"  \">No words</option></select>";
$done=false;
$prefix="";
if (file_exists("/usr/local/bin/ffmpeg")) {
  $fprefix="/usr/local/bin/";
} else if (file_exists("/bin/ffmpeg")) {
  $fprefix="/bin/";
} else if (file_exists("/usr/bin/ffmpeg")) {
  $fprefix="/usr/bin/";
}
$fswitch=" -vn -map_metadata -1 -c:a libmp3lame -b:a 192k ";
$omore="";

if (!$argc) {
$audioname=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'diffident_audio_' . rand(674,67788995) . '.aiff';
if (isset($_SERVER['HTTP_ORIGIN'])) {
    $origin = $_SERVER['HTTP_ORIGIN'];
    
    file_put_contents('xx.xx', $origin);
    
    // Allow any port on localhost or 127.0.0.1
    if (preg_match('/^https?:\/\/(w\.w\.w\.rjmprogramming\.com\.au|rjmprogramming\.com\.au\)(:\d+)?$/', $origin)) {
        header("Access-Control-Allow-Origin: " . $origin);
        header("Access-Control-Allow-Credentials: true");
    }
}

header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); //  GET, POST, PUT, DELETE, OPTIONS
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

//file_put_contents('xxx.xxx', '');
$durl="";

if (isset($_POST['execname']) && isset($_POST['execcont'])) {
   if (isset($_POST['audioname'])) {
//file_put_contents('xxxx.xxx', '');
      $audioname=str_replace('+',' ',urldecode($_POST['audioname']));
//file_put_contents('xxxxx.xxx', '');
   }
   if (strtoupper(PHP_OS) == "DARWIN") {
   if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp')) {
       mkdir($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp');
   }
   if (strpos($audioname, 'tmp') !== false && strpos($audioname, $_SERVER['DOCUMENT_ROOT']) === false) {
       $audioname=$_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename($audioname);
   }
   //exec('say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))] . ' "' . str_replace('+',' ',urldecode($_POST['execcont'])) . '"'));
//file_put_contents('xxxxxx.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
   exec('say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
   //exec('say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : '') . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ''));
//file_put_contents('xxxxxx2.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
   if (file_exists(str_replace('.aiff','.mp3',$audioname))) {
//file_put_contents('xxxxxx3.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
     $durl="data:audio/mpeg;base64," . base64_encode(file_get_contents(str_replace('.aiff','.mp3',$audioname)));
//file_put_contents('xxxxxx4.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
     $audioname=str_replace('.aiff','.mp3',$audioname);
//file_put_contents('xxxxxx5.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
   }
//file_put_contents('xxxxxx6.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname . $fswitch . ' ' . str_replace('.aiff','.mp3',$audioname)));
   echo "<html><body>said this @!@" . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename($audioname) . $durl . "</body></html>";
//file_put_contents('xxxxxx7.xxx', '' . 'say ' . (trim(str_replace('+',' ',urldecode($_POST['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_POST['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_POST['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_POST['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $fprefix . 'ffmpeg -i ' . $audioname  . $fswitch. ' ' . str_replace('.aiff','.mp3',$audioname)));
   //exit;
   } else {
     echo "<html>
   <head>
   <style>
   a { padding: 1 1 1 1; border: 1px solid black; }
   </style>
<title>Text to Speech - RJM Programming - December, 2026 ... thanks to macOS say and/or Google Translate</title>
   <scr" . "ipt type=text/javascript>
     var zhr=null, zform=null, zret=false, hasbeencalled=false, execname='/tmp/" . basename($audioname) . "', execcont='" . $durl . "';
     var lng=location.search.split('execname=')[1] ? decodeURIComponent(location.search.split('execname=')[1].split('&')[0]).substring(0,2) : (('' + navigator.language) != '' ? navigator.language.split('-')[0] : 'en');
     " . (strtoupper(PHP_OS) == "DARWIN" ? " var port=':8888'; " : " var port=''; ") . "

  function mampshowStuff(evt) {
  if (zhr.readyState == 4) {
    if (zhr.status == 200) { 
     //alert(zhr.responseText);
     if (zhr.responseText.indexOf('said this @!@') != -1) { if (zhr.responseText.indexOf('said this @!@<') == -1) { if (zhr.responseText.split('said this @!@')[1].indexOf('tmp') == 1) {  execname=zhr.responseText.split('said this @!@')[1].split('</body>')[0]; if (execname.indexOf('data:') != -1) { execcont='data:' + execname.split('data:')[1]; execname=execname.replace(execcont,'');  }  } else if (zhr.responseText.indexOf('said this @!@data:') != -1) { execcont=zhr.responseText.indexOf('said this @!@')[1].split('</body>')[0];  }  } hasbeencalled=true; zhr=zhr; } else { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }
     if (execname != '' && execcont != '') {
       document.getElementById('bupload').style.display='inline-block';
       document.getElementById('aemail').style.display='inline-block';
       document.getElementById('asms').style.display='inline-block';
       document.getElementById('duria').style.display='inline-block';
       document.getElementById('audioname').value=execname;
       document.getElementById('audioname').name='audioname';
       if (1 == 1) {
       document.getElementById('durias').src='';
       document.getElementById('duria').innerHTML=document.getElementById('duria').innerHTML.replace(' src=\"\"',' src=\"' + (execname != '' ? execname : execcont) + '\"');
       } else {
       document.getElementById('durias').src=(execname != '' ? execname : execcont);
       }
     }
    } else {
     //alert('0bad1:' + zhr.responseText);
     hasbeencalled=true;
     zret=true; 
     document.getElementById('mysub').name='mysub';
     document.getElementById('audioname').value=execname; // '/tmp/" . basename($audioname) . "';
     document.getElementById('audioname').name='audioname';
     document.getElementById('myform').action=document.getElementById('myform').action.replace('https://www.rjmprogramming.com.au/','./').replace('http://www.rjmprogramming.com.au/','./').replace('./', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/');
     document.getElementById('mysub').click();  
     document.getElementById('mysub').click();  
    }
  } else if (1 == 4) {
    hasbeencalled=true;
    zret=true; 
    document.getElementById('mysub').click();  
  }
  }

  function upload() {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     if (execcont.indexOf('/aif') != -1) {
     zform.append('execname', execname);
     } else {
     zform.append('execname', execname.replace('.aiff','.mp3'));
     }
     zform.append('execcont', execcont);
     zhr.open('post', '//www.rjmprogramming.com.au/local_tmp_uploader.php', true);
     zhr.send(zform);
  }
   
     function onsb() {
       if (document.getElementById('execcont').value.trim() == '') {  return false; }
     if (!zret) {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     zform.append('execname', document.getElementById('execname').value);
     zform.append('execcont', document.getElementById('execcont').value);
     zform.append('audioname', '" . $audioname . "');
     zhr.open('post', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/local_say_help.php', true);
     hasbeencalled=false;
     setTimeout(function(){ if (!hasbeencalled) { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }  }, 5000);
     zhr.onreadystatechange = mampshowStuff;
     zhr.send(zform);
     } 
       //if (zret) { alert(356); }
       return zret;
     }
   
     var twois=window.open('//translate.google.com/?sl=auto&tl=' + lng + '&text=' + encodeURIComponent(\"" . str_replace('+',' ',urldecode($_POST['execcont'])) . "\") + '%0A&op=translate', '_blank', 'left=100,top=100,width=500,height=700');
   </scr" . "ipt>
   </head>
   </head>
   <body" . $omore . ">
   <h1>Text to Speech</h1>
   <h3>RJM Programming - December, 2026</h3>
   <h4>Thanks to macOS say and/or Google Translate</h4>
   <form onsubmit='return onsb();' action=./local_say_help.php method=POST>
   " . $sayis . "<br><br>
   <textarea name=execcont id=execcont value='' placeholder=Text></textarea><br><br>
   <input type=hidden id=audioname value=''></input>
   <input type=submit id=mysub value='say ...'></input>
   </form>
   <hr>
   <button id=bupload onclick=upload(); style=display:none;text-decoration:none;background-color:pink;color:blue;>Upload &#x1F4E4;</button>&nbsp;&nbsp;<a target=_top id=aemail style=display:none;text-decoration:none;background-color:yellow;color:blue; onclick=upload(); href='mailto:?subject=My%20Audio&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;Email &#128231;&nbsp;</a>&nbsp;&nbsp;<a target=_top id=asms style=display:none;text-decoration:none;background-color:orange;color:blue; onclick=upload(); href='sms:&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;SMS &#128223;&nbsp;</a><br><br>
   <span id=duria style=display:none;><audio id=aduria controls><source id=durias type=audio/mpeg src=\"\"></source></audio></span>   </body>
   </html>";
   }
   exit;
}

}

$more="";
$du="";
$fmvs=-1;
$dup="data:audio/mpeg;base64,";
if (isset($_GET['execname']) && isset($_GET['execcont'])) {
   if (isset($_GET['audioname'])) {
      $audioname=str_replace('+',' ',urldecode($_GET['audioname']));
      if (strtoupper(PHP_OS) == "DARWIN") {
      if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename($audioname))) {
        $fdone=false;
        foreach(glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'diffident_*.aiff') as $fna) {
          //if (!$fdone) {
          
            //$fdone=true;
            if (filemtime($fna) > $fmvs) {
            $audioname=$fna;
            $fmvs=filemtime($fna);
            }
          //}
        }
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename(str_replace('.aiff','.mp3',$audioname)))) {
              $audioname=str_replace('.aiff','.mp3',$audioname);
            } else {
              $dup="data:audio/aiff;base64,";
            }
      }
      }
   }
   if (strtoupper(PHP_OS) == "DARWIN") {
     $more=" && 5 == 6";
     if (isset($_GET['mysub'])) {
       //sleep(16);
       //$audioname=str_replace('.aiff','.mp3',$audioname);
       if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename($audioname))) {
         $du=$dup . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . basename($audioname)));
         $omore=" onload=\"document.getElementById('bupload').style.display='inline-block'; document.getElementById('aemail').style.display='inline-block'; document.getElementById('asms').style.display='inline-block'; document.getElementById('duria').style.display='inline-block'; document.getElementById('audioname').value=execname; document.getElementById('audioname').name='audioname'; document.getElementById('execname').value='" . trim(str_replace('+',' ',urldecode($_GET['execname']))) . "';  document.getElementById('execcont').value=decodeURIComponent('" . $_GET['execcont'] . "'); execcont='" . $du . "'; \"";
       } else {
         //$omore=" onload=\" execname='/tmp/" . basename($audioname) . "';  execcont=decodeURIComponent('" . $_GET['execcont'] . "'); upload(); setTimeout(function(){  location.href='https://www.rjmprogramming.com.au/' + document.URL.split('//')[1].split('/')[1];   }, 15000); \"";
         $omore=" onload=\"document.getElementById('bupload').style.display='inline-block'; document.getElementById('aemail').style.display='inline-block'; document.getElementById('asms').style.display='inline-block'; document.getElementById('duria').style.display='inline-block'; document.getElementById('audioname').value=execname; document.getElementById('audioname').name='audioname'; document.getElementById('execname').value='" . trim(str_replace('+',' ',urldecode($_GET['execname']))) . "';  document.getElementById('execcont').value=decodeURIComponent('" . $_GET['execcont'] . "'); \"";
       }
     }
     if (!file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp')) {
       mkdir($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'tmp');
     }
     exec('say ' . (trim(str_replace('+',' ',urldecode($_GET['execname']))) == '' ? '' : ' -v ' . explode(' ',str_replace('+',' ',urldecode($_GET['execname'])))[-1 + sizeof(explode(' ',str_replace('+',' ',urldecode($_GET['execname']))))]) . ($audioname == '' ? '' : ' -o ' . str_replace('.mp3','.aiff',$audioname)) . ' "' . str_replace('"',"'",str_replace('+',' ',urldecode($_GET['execcont']))) . '"' . ($audioname == '' ? '' : ' && afplay ' . $audioname . ' ; ' . $prefix . 'ffmpeg -i ' . $audioname . ' ' . str_replace('.aiff','.mp3',$audioname)));
   } else if (isset($_GET['mysub'])) {
     $omore=" onload=\"document.getElementById('bupload').style.display='inline-block'; document.getElementById('aemail').style.display='inline-block'; document.getElementById('asms').style.display='inline-block'; document.getElementById('duria').style.display='inline-block'; document.getElementById('audioname').value=execname; document.getElementById('audioname').name='audioname'; document.getElementById('execname').value='" . trim(str_replace('+',' ',urldecode($_GET['execname']))) . "';  document.getElementById('execcont').value=decodeURIComponent('" . $_GET['execcont'] . "'); \"";
   }
   if (1 == 1) {
     echo "<html>
   <head>
   <style>
   a { padding: 1 1 1 1; border: 1px solid black; }
   </style>
<title>Text to Speech - RJM Programming - December, 2026 ... thanks to macOS say and/or Google Translate</title>
   <scr" . "ipt type=text/javascript>
     var zhr=null, zform=null, zret=false, hasbeencalled=false, execname='/tmp/" . basename($audioname) . "', execcont='" . $durl . "';
     var lng=location.search.split('execname=')[1] ? decodeURIComponent(location.search.split('execname=')[1].split('&')[0]).substring(0,2) : (('' + navigator.language) != '' ? navigator.language.split('-')[0] : 'en');
     " . (strtoupper(PHP_OS) == "DARWIN" ? " var port=':8888'; " : " var port=''; ") . "

  function upload() {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     //alert(execname.replace('.aiff','.mp3'));
     //alert(execcont);
     if (execcont.indexOf('/aif') != -1) {
     zform.append('execname', execname);
     } else {
     zform.append('execname', execname.replace('.aiff','.mp3'));
     }
     zform.append('execcont', execcont);
     zhr.open('post', '//www.rjmprogramming.com.au/local_tmp_uploader.php', true);
     zhr.send(zform);
  }

  function mampshowStuff(evt) {
  if (zhr.readyState == 4) {
    if (zhr.status == 200) { 
     alert('2:' + zhr.responseText);
     if (zhr.responseText.indexOf('said this @!@') != -1) { if (zhr.responseText.indexOf('said this @!@<') == -1) { if (zhr.responseText.split('said this @!@')[1].indexOf('tmp') == 1) {  execname=zhr.responseText.split('said this @!@')[1].split('</body>')[0]; if (execname.indexOf('data:') != -1) { execcont='data:' + execname.split('data:')[1]; execname=execname.replace(execcont,'');  }  } else if (zhr.responseText.indexOf('said this @!@data:') != -1) { execcont=zhr.responseText.indexOf('said this @!@')[1].split('</body>')[0];  }  } hasbeencalled=true; zhr=zhr; } else { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }
     if (execname != '' && execcont != '') {
       document.getElementById('bupload').style.display='inline-block';
       document.getElementById('aemail').style.display='inline-block';
       document.getElementById('asms').style.display='inline-block';
       document.getElementById('duria').style.display='inline-block';
       document.getElementById('audioname').value=execname;
       document.getElementById('audioname').name='audioname';
       if (1 == 1) {
       document.getElementById('durias').src='';
       document.getElementById('duria').innerHTML=document.getElementById('duria').innerHTML.replace(' src=\"\"',' src=\"' + (execname != '' ? execname : execcont) + '\"');
       } else {
       document.getElementById('durias').src=(execname != '' ? execname : execcont);
       }
     }
    } else {
     //alert('0bad2:' + zhr.responseText);
     hasbeencalled=true;
     zret=true; 
     document.getElementById('mysub').name='mysub';
     document.getElementById('audioname').value=execname; // '/tmp/" . basename($audioname) . "';
     document.getElementById('audioname').name='audioname';
     document.getElementById('myform').action=document.getElementById('myform').action.replace('https://www.rjmprogramming.com.au/','./').replace('http://www.rjmprogramming.com.au/','./').replace('./', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/');
     document.getElementById('mysub').click();  
     document.getElementById('mysub').click();  
    }
  } else if (1 == 4) {
    hasbeencalled=true;
    zret=true; 
    document.getElementById('mysub').click();  
  }
  }
   
     function onsb() {
       if (document.getElementById('execcont').value.trim() == '') {  return false; }
     if (!zret) {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     zform.append('execname', document.getElementById('execname').value);
     zform.append('execcont', document.getElementById('execcont').value);
     zform.append('audioname', '" . $audioname . "');
     zhr.open('post', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/local_say_help.php', true);
     hasbeencalled=false;
     setTimeout(function(){ if (!hasbeencalled) { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }  }, 18000);
     zhr.onreadystatechange = mampshowStuff;
     zhr.send(zform);
     } 
       //if (zret) { alert(56); }
       return zret;
     }
   
     if (('' + navigator.platform).toLowerCase().indexOf('mac') != 0" . $more . ") {
     var twois=window.open('//translate.google.com/?sl=auto&tl=' + lng + '&text=' + encodeURIComponent(\"" . str_replace('+',' ',urldecode($_GET['execcont'])) . "\") + '%0A&op=translate', '_blank', 'left=100,top=100,width=500,height=700');
     }
   </scr" . "ipt>
   </head>
   <body" . $omore . ">
   <h1>Text to Speech</h1>
   <h3>RJM Programming - December, 2026</h3>
   <h4>Thanks to macOS say and/or Google Translate</h4>
   <form onsubmit='return onsb();' action=./local_say_help.php method=GET>
   " . $sayis . "<br><br>
   <textarea name=execcont id=execcont value='' placeholder=Text></textarea><br><br>
   <input type=hidden id=audioname value=''></input>
   <input type=submit id=mysub value='say ...'></input>
   </form>
   <hr>
   <button id=bupload onclick=upload(); style=display:none;text-decoration:none;background-color:pink;color:blue;>Upload &#x1F4E4;</button>&nbsp;&nbsp;<a target=_top id=aemail style=display:none;text-decoration:none;background-color:yellow;color:blue; onclick=upload(); href='mailto:?subject=My%20Audio&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;Email &#128231;&nbsp;</a>&nbsp;&nbsp;<a target=_top id=asms style=display:none;text-decoration:none;background-color:orange;color:blue; onclick=upload(); href='sms:&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;SMS &#128223;&nbsp;</a><br><br>
   <span id=duria style=display:none;><audio id=aduria controls><source id=durias type=audio/mpeg src=\"\"></source></audio></span>   </body>
   </html>";
     exit;
   }
} else {
   echo "<html>
   <head>
   <style>
   a { padding: 1 1 1 1; border: 1px solid black; }
   </style>
<title>Text to Speech - RJM Programming - December, 2026 ... thanks to macOS say and/or Google Translate</title>
   <scr" . "ipt type=text/javascript>
     var zhr=null, zform=null, zret=false, hasbeencalled=false, execname='/tmp/" . basename($audioname) . "', execcont='" . $durl . "';
     var lng=location.search.split('execname=')[1] ? decodeURIComponent(location.search.split('execname=')[1].split('&')[0]).substring(0,2) : (('' + navigator.language) != '' ? navigator.language.split('-')[0] : 'en');
     " . (strtoupper(PHP_OS) == "DARWIN" ? " var port=':8888'; " : " var port=''; ") . "

  function upload() {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     if (execcont.indexOf('/aif') != -1) {
     zform.append('execname', execname);
     } else {
     zform.append('execname', execname.replace('.aiff','.mp3'));
     }
     zform.append('execcont', execcont);
     zhr.open('post', '//www.rjmprogramming.com.au/local_tmp_uploader.php', true);
     zhr.send(zform);
  }

  function mampshowStuff(evt) {
  if (zhr.readyState == 4) {
    if (zhr.status == 200) { 
     //alert(zhr.responseText);
     alert('3:' + zhr.responseText);
     if (zhr.responseText.indexOf('said this @!@') != -1) { if (zhr.responseText.indexOf('said this @!@<') == -1) { if (zhr.responseText.split('said this @!@')[1].indexOf('tmp') == 1) {  execname=zhr.responseText.split('said this @!@')[1].split('</body>')[0]; if (execname.indexOf('data:') != -1) { execcont='data:' + execname.split('data:')[1]; execname=execname.replace(execcont,'');  }  } else if (zhr.responseText.indexOf('said this @!@data:') != -1) { execcont=zhr.responseText.indexOf('said this @!@')[1].split('</body>')[0];  }  } hasbeencalled=true; zhr=zhr; } else { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }
     if (execname != '' && execcont != '') {
       document.getElementById('bupload').style.display='inline-block';
       document.getElementById('aemail').style.display='inline-block';
       document.getElementById('asms').style.display='inline-block';
       document.getElementById('duria').style.display='inline-block';
       document.getElementById('audioname').value=execname;
       document.getElementById('audioname').name='audioname';
       if (1 == 1) {
       document.getElementById('durias').src='';
       document.getElementById('duria').innerHTML=document.getElementById('duria').innerHTML.replace(' src=\"\"',' src=\"' + (execname != '' ? execname : execcont) + '\"');
       } else {
       document.getElementById('durias').src=(execname != '' ? execname : execcont);
       }
     }
    } else {
     //alert('0bad3:' + zhr.responseText);
     hasbeencalled=true;
     //alert(245);
     zret=true; 
     //alert(document.getElementById('myform').action);
     document.getElementById('mysub').name='mysub';
     document.getElementById('audioname').value=execname; // '/tmp/" . basename($audioname) . "';
     document.getElementById('audioname').name='audioname';
     document.getElementById('myform').action=document.getElementById('myform').action.replace('https://www.rjmprogramming.com.au/','./').replace('http://www.rjmprogramming.com.au/','./').replace('./', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/');
     document.getElementById('mysub').click();  
    }
  } else if (1 == 4) {
    hasbeencalled=true;
     //alert(1245);
    zret=true; 
    document.getElementById('mysub').click();  
  }
  }
   
     function onsb() {
       if (document.getElementById('execcont').value.trim() == '') {  return false; }
     if (!zret) {
     zhr = new XMLHttpRequest();
     zform = new FormData();
     zform.append('execname', document.getElementById('execname').value);
     zform.append('execcont', document.getElementById('execcont').value);
     zform.append('audioname', '" . $audioname . "');
     zhr.open('post', 'http://localhost' + (('' + navigator.platform).toLowerCase().indexOf('mac') == 0 ? ':8888' : '') + '/local_say_help.php', true);
     hasbeencalled=false;
     setTimeout(function(){ if (!hasbeencalled) { hasbeencalled=true; zret=true; document.getElementById('mysub').click();   }  }, 18000);
     zhr.onreadystatechange = mampshowStuff;
     zhr.send(zform);
     } 
       //f (zret) { alert(256); }
       return zret;
     }
   
   </scr" . "ipt>
   </head>
   <body" . $omore . ">
   <h1>Text to Speech</h1>
   <h3>RJM Programming - December, 2026</h3>
   <h4>Thanks to macOS say and/or Google Translate</h4>
   <form id=myform onsubmit='return onsb();' action=./local_say_help.php method=GET>
   " . $sayis . "<br><br>
   <textarea name=execcont id=execcont value='' placeholder=Text></textarea><br><br>
   <input type=hidden id=audioname value=''></input>
   <input type=submit id=mysub value='say ...'></input>
   </form>
   <hr>
   <button id=bupload onclick=upload(); style=display:none;text-decoration:none;background-color:pink;color:blue;>Upload &#x1F4E4;</button>&nbsp;&nbsp;<a target=_top id=aemail style=display:none;text-decoration:none;background-color:yellow;color:blue; onclick=upload(); href='mailto:?subject=My%20Audio&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;Email &#128231;&nbsp;</a>&nbsp;&nbsp;<a target=_top id=asms style=display:none;text-decoration:none;background-color:orange;color:blue; onclick=upload(); href='sms:&body=" . urlencode('https://www.rjmprogramming.com.au/tmp/' . basename(str_replace('.aiff','.mp3',$audioname))) . "'>&nbsp;SMS &#128223;&nbsp;</a><br><br>
   <span id=duria style=display:none;><audio id=aduria controls><source id=durias type=audio/mpeg src=\"\"></source></audio></span>
   </body>
   </html>";
}
exit;
?>
