Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Capture Voice using DirectSound

Capture Voice using DirectSound

Scheduled Pinned Locked Moved C#
help
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pakFari
    wrote on last edited by
    #1

    Hi, I a trying to capture the voice using direct sound, but it is not working,here is my code can anyone help me, I will be very thankful to him. private void CaptureThread() { MemoryStream inputStream = new MemoryStream(intervalSize); while (button1.Text == "Stop") { bool val=bufferNotifyEvent.WaitOne(); int currentPos; int readPos; captureBuffer.GetCurrentPosition(out currentPos, out readPos); inputStream.Position = 0; captureBuffer.Read(0, inputStream, intervalSize, LockFlag.None); outputBuffer.Write(0, inputStream, intervalSize , LockFlag.None); outputBuffer.Play(0,BufferPlayFlags.Looping); } Stop(); } the above code is the main thread that run to capture the voice, and some initializations are below private void Form1_Load(object sender, System.EventArgs e) { WaveFormat waveFormat; CaptureBufferDescription capBufDesc; BufferPositionNotify[] notifyPositions; bitsPerSample = 8; // 8 bits per sample const int samplesPerSecond = 11025; // 11 KHz const double interval = 1/45f; // Seconds intervalSize = (int) (interval * samplesPerSecond * bitsPerSample / 8); int samplesPerInterval = intervalSize * 8 / bitsPerSample; int bufferSize = intervalSize * 2; captureDevice = new Capture(); waveFormat = new WaveFormat(); waveFormat.BitsPerSample = bitsPerSample; waveFormat.SamplesPerSecond = samplesPerSecond; waveFormat.Channels = 1; waveFormat.AverageBytesPerSecond = bitsPerSample * samplesPerSecond / 8; waveFormat.BlockAlign = (short)(bitsPerSample / 8); waveFormat.FormatTag = WaveFormatTag.Pcm; capBufDesc = new CaptureBufferDescription(); capBufDesc.Format = waveFormat; capBufDesc.BufferBytes = bufferSize; captureBuffer = new CaptureBuffer(capBufDesc, captureDevice); bufferNotify = new Notify(captureBuffer); bufferNotifyEvent = new AutoResetEvent(false); notifyPositions = new BufferPositionNotify[2]; notifyPositions[0] = new BufferPositionNotify(); notifyPositions[0].EventNotifyHandle = bufferNotifyEvent.Handle; notifyPositions[0].Offset = intervalSize - (bitsPerSample / 8); notifyPositions[1] = new BufferPositionNotify(); notifyPositions[1].EventNotifyHandle = bufferNotifyEvent.Handle; notifyPositions[1].Offset = bufferSize - (bitsPerSample / 8); bufferNotify.SetNotificationPositions(notifyPositions); BufferDescription outputBufferDescription; outputDevice = new Device(); outputDevice.SetCooperativeLevel(this, CooperativeLevel.Normal); outputBufferDescription = new BufferDescription(waveFormat); outpu

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups