开发者

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

开发者 https://www.devze.com 2023-01-26 13:02 出处:网络
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)

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开发者_Python百科.Flush();

Anyone know what I'm doing wrong?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消