Solved

Setting recording properties in MMControl

Posted on 2004-04-26
5
1,174 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now