gpt4 book ai didi

java - 玩!框架 [1.2.4] - 通过 wami-recorder 接受音频/xwav 内容类型

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:12:38 25 4
gpt4 key购买 nike

我正在尝试使用 https://code.google.com/p/wami-recorder/ 在浏览器端录制一段声音片段,然后通过 wami 示例和服务器端 Controller 方法上传该文件。出于某种原因,request.body InputStream 抛出此错误:

java.io.IOException: Bad file descriptor
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:198)
at controllers.APIVoicemailController.addNewRecording(APIVoicemailController.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:256)
at play.Invoker$Invocation.run(Invoker.java:276)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:234)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

路由POST/upload的 Controller 方法

   public static void addNewRecording() {
if (request.method.equals(Constants.METH_POST)) {
try {
InputStream inputStream = request.body;
Map<String, Header> headerMap = request.headers;
for (Entry<String, Header> entry : headerMap.entrySet()) {
Logger.info("Head: " + entry.getKey() + " name; "
+ entry.getValue().name + " val: " + entry.getValue().value());
}

OutputStream out = new FileOutputStream(new File(
"/Users/franklovecchio/Desktop/file.mp3"));

int read = 0;
byte[] bytes = new byte[1024];

/* ERROR ON LINE BELOW */
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}

inputStream.close();
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}

for (Entry<String, String> params : request.params.allSimple().entrySet()) {
Logger.info("k: " + params.getKey() + "v: " + params.getValue());
}
renderCustomMessage("Created new recording.", "Success.");
}
}

我该如何解决?

最佳答案

我正在使用 Play 2,但如果您只是获取 InputStream 的内容而不检查 header ,您将能够毫无问题地将其存储在 WAV 文件或 DB 中。

关于java - 玩!框架 [1.2.4] - 通过 wami-recorder 接受音频/xwav 内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9875158/

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