我一直在尝试制作一个文本到语音程序,我在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();
}
}
答案 0 :(得分:2)
say
命令。
您可以创建一个脚本
@echo off
echo Dim Speak >> %HOMEPATH%\speak.vbs
echo Set Speak=CreateObject("sapi.spvoice") >>
%HOMEPATH%\speak.vbs
echo Speak.Speak "%1">> %HOMEPATH%\speak.vbs
%HOMEPATH%\speak.vbs
del %HOMEPATH%\speak.vbs
从https://superuser.com/questions/223913/os-x-say-command-for-windows
粘贴将脚本命名为 speak.bat 并将其放入C:\Windows\system32
然后修改
Process p = rt.exec("say" + textfield.getText());
到
Process p = rt.exec("speak" + textfield.getText());
您可能还会看一下开源的espeak
。