我实际上需要使用 PHP 脚本或 PHP 命令生成一个 .PHP 文件。文件生成将包含以下代码:
<?php
class TextToSpeech {
public $mp3data;
function __construct($text="") {
$text = trim($text);
if(!empty($text)) {
$text = urlencode($text);
$lang_en="http://translate.google.com/translate_tts?tl=en&q={$text}";
$lang_ro="http://translate.google.com/translate_tts?tl=ro&q={$text}";
$lang_fr="http://translate.google.com/translate_tts?tl=fr&q={$text}";
$language=$lang_en;
$this->mp3data = file_get_contents($language);
}
}
function setText($text) {
$text = trim($text);
if(!empty($text)) {
$text = urlencode($text);
$en="http://translate.google.com/translate_tts?tl=en&q={$text}";
$ro="http://translate.google.com/translate_tts?tl=ro&q={$text}";
$fr="http://translate.google.com/translate_tts?tl=fr&q={$text}";
$lang=$en;
$this->mp3data = file_get_contents($lang);
return $this->mp3data;
} else { return false; }
}
function saveToFile($filename) {
$filename = trim($filename);
if(!empty($filename)) {
return file_put_contents($filename,$this->mp3data);
} else { return false; }
}
}
?>
我想这样做是因为我想对语言有多种选择:
$language=$lang_en;
和
$lang=$en;