Alright, my brain has shorted out on me. What I’m trying to do is write a program that allows me to call my computer, after so many rings the computer answers. At this point I would be able to speak to my computer and utilize the computers voice recognition abilities. However, my computer is not receiving my voice via the telephone as a “mic in” audio source. More than likely it is because the COM4 port is what the modem is using as its relay source.
Currently, I can place a phone call from my computer and receive a phone call from my computer. The computer is currently acting as a glorified telephone. Two users can call one another back and forth but the PC just sits there like a third person on an awkward date. I’m wanting the computer to take a more active role in listening to the caller.
Regardless, I cannot seem to hammer out the code that would allow me to get the computer to listen to the callers voice. I’m just breaking the ice on the AT commands so please go gentle with me.
Below is the code from from1. Any assistance would be great. Thank you!
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>
* */
}
}
What you are describing is an IVR system. Here is a link to an article on why most modems will not work with IVR systems. Even if you got the modem to work you have a lot of development effort to get a basic IVR system to work. Voxeo has a free 2 port IVR system for developers called Prophecy. This IVR system uses open W3C standards like VoiceXML and CCXML to program your voice application and has a decent speech recognition and text-to-speech (TTS) bundled in it. Since you are using C# I would recommend looking at the open-source project VoiceModel which greatly simplifies developing voice applications that will run on Prophecy (or any VoiceXML compatible system) using C# and ASP.NET MVC.
Prophecy’s telephony interface is SIP, so the cost will be getting a VoIP gateway that will translate your analog telephone line to SIP. The FXO gateway mentioned in another answer may work if it supports SIP. Voxeo supports AudioCodes MP-114 which is a 4 port analog system that retails for about $395. You may be able to find a used one on eBay for less. They use to support Dialogic cards with a software VoIP Gateway but it turned out to be a support nightmare and caused a lot of issues with speech recognition so they dropped it. You need pretty decent voice quality to get speech recognition to work correctly which is another reason not to use a modem. It can be challenging getting a VoIP gateway to work correctly that has analog input but I have had success using the AudioCodes product. The other advantage to AudioCodes is that it is supported by Voxeo and their support is free and excellent.