Results 1 to 2 of 2

Thread: [RESOLVED] Voice recording Test

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Voice recording Test

    Hi,

    Can someone with a microphone please test this code for me. I have tried testing it myself but for some reason my voice is not being picked up by the microphone even though it is switched on.

    You need:

    Label1 (Label)
    Command1 (Command Button)
    Command2 (Command Button)
    Command3 (Command Button)

    Form code
    vb Code:
    1. Private Declare Function mciSendString Lib "winmm.dll" _
    2. Alias "mciSendStringA" (ByVal lpstrCommand As String, _
    3. ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
    4. ByVal hwndCallback As Long) As Long
    5.  
    6. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    7.  
    8. Const MAX_PATH As Long = 260
    9.  
    10. Dim url As String
    11.  
    12. Private Sub Command1_Click()
    13.  Command2.Enabled = True
    14.  url = GetShortFileName(ShowOpenDialog(App.Path, "All Files|*.*", "*.*"))
    15.     mciSendString "play " & url, "", 0, 0
    16.      Label1.Caption = "Playing..."
    17. End Sub
    18. Private Function GetShortFileName(ByVal sFileName As String) As String
    19.     Dim sBuffer As String
    20.     sBuffer = String$(MAX_PATH, vbNullChar)
    21.     Call GetShortPathName(sFileName, sBuffer, MAX_PATH)
    22.     GetShortFileName = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    23. End Function
    24.  
    25. Private Sub Command2_Click()
    26. url = ShowSaveAsDialog(App.Path, "", "All Files|*.*", "*.*")
    27.     mciSendString "open new Type waveaudio Alias recsound", url, 0, 0
    28.    mciSendString "record recsound", url, 0, 0
    29.    MsgBox (url)
    30.    Command2.Caption = "Recording..."
    31.    Label1.Caption = "Recording..."
    32. End Sub
    33.  
    34. Private Sub Command3_Click()
    35.  mciSendString "save recsound " & url, "", 0, 0
    36.  mciSendString "close recsound", "", 0, 0
    37.  Command2.Caption = "Stopped..."
    38.  Label1.Caption = "Stopped..."
    39.  MsgBox "File Created: " & url
    40. End Sub
    41.  
    42. Private Sub Form_Load()
    43.  Command1.Caption = "Play"
    44.  Command2.Caption = "Record"
    45.  Command3.Caption = "Stop"
    46. End Sub

    and this code from Ellis Dee which, needs to be put in a module (the code that is)

    vb Code:
    1. Author: Ellis Dee
    2. 'Website: [url]http://www.vbforums.com/showthread.php?t=605402&highlight=Common+Dialog[/url]
    3.        Option Explicit
    4.      
    5.     Private Enum FlagsEnum
    6.         feOpen
    7.         feSaveAs
    8.     End Enum
    9.      
    10.     Private Type OPENFILENAME
    11.         lStructSize As Long
    12.         hwndOwner As Long
    13.         hInstance As Long
    14.         lpstrFilter As String
    15.         lpstrCustomFilter As String
    16.         nMaxCustFilter As Long
    17.         nFilterIndex As Long
    18.         lpstrFile As String
    19.         nMaxFile As Long
    20.         lpstrFileTitle As String
    21.         nMaxFileTitle As Long
    22.         lpstrInitialDir As String
    23.         lpstrTitle As String
    24.         Flags As Long
    25.         nFileOffset As Integer
    26.         nFileExtension As Integer
    27.         lpstrDefExt As String
    28.         lCustData As Long
    29.         lpfnHook As Long
    30.         lpTemplateName As String
    31.     End Type
    32.      
    33.     Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    34.     Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
    35.      
    36.     ' Common Dialog - Open
    37.     Public Function ShowOpenDialog(pstrInitialPath As String, pstrFilter As String, pstrDefaultExt As String) As String
    38.         Dim typFileName As OPENFILENAME
    39.                
    40.         typFileName = GetStructure(pstrInitialPath, "", pstrFilter, pstrDefaultExt, feOpen)
    41.         If GetOpenFileName(typFileName) Then ShowOpenDialog = Left$(typFileName.lpstrFile, InStr(typFileName.lpstrFile, Chr$(0)) - 1)
    42.     End Function
    43.      
    44.     ' Common Dialog - SaveAs
    45.     Public Function ShowSaveAsDialog(pstrInitialPath As String, pstrFile As String, pstrFilter As String, pstrDefaultExt As String) As String
    46.         Dim typFileName As OPENFILENAME
    47.        
    48.         typFileName = GetStructure(pstrInitialPath, pstrFile, pstrFilter, pstrDefaultExt, feSaveAs)
    49.         If GetSaveFileName(typFileName) Then ShowSaveAsDialog = Left$(typFileName.lpstrFile, InStr(typFileName.lpstrFile, Chr$(0)) - 1)
    50.     End Function
    51.      
    52.     Private Function GetStructure(pstrPath As String, pstrFile As String, pstrFilter As String, pstrDefaultExt As String, penFlags As FlagsEnum) As OPENFILENAME
    53.         Const OFN_FILEMUSTEXIST = &H1000
    54.         Const OFN_PATHMUSTEXIST = &H800
    55.         Const OFN_HIDEREADONLY = &H4
    56.         Const OFN_LONGNAMES = &H200000
    57.         Const OFN_OVERWRITEPROMPT = &H2
    58.         Const OF_WRITE = &H1
    59.         Const MAX_PATH = 260
    60.         Dim frm As Form
    61.      
    62.         With GetStructure
    63.             .lStructSize = Len(GetStructure)
    64.             ' Get any form's window handle
    65.             For Each frm In Forms
    66.                 Exit For
    67.             Next
    68.             .hwndOwner = frm.hWnd
    69.             Set frm = Nothing
    70.             .hInstance = App.hInstance
    71.             .lpstrFilter = Replace(pstrFilter, "|", Chr(0)) & Chr(0)
    72.             .nMaxFile = MAX_PATH + 1
    73.             .nMaxFileTitle = MAX_PATH + 1
    74.             .lpstrFileTitle = Space(MAX_PATH)
    75.             .lpstrInitialDir = pstrPath
    76.             .lpstrDefExt = pstrDefaultExt
    77.             Select Case penFlags
    78.                 Case feOpen
    79.                     .lpstrTitle = "Open"
    80.                     .lpstrFile = Space(MAX_PATH)
    81.                     .Flags = OFN_FILEMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES
    82.                 Case feSaveAs
    83.                     .lpstrTitle = "Save As"
    84.                     .lpstrFile = pstrFile & Space$(MAX_PATH - Len(pstrFile))
    85.                     .Flags = OFN_PATHMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES + OF_WRITE ' + OFN_OVERWRITEPROMPT
    86.             End Select
    87.         End With
    88.     End Function

    Thanks,

    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Voice recording Test

    I found out that all I needed to do with re-install the audio drivers on my laptop, after that the above code saved microphone input to file.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width