dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberss
baskar
Sriram
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » ASP.NET WebForms

How to record voice from microphone?


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 10


In this article, you will know how to record voice from microphone? You can record voice by the use of Microsoft APIs to solve this issue



 


Learn how to record voice from microphone?


Do you want to record your voice from Microphone? If yes, you can use the Microsoft APIs to solve this issue. It's a very simple approach to record your voice from Mic. I provided C#.net code to solve this issue.



1. Open C#.net web applications. And added the blow namespace.

using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

2. Add the below API.
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

3. Create three Buttons and given the below name and text for the buttons.

1. Record
2. SaveStop
3. Read

1. Under Record Button Click paste the below Code:

// record from microphone
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);

2. Under Save / Stop button Click,


// stop and save
mciSendString("save recsound c:\\record.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
Computer c = new Computer();
c.Audio.Stop();

3. Under Read Button Click

Computer computer = new Computer();
computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background);


Save and Execute it.








Did you like this resource? Share it with your friends and show your love!


Responses to "How to record voice from microphone?"
Author: Abhi    04 Mar 2009Member Level: Gold   Points : 1
http://vivekthangaswamy.blogspot.com/2006/11/using-cnet-play-multimedia-files-using.html




Author: Prashanthi    23 Jul 2009Member Level: Silver   Points : 1
HI RajaRaman,

I used your code in my asp.net application
It is working fine in local machine.

but I want to save the voice record file from the client system.
how can it is possible
if you know the solution plz.. give reply

Thanks & Regards
Prashanthi G.




Author: Prachi    08 Oct 2009Member Level: Gold   Points : 0
How to do this in VB.NET?


Author: max    26 Feb 2010Member Level: Bronze   Points : 1
Hi Prashanthi,

it didn't work for me. Can you paste your code sample here please ?



Author: Travis    25 Jul 2010Member Level: Bronze   Points : 1
I've checked a lot of posts for various ways to record sound from C# in a windows forms. This was the simplest by far.

The only additional thing I had to do was to Add Reference to Microsoft.VisualBasic so that it would recognize "Computer".



Author: Gururaj    01 Feb 2011Member Level: Gold   Points : 1
Hi Rajaraman,

I am facing issues compiling the code. Request your help here.

i. unable to find the dll - Reference using Microsoft.VisualBasic.Devices;

ii. Where is class 'Computer' ?

Regards
|Guru|



Author: Habeebur    04 Nov 2011Member Level: Bronze   Points : 0
im using VS2005, it working but.. its plays nothing... simply i getting usshhhhhhhhh sound......


Guest Author: Shruthi     21 Apr 2012
it works in local properly!... but when uploaded in my Server.. it is not recording means i can see a file.. but when try to read i am not able to read this... recording.. saved..

Can u pls help?



Guest Author: Ashwin     28 May 2012
Can any one tell me how to add an API ? I'm using Microsoft Visual Studio 2010.


Guest Author: manoj     06 Sep 2012
Hi friends.

I want to get the audio from PC microphone and transmit the sound
to camera speakers.

In this article, How to add an API.



Guest Author: Nalina     05 Nov 2012
Super ! it worked like a charm for me!


Guest Author: Chandu Puthra     07 Feb 2013
Iam unable to use it...Not working in my local machine...
it is initiating that using Microsoft.VisualBasic.Devices;.

Devices does not exist in the namespace....

in this also below line also. at" extern int " im getting an error.
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);



Author: Rajendra Patel    09 Apr 2013Member Level: Bronze   Points : 0
please give me solution,Above code is working properly but i get disturbance in recorded voice. Is there any improvement in this code?



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Net DataGrid DateTimePicker column Style.
    Previous Resource: How to write "Text to Speech Applications" in C#?
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.