Solved

Setting recording properties in MMControl

Posted on 2004-04-26
5
1,207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 81
Help me. 3 79
VBA - If Bookmark = "XXBOOKMARKXX" then 15 67
Fastest way to find and count same items VB6 16 62
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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