Hello,
I am a beginner in c #. I have a code that is speaking, the sound output of the computer's sound card. But this code does not allow me to out the sound in a specific external sound card.I have used devicenumber in parameter but the problem is not solved yet.
Has ANYONE can help me improve my code so that it can hear the sound listen an external sound card.
Thank you in advance.
Here is the code: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;
namespace PaGa
{
public partial class StreamingForm : Form{
public StreamingForm()
{
InitializeComponent();
}
///
/// Clean up any resources being used.
///
///
/// The main entry point for the application.
///
//[STAThread]
private PaGa.WaveOutPlayer m_Player;
private PaGa.WaveInRecorder m_Recorder;
private PaGa.FifoStream m_Fifo = new PaGa.FifoStream();
private byte[] m_PlayBuffer;
private byte[] m_RecBuffer;
private void Filler(IntPtr data, int size)
{
if (m_PlayBuffer == null || m_PlayBuffer.Length < size)
m_PlayBuffer = new byte[size];
if (m_Fifo.Length >= size)
m_Fifo.Read(m_PlayBuffer, 0, size);
else
for (int i = 0; i < m_PlayBuffer.Length; i++)
m_PlayBuffer[i] = 0;
System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size);
}
private void DataArrived(IntPtr data, int size)
{
if (m_RecBuffer == null || m_RecBuffer.Length < size)
m_RecBuffer = new byte[size];
System.Runtime.InteropServices.Marshal.Copy(data, m_RecBuffer, 0, size);
m_Fifo.Write(m_RecBuffer, 0, m_RecBuffer.Length);
}
private void Stop()
{
if (m_Player != null)
try
{
m_Player.Dispose();
}
finally
{
m_Player = null;
}
if (m_Recorder != null)
try
{
m_Recorder.Dispose();
}
finally
{
m_Recorder = null;
}
m_Fifo.Flush(); // clear all pending data
}
private void Start()
{
Stop();
try
{
PaGa.WaveFormatt fmt = new PaGa.WaveFormatt(44100, 16, 2);
m_Player = new PaGa.WaveOutPlayer(-1, fmt, 16384, 3, new PaGa.BufferFillEventHandler(Filler));
m_Recorder = new PaGa.WaveInRecorder(-1, fmt, 16384, 3, new PaGa.BufferDoneEventHandler(DataArrived));
//WaveOut outputDevice = new WaveOut();
// waveOut = outputDevice;
// outputDevice.DeviceNumber = _deviceNumber;
}
catch
{
Stop();
throw;
}
}
private void StreamingForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Stop();
}
private void StartButton_Click(object sender, System.EventArgs e)
{
Start();
}
private void StopButton_Click(object sender, System.EventArgs e)
{
Stop();
}
}
}
sawass sawassPosted May 21, 2011, 5:13 PM
if I speak into the microphone of the computer, the speak is out immediately from sound card.
Because I have 3 sound cards, I want
by calling the function "Stream Form () 'in the same project and is not in the same function, the speak is out in particular sound card by specifying in parameter the card where I want to broadcast my message.
I have the same problem as nicole castle but the only difference I want to broadcast a voice message directly.
I hope I don't suit you.
FroglegPosted May 21, 2011, 3:05 AM
sawass sawassPosted May 20, 2011, 6:57 AM
I tried
with device number but this does not solve the problem
. He always reads the sound card of pc
Will you help me please
FroglegPosted May 19, 2011, 2:13 PM
http://www.c-sharpcorner.com/Forums/Thread/122072/playback-a-sound-in-a-specific-device.aspx