Sunday, September 18, 2011

Record and Play your voice application in asp.net

Here in this example i will show how to record and play your voice

Take control in .aspx page

 <asp:Button ID="BtnRecord" runat="server" Text="Record" onclick="BtnRecord_Click" />
        <br />
        <asp:Button ID="Btnsavestop" runat="server" Text="SaveStop"
            onclick="Btnsavestop_Click" />
        <br />
        <asp:Button ID="Btnread" runat="server" Text="Read" onclick="Btnread_Click" />

Now in code behind file  .cs


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

public partial class _Default : System.Web.UI.Page
{
    [DllImport("winmm.dll",EntryPoint="mciSendStringA")]
    private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

    protected void Page_Load(object sender, EventArgs e)
    {
        Computer computer = new Computer();
         computer.Audio.Play("c:\\Mere Bina.mp3", AudioPlayMode.WaitToComplete);
    }
protected void BtnRecord_Click(object sender, EventArgs e)
{
  
    mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
    mciSendString("record recsound", "", 0, 0);

}
protected void Btnsavestop_Click(object sender, EventArgs e)
{
    mciSendString("save recsound c:\\record.wav", "", 0, 0);
    mciSendString("close recsound ", "", 0, 0);
    Computer c = new Computer();
    c.Audio.Stop();

}
protected void Btnread_Click(object sender, EventArgs e)
{
    Computer computer = new Computer();
    computer.Audio.Play("c:\\record.wav", AudioPlayMode.WaitToComplete);

}
}

to get better result use microphone


4 comments:

  1. Hi it is working fine, but the problem is even though i use the microphone, the sound of recorded audio is very low , will you plz help me with this.

    Regards,
    Bhanuprakash

    ReplyDelete
  2. hi please provide the running code

    ReplyDelete
  3. Hi , Mozila firefox this code is not working pls help me.

    ReplyDelete
  4. cant add substring c:\\record.wav in "save recsound c:\\record.wav". also not working in server based

    ReplyDelete