Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording Voice

Status
Not open for further replies.

Fifer74

Programmer
Feb 25, 2003
12
0
0
GB
Hi,

Does anyone know how to record voice from a microphone to a .wav file in VB .NET 2003.

Thanks in advance.
 
You can use the mciSendString API for this:

Declaration:

Code:
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

Code:

Code:
Dim i As Integer 'Used for the return values

'First we must tell the API we want to open a new capture using wave audio:
i = mciSendString("open new type waveaudio alias capture", 0&, 0, 0)

'Then you set the bits per sample (8 or 16)
'16 bits per sample is better quality, but larger file
i = mciSendString("set capture bitspersample 16", 0&, 0, 0)

'Next the Samples per Second can be set using the samplespersec command.
'11025=low quality
'22050=medium quality
'44100=high quality
i = mciSendString("set capture samplespersec 11025", 0&, 0, 0)

'Specify wether you want mono (1) or stereo (2):
i = mciSendString("set capture channels 2", 0&, 0, 0)

'Start recording:
i = mciSendString("record capture", 0&, 0, 0)

'It will continue recording untill you pause or stop it:
i = mciSendString("pause capture", 0&, 0, 0)

'When paused it can be resumed:
i = mciSendString("resume capture", 0&, 0, 0)

'Or you can stop it in order to save it afterwards:
i = mciSendString("stop capture", 0&, 0, 0)

'Finally, you can save the file:
i = mciSendString("save capture c:\NewWave.wav", 0&, 0, 0)

Remember to save the file in a unique filename, otherwise the file will be overwritten without warning!

Also, check the mciSendString API for much more functionality like deleting parts, inserting parts, etc.

Regards, Ruffnekk
---
Basic Instructions Before Leaving Earth (B.I.B.L.E.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top