Skip to content

Instantly share code, notes, and snippets.

@giangmd
Created December 30, 2019 09:24
Show Gist options
  • Save giangmd/1f465dbacbcca1e65b08e40ae5fcf772 to your computer and use it in GitHub Desktop.
Save giangmd/1f465dbacbcca1e65b08e40ae5fcf772 to your computer and use it in GitHub Desktop.
<?php
$text = "Xin chào tất cả mọi người. Tôi tên là Giang. Hôm nay, tôi đến đây để làm việc. Chúc mọi người làm việc vui vẻ!";
$lang = "vi";
$file = md5($lang."?".urlencode($text));
$file = "audio/" . $file . ".mp3";
if (!is_dir("audio/"))
mkdir("audio/");
else
if (substr(sprintf('%o', fileperms('audio/')), -4) != "0777")
chmod("audio/", 0777);
if (!file_exists($file))
{
$mp3 = file_get_contents('https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q='. urlencode($text) .'&tl='. $lang .'&total=1&idx=0&textlen=5&prev=input');
file_put_contents($file, $mp3);
}
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment