好吧,我的大脑短路了。我正在尝试做的是编写一个程序,允许我在计算机应答之后呼叫我的计算机。在这一点上,我将能够对我的电脑说话并利用电脑的语音识别能力。但是,我的计算机没有通过电话作为“麦克风输入”音频源接收我的声音。很可能是因为调制解调器使用 COM4 端口作为其中继源。
目前,我可以从我的电脑拨打电话并从我的电脑接听电话。计算机目前正在充当美化的电话。两个用户可以来回呼叫对方,但 PC 就像第三个人在尴尬的约会中一样坐在那里。我希望计算机在聆听呼叫者时发挥更积极的作用。
无论如何,我似乎无法敲定出能让我让电脑听来电者声音的代码。我只是在 AT 命令上打破僵局,所以请对我温柔一点。
下面是from1的代码。任何帮助都会很棒。谢谢!
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 System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.IO;
namespace VoiceModem
{
public partial class Form1 : Form
{
byte[] buffer;
public Form1()
{
InitializeComponent();
}
SerialPort modemPort;
int bufferLoc;
string strBuf;
FileStream file;
StreamWriter logfile;
//note to self: the max port speed is listed at 115200
private void btnCALL_Click(object sender, System.EventArgs e)
{
string PHONENUMBER = "ATD=" + this.textBox1.Text + "\r";
//File.Close("raw.txt", FileMode.Create);
//C:\Documents and Settings\Commander\Desktop
file = File.Open("raw.txt", FileMode.Create);
logfile = File.CreateText("log.txt");
buffer = new byte[10 * 1024];
modemPort = new SerialPort("COM4", 112500, Parity.None, 8, StopBits.One);
modemPort.ReadTimeout = SerialPort.InfiniteTimeout;
modemPort.DataReceived += new SerialDataReceivedEventHandler(modemPort_DataReceived);
modemPort.Open();
modemPort.Write("AT\r"); //OK
modemPort.Write("ATA\r"); //ANSWERING IN VOICE MODE *** NO CARRIER
Thread.Sleep(500);
modemPort.Write("AT+FCLASS=8\r"); ///this should be voice here
Thread.Sleep(500);
modemPort.Write(PHONENUMBER); //DIAL number that D equals
// modemPort.Write("ATH\r"); //HANG UP IN VOICE MODE //ERROR
//modemPort.Write("AT+VSM=1\r");
// modemPort.Write("AT+VTX\r"); //VOICE TRANSMIT MODE //ERROR
// modemPort.Write("AT+VLS=5\r");
Thread.Sleep(500);
modemPort.Write("AT+VRX\r"); //VOICE RECEIVE MODE
Thread.Sleep(500);
modemPort.Write("AT+VLS=3+RX\r");
//VLS
//0 - Telephone Line Select (Go on hook)
//2 - Speakers
//3 - Microphone
//4 - Telephone Line Select + Samples routed to/from Speakers/Mic in TX/RX modes
//6 - Speakerphone
}
private void button1_Click(object sender, System.EventArgs e)
{
//C:\Documents and Settings\Commander\Desktop
file = File.Open("raw.txt", FileMode.Create);
logfile = File.CreateText("log.txt");
buffer = new byte[10*1024];
modemPort = new SerialPort("COM4",112500, Parity.None, 8,StopBits.One);
modemPort.ReadTimeout = SerialPort.InfiniteTimeout;
modemPort.DataReceived+= new SerialDataReceivedEventHandler(modemPort_DataReceived);
modemPort.Open();
modemPort.Write("AT\r"); //OK
//modemPort.Write("ATA\r"); //ANSWERING IN VOICE MODE *** NO CARRIER
modemPort.Write("AT+FCLASS=8\r");
// "ATD=6022626151;\r"
//modemPort.Write(this.textBox1.Text);
//ATD4412345679;
//Dmn ATDmn will dial a phone number where m is the modifier: L, W, ,, ;, @, or S.
//It will dial the telephone number n.
// string str = "Hello " + userName + ". Today is " + date + ".";
string PHONENUMBER = "ATD=" + this.textBox1.Text + "\r";
Thread.Sleep(500);
modemPort.Write(PHONENUMBER); //DIAL number that D equals
Thread.Sleep(500);
modemPort.Write("ATH\r"); //HANG UP IN VOICE MODE //ERROR
//modemPort.Write("AT+VSM=1\r");
Thread.Sleep(500);
modemPort.Write("AT+VLS=?\r");
Thread.Sleep(500);
modemPort.Write("AT+VTX\r"); //VOICE TRANSMIT MODE //ERROR
//modemPort.Write("AT+VLS=1\r");
Thread.Sleep(500);
buffer = new byte[10*1024];
modemPort.Write("AT+VRX\r"); //VOICE RECEIVE MODE
//modemPort.Write("AT+VRX\r");
}
void modemPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs args)
{
int x = modemPort.BytesToRead;
modemPort.Read(buffer,0,x);
file.Write(buffer,0,x);
logfile.WriteLine(x.ToString()+args.EventType.ToString());
}
private void button2_Click(object sender, System.EventArgs e)
{
modemPort.Close();
file.Close();
logfile.Close();
}
private void button3_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
//Form2.show();
}
private void button4_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Text = System.IO.File.ReadAllText("raw.txt");
}
private void button5_Click(object sender, System.EventArgs e)
{
this.richTextBox2.Text = System.IO.File.ReadAllText("log.txt");
}
private void NUMBER1_Click(object sender, System.EventArgs e)
{
//tBox1.Text += "a";
this.textBox1.Text += "1";
}
private void NUMBER2_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "2";
}
private void NUMBER3_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "3";
}
private void NUMBER4_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "4";
}
private void NUMBER5_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "5";
}
private void NUMBER6_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "6";
}
private void NUMBER7_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "7";
}
private void NUMBER8_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "8";
}
private void NUMBER9_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "9";
}
private void NUMBER0_Click(object sender, System.EventArgs e)
{
this.textBox1.Text += "0";
}
private void btnREDIAL_Click(object sender, System.EventArgs e)
{
buffer = new byte[10 * 1024];
modemPort = new SerialPort("COM4", 112500, Parity.None, 8, StopBits.One);
modemPort.ReadTimeout = SerialPort.InfiniteTimeout;
modemPort.DataReceived += new SerialDataReceivedEventHandler(modemPort_DataReceived);
modemPort.Open();
modemPort.Write("AT\r"); //OK
modemPort.Write("ATDL\r"); //OK
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.textBox1.Focus();
}
private void btnANSWER_Click(object sender, System.EventArgs e)
{
//C:\Documents and Settings\Commander\Desktop
file = File.Open("raw.txt", FileMode.Create);
logfile = File.CreateText("log.txt");
buffer = new byte[10 * 1024];
modemPort = new SerialPort("COM4", 112500, Parity.None, 8, StopBits.One);
modemPort.ReadTimeout = SerialPort.InfiniteTimeout;
modemPort.DataReceived += new SerialDataReceivedEventHandler(modemPort_DataReceived);
modemPort.Open();
modemPort.Write("AT\r"); //OK
Thread.Sleep(500);
modemPort.Write("ATA\r"); //ANSWERING then gives beep-boops
Thread.Sleep(500);
//modemPort.Write("AT+VLS=1");
//modemPort.Write("AT+FCLASS=8\r");
// string str = "Hello " + userName + ". Today is " + date + ".";
// string PHONENUMBER = "ATD=" + this.textBox1.Text + "\r";
// modemPort.Write(PHONENUMBER); //DIAL number that D equals
//modemPort.Write("ATH\r"); //HANG UP IN VOICE MODE //ERROR
//modemPort.Write("AT+VSM=1\r");
//modemPort.Write("AT+++\r");// disconnects data mode to allow for voice mode
//voice mode is activated using ata
modemPort.Write("AT+VRX\r");
//modemPort.Write("AT+VTX\r"); //VOICE TRANSMIT MODE //ERROR
//modemPort.Write("AT+VLS=1\r");
// modemPort.Write("ATH\r"); //HANG UP IN VOICE MODE //ERROR
//modemPort.Write("AT+VRX\r");
//modemPort.Write("ATA\r"); //answer the call
}
private void btnHANGUP_Click(object sender, System.EventArgs e)
{
modemPort.Close();
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
//int iPhone = 7065551212;
//string strPhone = string.Format("{0:(###) ###-####}", iPhone);
// this.textBox1.Mask = "(999) 000-0000";
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
// Reset the colors and selection of the TextBox after focus is lost.
string x = textBox1.Text;
double y = Double.Parse(x);
textBox1.Text = String.Format("{0:(###) ###-####}", y);
textBox1.ForeColor = Color.Black;
textBox1.BackColor = Color.White;
textBox1.Select(0, 0);
}
/*
* ACTIVE PROFILE:
E0 L1 M1 Q0 T V1 X4 &C1 &D2 &G0 &P0
S00:000 S01:000 S02:043 S03:013 S04:010 S05:008 S06:002 S07:060 S08:002
S10:014 S12:050 S29:070
STORED PROFILE 0:
E0 L1 M1 Q0 T V1 X4 &C1 &D2 &G0 &P0
S00:000 S02:043 S06:002 S07:050 S08:002 S10:014 S12:050 S29:070
*
*
* DIAG <2A4D3263 0=10>
DIAG <2A4D3263 1=0>
DIAG <2A4D3263 60=1>
* */
}
}