无法使用点网记录Wav文件 [英] Unable to record Wav File using dot net

查看:53
本文介绍了无法使用点网记录Wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将耳机(标准输出)上播放的声音录制到wav文件中.我正在尝试录制各种来源的音频. MP3文件.麦克风和Windows事件.

我正在使用MSDN中提供的代码示例,但我的wav文件始终只有1KB.这是我正在使用的代码...谁能告诉我我要去哪里错了?


带2个按钮的表单代码:

I'm trying to record the sound that is playing on my headphones (standard out) to a wav file. I'm trying to record the audio from various sources. MP3 files. Microphone and windows events.

I'm using the code examples given in MSDN but my wav file is always only 1KB. Here is the code I am working from... can anyone tell where I'm going wrong?


Form code with 2 buttons:

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        Me.Label1.Text = "recording"
        SoundCapture.StartRecording()
    End Sub

    Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        Me.Label1.Text = "idle"
        SoundCapture.SaveRecording("c:\test.wav")
    End Sub


用于处理记录的类代码:

Class Code to handle recording:

Imports System.Runtime.InteropServices
Imports System.Text
Public Class SoundCapture
    <DllImport("winmm.dll")> _
    Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
    End Function

    Dim i As Integer
    Public Sub StartRecording()
        i = mciSendString("open new type waveaudio alias capture", Nothing, 0, 0)
        Console.WriteLine(i)
        i = mciSendString("record capture", Nothing, 0, 0)
        Console.WriteLine(i)
    End Sub
    Public Sub SaveRecording(fileName As String)
        i = mciSendString("save capture " + fileName, Nothing, 0, 0)
        i = mciSendString("close capture", Nothing, 0, 0)
    End Sub
End Class





推荐答案

我不知道.但是也许您应该尝试使用该线程中的代码.

I don't know. But maybe you should try the code in this thread.

但是,请注意,在我的答复中有关也在控制面板,音频/录音中"的部分,我不得不将麦克风设置为默认的录音设备,并禁用Realtek的立体声混音".因为您可能需要使用控制面板"进行设置 使其正常工作.

However note the part in a response of mine about "Also in Control Panel, Audio/recording, I had to set my microphone as the default recording device and disable my realtek "stereo mix" as you may have to set something using Control Panel for this to work correctly.


这篇关于无法使用点网记录Wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆