Solved

Setting recording properties in MMControl

Posted on 2004-04-26
5
1,178 Views
Last Modified: 2007-12-19
I am using MMControl object vb5 to record speech.  I want to be able to set recording properties to 16 bits, 16,000 Hz sampling, mono.  How can I do this?
0
Comment
Question by:Venkatagiri
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:OHDev2004
ID: 10923585
you want the whole code for recording or just the command that will set that setting ?

if you want the command that will set that setting use this :

dim RetLng as long
RetLng = mciSendString("set recwav time format ms bitspersample 16 channels 1 samplespersec 16000", 0, 0, 0)
0
 

Author Comment

by:Venkatagiri
ID: 10930519
I am using the MMControl command "Record" to record speech.  It appears to me, after having played with MCISendString as suggested by you, that if I use MCISendString to set bits per sample, etc, then I would have to use another MCISendString to record and another one to save instead of the MMControl commands "Record" and "Save."  Is there a way to set the recording parameters when using MMControl to record and save?  MMControl appears to use the Windows default for recording.  MCISendString does not appear to affect recording parameters set in Windows (in my case XP).  Thanks for your help.
0
 
LVL 7

Expert Comment

by:OHDev2004
ID: 10930747
when you use the string i posted it's for intializing the MMControl so this does the trick ,,
this also affects the save command ,,
i dont know what problem you encouter here :) if you want the whole code for recording i can post it to you
0
 

Author Comment

by:Venkatagiri
ID: 10933140
First, let me explain what I am doing.  Am I right in assuming that the code you provided would work only with the following declaration because without it I received an error?
       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

Next I included your code in the Form_Load sub in the form that has the MMControl object.  Later I recorded and saved a wav file using the MMControl commands "Record" and "Save".  When I checked the recording properties of this file, it was Windows default of 8-bit, 11025 Hz, mono.

If I am doing something wrong here, please post the entire code and I will try it.  Thanks for your help.
0
 
LVL 7

Accepted Solution

by:
OHDev2004 earned 250 total points
ID: 10933842
i only posted that line of code assuming you already have the full code and you'll replace the existing one with the one i posted ,,

ok here is the Full Code (by the way it's a modification of 2 other coders) :)
but i combined it to be a one working function

============================================================
'In a Module
Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Public 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 Function RecordWave(DurationInSeconds As Long, BitRate As Single, Channels As Single, SamplesPerSeconds As Long, OutputFile As String)
    Dim lRes As Long, sRes As String * 255, sErr As String * 255
    Dim Alignment As Long
    Dim RBuffer As String
    RBuffer = Space$(260)
    Alignment = Channels * BitRate / 8
    i = mciSendString("close all", RBuffer, Len(RBuffer), 0)
    lRes = mciSendString("open new type waveaudio alias capture", RBuffer, Len(RBuffer), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("set capture alignment " & Alignment & " bitspersample " & BitRate & " samplespersec " & SamplesPerSeconds & " channels " & CStr(Channels) & " bytespersec " & (Alignment * SamplesPerSeconds), sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("record capture", sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    Pause DurationInSeconds
    lRes = mciSendString("stop capture", sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("save capture " & OutputFile, sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("close capture", 0, 0, 0)
    If lRes <> 0 Then GoTo MCIError
    MsgBox "Finito"
    Exit Function
MCIError:
    mciSendString "stop recwav", 0, 0, 0
    mciSendString "close recwav", 0, 0, 0
    mciGetErrorString lRes, sErr, Len(sErr)
    MsgBox Replace(sErr, vbNullChar, vbNullString)

End Function


Public Sub Pause(ByVal lMilleseconds As Long)
    Dim lCurr As Long
    lCurr = Timer + (lMilleseconds / 1000)
    Do Until lCurr <= Timer
        DoEvents
    Loop
End Sub
===========================================

here is a sample :

Dim RecDuration As Long
Dim RecFile As String
RecFile = "C:\Record-Test.wav"
RecDuration = 5 * 1000

'Use only the followong samplerates:
'11025 - 22050 - 44100
Call RecordWave(RecDuration, 8, 1, 22050, RecFile)


Hope that this works ,, i've tested it :)
OHDev2004
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now