我有以下代码:
public class ChatSystem {
public static void main(String[] args) {
SpeakCommand sp = new SpeakCommand("hello master! How are you feeling today?");
sp.execute();
}
}
import java.io.IOException;
public class SpeakCommand implements CommandInterface{
String message;
public SpeakCommand(String content){
message=content;
}
public void execute() {
try {
System.out.println("spd-say \"" +message+ "\" -p 100 -i 100 -t female1");
Runtime.getRuntime().exec("spd-say \"" +message+ "\" -p 100 -i 100 -t female1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
如果执行该命令,我的笔记本电脑会以正确的声音说“你好”(即-p 100 -i 100 -t female1 -r -40
确实传递给 say)。打印输出还正确显示了 spd-say,"hello master! How are you feeling today?" -p 100 -i 100 -t female1
如果在命令行中执行该命令,它会起作用。知道我做错了什么吗?
答案1
代替
Runtime.getRuntime().exec("spd-say \"" +message+ "\" -p 100 -i 100 -t female1");
和
Runtime.getRuntime().exec(new String[]{"spd-say",'\"'+message+'\"',"-p 100 -i 100 -t female1");
它会起作用的。干杯!