C#调制解调器和AT命令

时间:2012-05-15 03:07:28

标签: c# speech-recognition voice modem at-command

好吧,我的大脑已经缩短了。我正在尝试做的是编写一个程序,允许我打电话给我的电脑,经过这么多次电脑响应。此时我可以与计算机对话并利用计算机语音识别功能。但是,我的电脑没有通过电话接收我的声音作为“麦克风输入”音频源。很可能是因为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>
         * */





    } 



}

4 个答案:

答案 0 :(得分:4)

您无法使用调制解调器(代表MOdulator / DEModulator)。这些设计用于将数字通信转换为模拟,用于传输下行电话线,然后将模拟信号更改回数字。你想要的是语音处理卡。

我最熟悉的是Dialogic,但大约10年前。我做了一个快速搜索,Dialogic Diva 2端口模拟卡就是你想要的东西。您还可以搜索电话板或卡。我看到了一家名为Digium的公司的另一张卡片。

语音处理卡可插入PC主板的PCI插槽。您将模拟电话线插入卡中。通过电路板的API,您可以与电话线进行交互,就好像电脑是电话一样。 10年前你可以检测人声频率,但语音识别还处于起步阶段。您可以通过电话线播放声音文件(“按1进行客户服务”),然后响应按键音(也称为DTMF)进行程序控制。

您可以在PC上编写任何内容,从简单的语音邮件到非常简洁的多线电话系统。我确信Dialogic卡的API功能大幅增加。这就是我接下来要看的地方。调制解调器根本不会做你想做的事。

答案 1 :(得分:2)

手机是调制解调器的答案;它只与其他调制解调器通信。它不支持接听电话并将任何音频传递给程序。

答案 2 :(得分:1)

您所描述的是IVR系统。这是一个link to an article on why most modems will not work with IVR systems。即使您使调制解调器工作,您也需要进行大量的开发工作才能使基本的IVR系统正常工作。 Voxeo有一个free 2 port IVR system for developers called Prophecy。这个IVR系统使用开放的W3C标准,如VoiceXMLCCXML来编程您的语音应用程序,并在其中捆绑了一个体面的语音识别和文本到语音(TTS)。由于您使用的是C#,我建议您查看开源项目VoiceModel,它可以极大地简化使用C#和ASP.NET MVC开发在Prophecy(或任何VoiceXML兼容系统)上运行的语音应用程序。

Prophecy的电话接口是SIP,因此成本将是获得一个VoIP网关,将您的模拟电话线转换为SIP。如果它支持SIP,则另一个答案中提到的F​​XO网关可能有效。 Voxeo支持零售价约为395美元的AudioCodes MP-114 which is a 4 port analog system。你可以在eBay上找到一个用过的东西。他们使用软件VoIP网关来支持Dialogic卡,但结果却是一个支持噩梦,并且在语音识别方面引起了很多问题,所以他们放弃了。您需要相当不错的语音质量才能使语音识别正常工作,这是不使用调制解调器的另一个原因。使用具有模拟输入的VoIP网关正常工作可能具有挑战性,但我使用AudioCodes产品取得了成功。 AudioCodes的另一个优势是它得到了Voxeo的支持,他们的支持是免费且非常好的。

答案 3 :(得分:0)

您需要的是FXO gateway,可让您将POTS信号转换为您的计算机可以使用的信号。您可以在$50-70 range中获得低端消费者设备。