Skip to content

Instantly share code, notes, and snippets.

@alicangnll
Created May 5, 2020 00:50
Show Gist options
  • Save alicangnll/d3cebc638f2fe7e50448ea5731b434f9 to your computer and use it in GitHub Desktop.
Save alicangnll/d3cebc638f2fe7e50448ea5731b434f9 to your computer and use it in GitHub Desktop.
Google Translate TTS Freemium Function for PHP
<?php
function tts_save($icerik) {
$sesget = strip_tags($icerik);
$words = substr($sesget, 0, 100);
$words2 = urlencode($words);
$file = base64_encode("".$_SERVER["REMOTE_ADDR"]."".rand());
$file = "audio/" . $file . ".mp3";
if (!file_exists($file)) {
$mp3 = file_get_contents('http://translate.google.com/translate_tts?ie=UTF-8&tl=tr-TR&client=tw-ob&q='.$words2.'');
file_put_contents($file, $mp3);
}
echo '<audio controls="controls" autoplay="autoplay"><source src="'.$file.'" type="audio/mp3" /></audio>';
}
$getirses = strip_tags($_GET["s"]);
tts_save($getirses);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment