winform activate sound recorder

CharlieChau

Active member
Joined
Jun 15, 2004
Messages
26
Programming Experience
Beginner
How can I use a button in winform to activate the sound recorder in the entertainment.

Thanks,
CC
 
you can use the mciSendString Api to record sound via a microphone , the api is like this ...
VB.NET:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32) As Int32
a good site showing examples of mciSendString is this ...http://www.geocities.com/smigman.geo/mci/wav.html
the section you need is this ...
Record a WAV File From Scratch

Open... Capture...
Before you can record a WAV file, you must open the WAV device with a new type, in this case it is waveaudio which we will refer as capture in the examples that follow. (Don't confuse this OPEN with the other OPEN statement).

i = mciSendString("open new type waveaudio alias capture", 0&, 0, 0)Bits per Sample...
The Bits per Sample can be set using the bitspersample command with either 8 or 16 following it. The eight sets the wave file to record at 8 bits, the sixteen sets the wav file to record at 16 bits (16 bits has better sound quality).

i = mciSendString("set capture bitspersample 8", 0&, 0, 0)Samples per Second...
The Samples per Second can be set using the samplespersec command.

Samples that are supported:
11025 low quality
22050 medium quality
44100 high quality (CD music quality)

i = mciSendString("set capture samplespersec 11025", 0&, 0, 0)NOTE: Many people have e-mailed me saying that they cannot record a WAV at different qualities. So far, I haven't been able to help them out. I do know this much. I have successfully recorded all possible types of WAV files, but noticed that determining the Sample rate always returns 11025 even though we know that the WAV is recorded at a higher level. A mystery that I haven't figured out yet (in VB5.0).

Mono... Stereo...
Set the wav to record with one channel (1 = mono) or two channels (2 = stereo). Use the channels command in the example below.

i = mciSendString("set capture channels 1", 0&, 0, 0)Record...
With or without the using settings shown above, you can still record a WAV file. The line of code below is almost the same as the play command. When used, it immediately starts recording until you stop or pause it.

i = mciSendString("record capture", 0&, 0, 0)DELETE
You can delete any section of a WAV file. The nice thing about this, is the fact that you do not need to be a math wizard to figure out what you just deleted incase you want to delete multiple sections.

If you use the sample code below, it works. If you use it again during the same session, nothing will happen. This is because you are refering to the size of the original file (before saving it). Deleting the fist part of the WAV doesn't make the file length shorter (until you save it as a new file), it just isn't played back. It is easy to delete a middle section or an end section when refering to the original file length.

i = mciSendString("delete capture from 1 to 200", 0&, 0, 0)Save
A WAV file is not created until you save it. Any recorded data in a WAV file is buffered, or placed into temporary memory. The code below will make the WAV file with the newly recorded information, using the save command. Make sure you save the file with a unique name. Saving a file with one that already exists will completely ruin the older file. The output in this example is "C:\NewWav.wav".

i = mciSendString("save capture c:\NewWave.wav", 0&, 0, 0)
hope it helps :)
 
Back
Top