【发布时间】:2015-03-12 16:22:42
【问题描述】:
我一直在尝试制作一个文本到语音程序,我在 Windows pc 上仅供参考。我无法让我的程序说出我告诉它的内容。如果有人可以帮助我解决此问题或将我指向可以帮助我解决此问题的资源,将不胜感激
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class javatalker extends JFrame{
private static final long serialVersionUID = 1L;
JPanel panel = new JPanel();
JTextField textfield = new JTextField(35);
JButton button = new JButton("Push To Talk");
JCheckBox checkbox1 = new JCheckBox("Normal");
JCheckBox checkbox2 = new JCheckBox("Blitzcrank");
public javatalker() {
panel.add(textfield);
panel.add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(textfield.getText().equalsIgnoreCase("")){
System.out.println("Typle in a string");
} else{
Runtime rt = Runtime.getRuntime();
try{
if(checkbox1.isSelected() == true){
Process p = rt.exec("say" + textfield.getText());
}
if(checkbox2.isSelected() == true){
Process p = rt.exec("say -v Cellos" + textfield.getText());
} else{
System.out.println("Please select a voice");
}
}catch(Exception ex) {
ex.getStackTrace();
}
}
}
});
panel.add(checkbox1);
panel.add(checkbox2);
panel.setBackground(Color.black);
add(panel);
setTitle("Voicip");
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
}
public static void main(String args[]){
new javatalker();
}
}
【问题讨论】:
-
我认为“say”命令在 Windows 上不起作用。我相信它只是 OS X。
-
你知道windows是什么
-
我没用过,不过这个问题或许能帮到你:superuser.com/questions/223913/os-x-say-command-for-windows
标签: java windows text-to-speech