Php 将参数设置为函数以处理它
因此,我需要将参数设置为函数,以便将其转换为.mp3文件。使用此行:Php 将参数设置为函数以处理它,php,Php,因此,我需要将参数设置为函数,以便将其转换为.mp3文件。使用此行:$tts->setText($row['raspuns'])不会发生任何事情,但如果我写$tts->setText(“你好,世界!”)它工作得很好,这让我得出结论,我必须找到一个正确的代码,使tts获得文本。有人能帮我吗 <html> <head> <title> Bot </title> <li
$tts->setText($row['raspuns'])代码>不会发生任何事情,但如果我写$tts->setText(“你好,世界!”)代码>它工作得很好,这让我得出结论,我必须找到一个正确的代码,使tts获得文本。有人能帮我吗
<html>
<head>
<title>
Bot
</title>
<link type="text/css" rel="stylesheet" href="main.css" />
</head>
<body>
<form action="bot.php "method="post">
<lable>You:<input type="text" name="intrebare"></lable>
<input type="submit" name="introdu" value="Send">
</form>
</body>
</html>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("robo") or die(mysql_error());
$intrebare=$_POST['intrebare'];
$query = "SELECT * FROM dialog where intrebare = '$intrebare'";
$result = mysql_query($query) or die(mysql_error());
$row = $result;
?>
<?php
require "tts.php";
$tts = new TextToSpeech();
**$tts->setText($row['raspuns']);**
*//$tts->setText("Hello World!");*
$tts->saveToFile("voice.mp3");
$file='voice.mp3';
?>
<div id="history">
<?php
while (true == ($row = mysql_fetch_array($result))) {
echo "<b>The robot says: </b><br />";
echo $row['raspuns'];
echo "<embed src =\"$file\" hidden=\"true\" autostart=\"true\"></embed>";
}
?>
</div>
机器人程序
你:
您需要从结果中提取行
如果希望代码在tts类调用所在的位置工作,请更改
$row = $result;
到
注意,下面有一个代码块,用于重新定义$row数组
另请注意,mysql_*函数已弃用,请改用PDO或mysqli_*函数。您当前的代码对sql注入非常开放 听着,丹尼尔,你需要把你的问题标记为已回答!现在你有三个问题都有很好的答案,但没有任何分数。如果你不这样做,人们就会停止帮助你!好啊您的查询是否得到任何结果或多行?(mysql_fetch_row将需要1行,或者您需要使用mysql_fetch_array()循环遍历结果,就像您在下面做的那样。然后您是否取消了对$tts->setText($row['raspuns'])行的注释?请注意,您可以完全取消while循环。
$row = $result;
$row = mysql_fetch_row($result);