您好,请帮助我已经使用免费的 tts 完成了一个文本到语音的 Java 应用程序现在我正在尝试用 struts 2 做同样的事情。我在我的表格中创建了一个按钮,我的想法是当我点击按钮时我会调用一个struts 动作称为发音扩展了 freetts 类,它将读取我的表的内容,但我不知道该怎么做这是我旧的免费 tts 类
package com.hello;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class myfreetts {
private String text; // string to speech
Voice voice;
public Prononcer(String text) {
this.text = text;
}
public void execute() {
System.setProperty("mbrola.base", "C:\\Users\\iup\\workspace\\newpro\\mbrola");
VoiceManager voiceManager = VoiceManager.getInstance();
voice = voiceManager.getVoice("mbrola_en1");
voice.allocate();
voice.speak(text);
}
public static void main(String[] args) {
String text = "FreeTTS was written by the Sun Microsystems Laboratories "
+ "Speech Team and is based on CMU's Flite engine.";
myfreetts freeTTS = new myfreetts(text);
freeTTS.execute();
}
}
这是我的jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>profile success</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#p").click(function(){
alert("Le bouton a été cliqué.");
});
});
</script>
</head>
<body background="images\25.jpg">
<div style="text-align: center"> <div style="color:WHITE"> <h1> Les informations de votre commande </h1></div></div>
<hr/>
<table border="2">
<tr>
<td><div style="color:cc9999"><h3>No_commande </h3> </div></td>
<td><div style="color:cc9999"><h3>Nom </h3> </div></td>
<td><div style="color:cc9999"><h3>Date </h3> </div></td>
<td><div style="color:cc9999"><h3>Etat </h3> </div></td>
<td><div style="color:cc9999"><h3>Tel </h3> </div></td>
<td><div style="color:cc9999"><h3>Prononcer </h3> </div></td>
<td><div style="color:cc9999"><h3>Test </h3> </div></td>
</tr>
<s:iterator value="list" id="message">
<tr>
<td><div style="color:WHITE"><h3> <s:property value="no_commande"/></h3> </div></td>
<td><div style="color:WHITE"><h3><s:property value="nom_client"/></h3> </div></td>
<td><div style="color:WHITE"><h3><s:property value="date"/></h3> </div></td>
<td><div style="color:WHITE"><h3><s:property value="etat"/></h3> </div></td>
<td><div style="color:WHITE"><h3><s:property value="tel"/></h3> </div></td>
<td><div style="color:WHITE"><h3><button id="p">Cliquez ici</button>
<td><div style="color:WHITE"><h3><a href="prononce">test</a> </h3> </div></td>
</h3> </div></td>
</tr>
</s:iterator>
</table>
</body>
</html>
ps:我仍在测试按钮,这就是我使用警报的原因,这是我的 struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<action name="login">
<result >login.jsp</result>
</action>
<action name="loginprocess" class="com.hello.Login" method="execute">
<result name="success" >loginsucces.jsp</result>
<result name="error" >loginerror.jsp</result>
</action>
<action name="logout" class="com.hello.Login" method="logout">
<result name="success" >logoutsuccess.jsp</result>
</action>
<action name="profile" class="com.hello.Profile">
<result name="success" >profilesuccess.jsp</result>
<result name="error" >profileerror.jsp</result>
</action>
<action name="loginprocess" class="com.hello.Login" method="execute">
<result name="success" >loginsucces.jsp</result>
<result name="error" >loginerror.jsp</result>
</action>
<action name="viewrecords" class="com.hello.RetrieveRecords">
<result name="success">viewrecords.jsp</result>
</action>
<action name="prononce" class="com.hello.myfreetts">
<result>test.jsp</result>
</action>
</package>
</struts>
请帮助我绝望。