我有一个c#处理程序,它提供我使用文本到语音生成的音频文件。当文件被写入磁盘时,它们听起来很好,但是当我尝试在浏览器中(通过处理程序)使用quicktime插件播放它们时,它会将它们缩短大约2秒。
在处理程序中,我使用以下代码。。。
context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.ContentType = "audio/x-wav"; context.Response.WriteFile(fileName); context.Response.Flush();
有人知道我做错了什么吗?
您应该尝试将文件作为二进制数据直接写入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);