Using a c# handler to serve up wav files cuts audio short (only a couple of seconds)

假如想象 提交于 2019-12-11 04:28:47

问题


I've got a c# handler that serves up audio files I've generated using text-to-speech. When the files are written to disk they sound fine, but when I try and play them in a browser (via the handler) using a quicktime plugin it cuts them short at about 2 seconds.

Inside the handler I'm using the following code...

context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/x-wav";

context.Response.WriteFile(fileName);
context.Response.Flush();

Anyone know what I'm doing wrong?


回答1:


You should try writing the file as binary data directly to the OutputStream

context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/x-wav";
byte[] byteArray = File.ReadAllBytes(fileName);
context.Response.OutputStream.Write(byteArray, 0, byteArray.Length);


来源:https://stackoverflow.com/questions/4245137/using-a-c-sharp-handler-to-serve-up-wav-files-cuts-audio-short-only-a-couple-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!