2013-04-22 7 views
0

У меня есть этот код, и он отлично работает, но я изо всех сил пытаюсь получить его для вывода wav-файла, который может быть встроен в страницу, а не для того, чтобы пользователь загружал и слушал. Любая помощь очень ценится. Я хотел бы иметь возможность напрямую вызвать файл с помощью строки запроса, чтобы он соответствовал текстуу перехвата. Model.InstanceData ["Код"] - это штрих-код в текстовой строке. Я просто не могу показаться, что обманываю его. Благодаря!Текст в речь с использованием встроенного

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

ответ

0

В основном после того, как много игр вокруг решения было немного проще, чем я думал. Я создал новый CaptchaPlayer.aspx плеер в моем проекте и в коде использовал:

protected void Page_Load(object sender, EventArgs e) 
    { 
     PlayCaptchaSession(); 
    } 

    private void PlayCaptchaSession() 
    { 
     object o = Session["captcha"]; 

     if (o != null) 
     { 
      HttpContext context = HttpContext.Current; 

      if (context == null || context.Response == null) 
      { 
       return; 
      } 

      //context.Response.AddHeader("content-disposition", "inline; filename=" + "captcha.wav"); 
      context.Response.AddHeader("content-transfer-encoding", "binary"); 
      context.Response.ContentType = "audio/wav"; 
      SoundGenerator soundGenerator = new SoundGenerator(o as string); 
      MemoryStream sound = new MemoryStream(); 
      // Write the sound to the response stream 
      soundGenerator.Sound.Save(sound, SoundFormatEnum.Wav); 
      sound.WriteTo(context.Response.OutputStream); 
     } 
    } 

} 

После этого я смог добавить встраивание в виде страницу

<embed id='captchaAudio' width='1' height='1' enablejavascript='true' autostart='false' name='Verification code player' src='/CaptchaPlayer.aspx'> 
       <noembed><a href='/CaptchaPlayer.aspx' title='Verification code wave audio file download'>Audio File</a></noembed> 
       <script type="text/javascript"> 
       $(document).ready(function(){ 
        $(".capLink").click(function() { 
         //alert(".click() called."); 
         document.getElementById('captchaAudio').Play(); 

        }); 
       });  
       </script> 

И что сделало обмануть! Я надеюсь, что это помогает кому-то.

Смежные вопросы