Skip to content

Instantly share code, notes, and snippets.

@yohanes
Created Sep 1, 2018
Embed
What would you like to do?
<?php
header("Content-type: application/json");
$lang = "en";
$dir = "/var/www/html/talkdata/";
$text = $_GET['t'];
$m = urlencode($text);
$filename = $lang . "-". $m . ".mp3";
$file = $dir.$filename;
if (!file_exists($file)) {
$mp3 = file_get_contents(
'http://translate.google.com/translate_tts?ie=UTF-8&q='. $m .'&tl='. $lang .'&total=1&idx=0&textlen=5&prev=input&client=tw-ob');
file_put_contents($file, $mp3);
}
echo '{"id":"'.$filename.'"}';
?>
@shoaiyb
Copy link

shoaiyb commented Dec 16, 2021

To suppress

<?php
        header("Content-type: application/json");
        $lang = "en";
        $dir = "/var/www/html/talkdata/";
        $text = $_GET['t'];
        $m = urlencode($text);
        $filename = $lang . "-". $m . ".mp3";
        $file = $dir.$filename;
        if (!file_exists($file)) {
                @gethostbyname('http://translate.google.com');
                $mp3 = (
                'http://translate.google.com/translate_tts?ie=UTF-8&q='. $m .'&tl='. $lang .'&total=1&idx=0&textlen=5&prev=input&client=tw-ob');
                @file_put_contents($file, $mp3);
        }
        echo '{"id":"'.$filename.'"}';
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment