Solved

Setting recording properties in MMControl

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

809 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