gpt4 book ai didi

java - 将 CMUSphinx 与 PyAIML 连接 - 输入/输出流

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:09 25 4
gpt4 key购买 nike

我有一个使用 PyAIML 用 Python 编写的简单聊天机器人,并且我正在运行一个与它一起运行的 Java 语音到文本系统。现在,我想将 Java 的输出通过管道传输到 Python 中。

这是我迄今为止尝试过的:

File file = new File("C:\\Users\\path\\to\\chat_bot\\");

Process process = Runtime.getRuntime().exec("python chat.py", null, file);
OutputStream stdin = process.getOutputStream();
InputStream stderr = process.getErrorStream();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

while ((line = reader.readLine()) != null) {
System.out.println("Stdout: " + line);
}

String input = in.nextLine();
input += "\n";
writer.write(input);
writer.flush();

现在,我在 Python 2.7 中安装了 AIML,但由于某种原因,默认值已设置为 Python 3.3另外,我从 Java 得到的错误是:

java.io.IOException:管道正在关闭

我已更改 Windows 注册表以将 Python 2.7 设置为默认值,但这没有用。那么,如何设置Java运行C:\Python27文件夹中的python呢?我真的还不想卸载 Python 3.3。

最佳答案

您可能应该使用 ProcessBuilder (而不是 Runtime.exec)。除此之外,您可能应该使用 python 版本的完整路径(例如使用 c:\\Python27\\bin\\python 而不是仅仅 python)想要。

关于java - 将 CMUSphinx 与 PyAIML 连接 - 输入/输出流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20306713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com