0
我有这个代码,它工作正常,但我一直在努力如何让它输出一个可以嵌入在页面中的wav文件,而不是让用户下载和收听。 任何帮助,不胜感激。我希望能够使用查询字符串直接调用该文件,以便它与验证码文本匹配。 Model.InstanceData [“Code”]是文本字符串中的验证码。我似乎无法忘记它。谢谢!使用嵌入文本到语音
private void _playBtn_Click(object sender, ImageClickEventArgs e)
{
HttpContext context = HttpContext.Current;
if (context == null || context.Response == null)
{
return;
}
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment; filename=" + "captcha.wav");
context.Response.AddHeader("content-transfer-encoding", "binary");
context.Response.ContentType = "audio/wav";
SoundGenerator soundGenerator = new SoundGenerator(Model.InstanceData["Code"]);
MemoryStream sound = new MemoryStream();
// Write the sound to the response stream
soundGenerator.Sound.Save(sound, SoundFormatEnum.Wav);
sound.WriteTo(context.Response.OutputStream);
}