在 MS Access 中录制和播放音频

发布于 2024-10-28 09:11:37 字数 740 浏览 1 评论 0原文

我一直在寻找高处和低处,并处于绝望的边缘。我想要完成的是简单地从麦克风录制音频,将其保存到文件中,然后播放。我尝试过的事情:

就像我说的,我对任何可以使用任何人能想到的可怕技巧实现自动化的事情都持开放态度。有什么建议吗? 来吧,你可以再次拯救我......:-)

I have been searching high and low and am at the point of desperation. What I am trying to accomplish is to simply record audio from the microphone, save it to a file and then play it back. Things I have tried:

Like I said, I am open to about anything that I can automate using any terrible tricks anyone can think of. Any suggestions? Come on SO, you can save me again... :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無心 2024-11-04 09:11:37

我知道这是一篇旧文章,但在寻找使用 vba 录制音频的解决方案时,我多次登陆此处。我终于在 http://www.vbarchiv.net 上找到了解决方案,我想分享一下:
将其放入模块中,将其命名为 sndmodule:

Option Compare Database
Option Explicit

REM found at http://www.vbarchiv.net

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

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 Enum BitsPerSec
  Bits16 = 16
  Bits8 = 8
End Enum

Public Enum SampelsPerSec
  Sampels8000 = 8000
  Sampels11025 = 11025
  Sampels12000 = 12000
  Sampels16000 = 16000
  Sampels22050 = 22050
  Sampels24000 = 24000
  Sampels32000 = 32000
  Sampels44100 = 44100
  Sampels48000 = 48000
End Enum

Public Enum Channels
  Mono = 1
  Stereo = 2
End Enum

Public Sub play(file As String)
  Dim wavefile
  wavefile = file
  Call sndPlaySound(wavefile, SND_ASYNC Or SND_FILENAME)
End Sub


Public Sub StartRecord(ByVal BPS As BitsPerSec, _
  ByVal SPS As SampelsPerSec, ByVal Mode As Channels)

  Dim retStr As String
  Dim cBack As Long
  Dim BytesPerSec As Long

  retStr = Space$(128)
  BytesPerSec = (Mode * BPS * SPS) / 8
  mciSendString "open new type waveaudio alias capture", retStr, 128, cBack
  mciSendString "set capture time format milliseconds" & _
    " bitspersample " & CStr(BPS) & _
    " samplespersec " & CStr(SPS) & _
    " channels " & CStr(Mode) & _
    " bytespersec " & CStr(BytesPerSec) & _
    " alignment 4", retStr, 128, cBack
  mciSendString "record capture", retStr, 128, cBack
End Sub

Public Sub SaveRecord(strFile)
  Dim retStr As String
  Dim TempName As String
  Dim cBack As Long
  Dim fs, F

  TempName = strFile 'Left$(strFile, 3) & "Temp.wav"
  retStr = Space$(128)
  mciSendString "stop capture", retStr, 128, cBack
  mciSendString "save capture " & TempName, retStr, 128, cBack
  mciSendString "close capture", retStr, 128, cBack

End Sub

在代码中,您可以像这样使用它:

Private Sub StartRecord_Click()
  sndmodule.StartRecord Bits16, Sampels32000, Mono
End Sub

Private Sub EndRecord_Click()
  sndmodule.SaveRecord "C:\Users\Johanness\Downloads\test.wav"
End Sub

Private Sub Play_Click()
  sndmodule.play "C:\Users\Johanness\Downloads\test.wav"
End Sub

I know this is an old post, but I landed here several times in my search for a solution to record audio with vba. I finally found a solution on http://www.vbarchiv.net I would like to share:
Put this in a module, lets name it sndmodule:

Option Compare Database
Option Explicit

REM found at http://www.vbarchiv.net

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

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 Enum BitsPerSec
  Bits16 = 16
  Bits8 = 8
End Enum

Public Enum SampelsPerSec
  Sampels8000 = 8000
  Sampels11025 = 11025
  Sampels12000 = 12000
  Sampels16000 = 16000
  Sampels22050 = 22050
  Sampels24000 = 24000
  Sampels32000 = 32000
  Sampels44100 = 44100
  Sampels48000 = 48000
End Enum

Public Enum Channels
  Mono = 1
  Stereo = 2
End Enum

Public Sub play(file As String)
  Dim wavefile
  wavefile = file
  Call sndPlaySound(wavefile, SND_ASYNC Or SND_FILENAME)
End Sub


Public Sub StartRecord(ByVal BPS As BitsPerSec, _
  ByVal SPS As SampelsPerSec, ByVal Mode As Channels)

  Dim retStr As String
  Dim cBack As Long
  Dim BytesPerSec As Long

  retStr = Space$(128)
  BytesPerSec = (Mode * BPS * SPS) / 8
  mciSendString "open new type waveaudio alias capture", retStr, 128, cBack
  mciSendString "set capture time format milliseconds" & _
    " bitspersample " & CStr(BPS) & _
    " samplespersec " & CStr(SPS) & _
    " channels " & CStr(Mode) & _
    " bytespersec " & CStr(BytesPerSec) & _
    " alignment 4", retStr, 128, cBack
  mciSendString "record capture", retStr, 128, cBack
End Sub

Public Sub SaveRecord(strFile)
  Dim retStr As String
  Dim TempName As String
  Dim cBack As Long
  Dim fs, F

  TempName = strFile 'Left$(strFile, 3) & "Temp.wav"
  retStr = Space$(128)
  mciSendString "stop capture", retStr, 128, cBack
  mciSendString "save capture " & TempName, retStr, 128, cBack
  mciSendString "close capture", retStr, 128, cBack

End Sub

In your code you can use it like this:

Private Sub StartRecord_Click()
  sndmodule.StartRecord Bits16, Sampels32000, Mono
End Sub

Private Sub EndRecord_Click()
  sndmodule.SaveRecord "C:\Users\Johanness\Downloads\test.wav"
End Sub

Private Sub Play_Click()
  sndmodule.play "C:\Users\Johanness\Downloads\test.wav"
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文