ATコマンドとNaudio LIBを使用してモデムに音声を送受信しようとしていますが、モデムへの着信音声はうまく機能していますが、 (騒々しい)コマンドとNAudioのlibを使用して音声コールを行います。
何か助けていただければ幸いです。
WaveIn waveSource;
SerialPort portsend = new SerialPort("COM20", 57600, Parity.None , 8 , StopBits.One);
SerialPort portReceived = new SerialPort("COM19", 57600, Parity.None , 8 , StopBits.One);
WaveOut waveOut = new WaveOut();
WaveFormat format = new WaveFormat(8000, 16,1);
// button call number
private void button1_Click(object sender, EventArgs e)
{
waveSource = new WaveIn(this.Handle);
waveSource.WaveFormat = new WaveFormat(8000,16, 1);
waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveOut.DesiredLatency = 100;
portReceived.Open();
portsend.Open();
portsend.ReadTimeout = SerialPort.InfiniteTimeout;
portsend.WriteLine("ATZ;" + Environment.NewLine);
Thread.Sleep(1000);
portsend.WriteLine("ATD01271698522;" + Environment.NewLine);
portReceived.DataReceived += new SerialDataReceivedEventHandler(modemPort_DataReceived); // received the binary of voice come from the modem
Thread.Sleep(1000);
portsend.Write("AT^DDSETEX=2" + Environment.NewLine);
waveSource.StartRecording();
}
int i = 0;
byte[] buffer;
private BufferedWaveProvider _bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16,1));
void modemPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs args)
{
int x = portReceived.BytesToRead;
buffer = new byte[x];
portReceived.Read(buffer, 0, x);
_bufferedWaveProvider.AddSamples(buffer, 0, x);
if(i==0)
{
waveOut.Init(_bufferedWaveProvider);
}
waveOut.Play();
++i;
}
private void button2_Click(object sender, EventArgs e)
{
portsend.Close();
portReceived.Close();
}
void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
portReceived.Write(e.Buffer, 0, e.BytesRecorded); // send the voice from mic to the modem
}
詳細情報を追加できますか?あなたの問題は何ですか ?例外はありますか? – Thomas