我正在尝试将 单词 转换为 语音..
直到现在我已经尝试过这个:
<?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 和输出中的音频播放器。但是没有播放文件,也没有在文件夹中创建文件?
原文由 Sankalp Mishra 发布,翻译遵循 CC BY-SA 4.0 许可协议
http://translate.google.com/translate_tts?ie=UTF-8&q=Hello&tl=en&total=1&idx=0&textlen=5&prev=input
对于单个单词 Hello 。你会看到你必须在 textlen 中指定语言和文本的长度,即使它对我在不更改此 var 的情况下尝试的所有句子都有效。
所以完整的代码看起来像: