PDA

View Full Version : ضبط کردن صدا ( مشکل ایجاد شده )



seyedVB
یک شنبه 28 تیر 1388, 14:52 عصر
اشکال این کد کجاست که play نمیکنه :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using System.IO;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
CaptureBuffer captureBuffer;
CaptureBufferDescription captureDes = new CaptureBufferDescription();
WaveFormat waveFormat = new WaveFormat();
Capture captureDevice = new Capture();
Device sndDevice;
SecondaryBuffer buffer;
StreamWriter wStream;
StreamReader wReader;
char[] bytes;
char[] bytesRead;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{


captureDes.BufferBytes = 192000;
waveFormat.BitsPerSample = 8;
waveFormat.Channels = 1;
waveFormat.SamplesPerSecond = 22050;
waveFormat.BlockAlign = (short)(waveFormat.Channels * (waveFormat.BitsPerSample/8));
waveFormat.AverageBytesPerSecond = waveFormat.BlockAlign * waveFormat.SamplesPerSecond;
captureDes.Format = waveFormat;
waveFormat.BlockAlign = 1;
captureDes.Format = waveFormat;
captureDes.BufferBytes = 100000;
captureDes.ControlEffects = false;
captureDes.WaveMapped = true;
captureBuffer = new Microsoft.DirectX.DirectSound.CaptureBuffer(captur eDes, captureDevice);
bytes = new char[100000];
bytesRead = new char[100000];
sndDevice = new Device();
sndDevice.SetCooperativeLevel(this, CooperativeLevel.Normal);


}

private void btnPlay_Click(object sender, EventArgs e)
{
wReader = new StreamReader("sap.wav");
while (wReader.EndOfStream == false)
{
wReader.Read(bytesRead, 0, 100000);
}
buffer = new SecondaryBuffer("sap.wav", sndDevice);
buffer.Play(0, BufferPlayFlags.Looping);
}

private void btnStop_Click(object sender, EventArgs e)
{
captureBuffer.Stop();
wStream.Close();
}

private void btnRecord_Click(object sender, EventArgs e)
{
wStream = new StreamWriter("sap.wav");
captureBuffer.Start(true);
for (int i = 0; i < 100000; i++)
{
bytes[i] = (char)captureBuffer.Caps.BufferBytes;
wStream.Write(bytes[i]);
}
}
}
}

Unknownlive
یک شنبه 28 تیر 1388, 18:47 عصر
من نمی دونم مشکل این کد چیه اما می تونی از کامپوننت های موجود با خود VS استفاده کنی کد هاش چند خط کوتاه بیش تر نمی شه اگه اسمش یادم اومد می گم