単語を音声に変換しようとしています..
今まで私はこれを試しました:
<?php
$text = "Hello this is a test for voice api of google";
// Name of the MP3 file generated using the MD5 hash
$file = md5($text);
// Save the MP3 file in this folder with the .mp3 extension
$file = "audio/" . $file .".mp3";
if($file) {
echo "created";
} else {
echo "not created";
}
// If the MP3 file exists, do not create a new request
if (!file_exists($file)) {
$mp3 = file_get_contents(
'http://translate.google.com/translate_tts?q=' . $text);
echo "hello";
file_put_contents($file, $mp3);
} else {
echo "hii";
}
?>
私のhtmlファイルで:
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo $file; ?>" type="audio/mp3" />
</audio>
helloとオーディオプレーヤーが出力に作成されています。しかし、ファイルは再生されず、フォルダーにも作成されませんか?