VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Record sound from mic, cd-line, etc into a file.

by Islam Mohamed Adel (3 Submissions)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 26th June 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Record sound from mic, cd-line, etc into a file.

API Declarations


'This is by: Islam Mohamed Adel

Rate Record sound from mic, cd-line, etc into a file.



'   Name    :   Record.cls
'   Author  :   Islam Mohamed Adel
'
'   Notes   :   A record class, which when turned
'           :   into an object lets you record sound
'           :   through mic, cd-line, etc... into a file


' -=-=-=- PROPERTIES -=-=-=-
' FileName      Determines the name of the file used (wav only)
' State        The current status of the object (Read Only)

' -=-=-=- METHODS -=-=-=-=-
' PauseRecord     Toggle pause the record (if you are already recording)
' StartRecord     Start Recording (you must have been set a good filename)
' StopRecord      Stop recording (and will save the sound into <filename>)

--------
' NOTES
' -----
'
' Before you can Start or Stop recording you must set a good
' filename which the class will use to save your sound into.
---------

Private FName As String
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Enum MyState
    Idle
    Recording
    Paused
End Enum
Private xState As MyState
Public Property Get FileName() As String
FileName = FName
End Property

Public Property Let FileName(ByVal sFileName As String)
FName = sFileName
End Property

Public Function StartRecord() As Boolean
On Error GoTo ER:
If FName = "" Then GoTo ER:
Dim RS As String, cb As Long, I As Long
RS = Space$(128)
I = mciSendString("open new type waveaudio alias capture", RS, 128, cb)
I = mciSendString("record capture", RS, 128, cb)
xState = Recording
StartRecord = True
Exit Function
ER:
StartRecord = False
End Function

Public Function StopRecord() As Boolean
On Error GoTo ER:
If FName = "" Then GoTo ER:
Dim RS As String, cb As Long, I As Long
RS = Space$(128)
I = mciSendString("save capture " & FName, RS, 128, cb)
I = mciSendString("close capture", RS, 128, cb)
xState = Idle
StopRecord = True
Exit Function
ER:
I = mciSendString("close capture", RS, 128, cb)
StopRecord = False
End Function

Private Sub Class_Initialize()
xState = Idle
End Sub

Private Sub Class_Terminate()
StopRecord
End Sub



Public Function PauseRecord() As Boolean
On Error GoTo ER:
If FName = "" Then GoTo ER:
Dim RS As String, cb As Long, I As Long
RS = Space$(128)
If xState = Paused Then
I = mciSendString("record capture", RS, 128, cb)
xState = Recording
ElseIf xState = Recording Then
I = mciSendString("pause capture", RS, 128, cb)
xState = Paused
End If
PauseRecord = True
Exit Function
ER:
PauseRecord = False
End Function


Public Property Get State() As MyState
State = xState
End Property



Download this snippet    Add to My Saved Code

Record sound from mic, cd-line, etc into a file. Comments

No comments have been posted about Record sound from mic, cd-line, etc into a file.. Why not be the first to post a comment about Record sound from mic, cd-line, etc into a file..

Post your comment

Subject:
Message:
0/1000 characters