Javascript 如何将PHP表中的文本转换为语音
我正在做一个项目,我有一个包含学生名单的表格,我想让我的网络应用程序一个接一个地“说出”他们的名字和姓氏,就像老师在标记谁在场或不在场一样 我不知道在这种情况下使用的技术是Javascript还是PHP,尽管看起来Javascript可能更容易 以下是表格显示的代码,我提前向大家表示感谢:Javascript 如何将PHP表中的文本转换为语音,javascript,php,text-to-speech,Javascript,Php,Text To Speech,我正在做一个项目,我有一个包含学生名单的表格,我想让我的网络应用程序一个接一个地“说出”他们的名字和姓氏,就像老师在标记谁在场或不在场一样 我不知道在这种情况下使用的技术是Javascript还是PHP,尽管看起来Javascript可能更容易 以下是表格显示的代码,我提前向大家表示感谢: <?php if (isset($_GET['datepick']) & isset($_GET['classpick'])) { $datepicked = $_GE
<?php
if (isset($_GET['datepick']) & isset($_GET['classpick'])) {
$datepicked = $_GET['datepick'];
$matierepicked = $_GET['classpick'];
$viewab = $conn->prepare("SELECT * FROM absence,etudiant WHERE absence.date = ? AND absence.matiere = ? AND (absence.etudiant_ID = etudiant.etudiant_ID)");
$viewab->execute(array($datepicked, $matierepicked));
if ($viewab->rowCount()!=0){
echo("<table class='table table-condensed table-hover table-bordered table-striped' style='background-color: white'>");
echo "<tr>";
echo "<th style='background-color: grey'> Nom </th>";
echo "<th style='background-color: grey'>Prenom </th>";
echo "<th style='background-color: grey'>Matiere</th>";
echo "<th style='background-color: grey'>Date</th>";
echo "<th style='background-color: grey'>Total des heures absentées</th>";
echo "</tr>";
while ($row = $viewab->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['Nom'] . "</td>";
echo "<td>" . $row['Prenom'] . "</td>";
echo "<td>" . $row['matiere'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['Nb_absences'] . "</td>";
echo "</tr>";
}
echo("</table>"); }
Javascript将更容易,例如:
var msg = new SpeechSynthesisUtterance();
msg.text = "Hello World";
window.speechSynthesis.speak(msg);
Javascript将更容易,例如:
var msg = new SpeechSynthesisUtterance();
msg.text = "Hello World";
window.speechSynthesis.speak(msg);
您可以解析表并将名称添加到表中
下面是使用的更高级示例
//获取HTML元素
const persons=document.queryselectoral('.person表tbody tr');
const btn=document.querySelector('.speak btn');
//说话功能
const speak=(msg)=>{
const synth=新语音合成();
synth.text=msg;
window.speechSynthesis.speak(synth);
}
//念名字
常量发音名称=(人)=>{
for(const person of persons){
const[name,lastname]=person.children;
const fullname=`${name.textContent}${lastname.textContent}`;
讲(全名);
}
}
//添加单击事件
btn.addEventListener('click',()=>发音名称(persons))代码>
姓名姓性别
埃利斯·西蒙斯F
杜鲁夫·马歇尔
米利森特·汉森F
常春藤
本杰明·拉曼
Speak
您可以解析您的表并将名称添加到表中
下面是使用的更高级示例
//获取HTML元素
const persons=document.queryselectoral('.person表tbody tr');
const btn=document.querySelector('.speak btn');
//说话功能
const speak=(msg)=>{
const synth=新语音合成();
synth.text=msg;
window.speechSynthesis.speak(synth);
}
//念名字
常量发音名称=(人)=>{
for(const person of persons){
const[name,lastname]=person.children;
const fullname=`${name.textContent}${lastname.textContent}`;
讲(全名);
}
}
//添加单击事件
btn.addEventListener('click',()=>发音名称(persons))代码>
姓名姓性别
埃利斯·西蒙斯F
杜鲁夫·马歇尔
米利森特·汉森F
常春藤
本杰明·拉曼
Speak
JS有一个(实验性)功能,可以用于此。@雷诺,谢谢,我会看看它是否有助于添加到其他注释这里是官方的W3C Web Speech API文档->这也可能被证明是有用的。如果你想支持IE,你需要一个polyfill->JS有一个(实验性的)可用于此目的的功能。@Reyno谢谢,我会看一下,看看它是否有助于添加到其他注释中。这里是官方的W3C Web Speech API文档->它也可能被证明是有用的。请注意,如果您想支持IE,您需要一个polyfill->我是否应该将每一行的名称和姓氏连接到该消息中变量,然后对其使用speak函数?您认为这是一个好方法吗?是的,您可以将所有行放在一个变量中,并对每行进行speak或speak。这是生成Speech的最简单wat我是否应该将每行的名称和姓氏连接到msg变量中,然后对其使用speak函数?你认为这是一个很好的方法吗?是的,你可以把所有的行放在一个变量中,然后对每一行进行speak或speak。这是生成speech的最简单的wat