【发布时间】:2019-04-13 00:19:52
【问题描述】:
我让 text2speech 工作,但我想使用 GET 方法,我该怎么做?
我的意思是我想通过这样的 URL 转换 text2speech:
http://localhost/txt2speech/v.php?textbox=Hello Word
如果我在浏览器中输入该 URL,我希望它能够播放音频。
我可以成功地将文本转换为语音,但问题是它播放的是同一个文件。
示例
如果我发送http://localhost/txt2speech/v.php?textbox=HelloWord 然后如果我发送http://localhost/txt2speech/v.php?textbox=SecondString
它播放 HelloWorld,但我希望它播放 SecondString
但是,如果我在不同的窗口中尝试,它将播放 SecondString 文件。
我还有一个问题。如果我传递一个带有空格的字符串,它将不起作用。
示例
http://localhost/txt2speech/v.php?textbox=Hello This is sentence with spaces
这些是我正在使用的文件:
index.php
<html>
<body>
<h2>Text to Speech PHP Script</h2>
<form action="v.php" method="GET">
Enter your text: <input name="textbox"></input>
</form>
</body>
</html>
v.php
<?php
if($_GET){
$text = substr($_GET['textbox'], 0, 100);
$file = 'filename';
$file = "audio/" . $file . ".mp3";
$mp3 = file_get_contents("https://translate.google.com.vn/translate_tts?ie=UTF-8&q=$sname+&tl=en&client=tw-ob");
file_put_contents($file, $mp3);
}
?>
<?php if($_GET){?>
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo $file; ?>" type="audio/mp3" />
</audio>
<?php }?>
【问题讨论】:
标签: php html text text-to-speech speech