calina.stoica 0 Newbie Poster

I have to do an application in C# to call from a modem a phone number and sending SMS.I managed to do the part for dialing and sending SMS using AT commands, and now I have to inject voice when the somebody answers the call.I wrote separately the application for converting text to voice in C# but i don't know how to integrate both of the applications(that for sending SMS and dialing with the text to voice application).I mean...how do i have to write the entire code in order to hear a voice message when the call is answered?My program just dials a phone number and send SMS and I do not know how to test if the call is answered , or if the line is busy.

Thank you...I hope somebody can help me with this project.

I will copy my code here :

using System;
using System.Collections.Generic;
using System.Text;
using System;
using System.IO.Ports;
using System.Threading;
using System.Speech.Synthesis;
using System.Collections.ObjectModel;

public class PortChat
{
   // static bool _continue;
    static SerialPort _serialPort;

    public static void Main()
    {

        //string message;
        StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
        // Create a new SerialPort object with default settings.
        _serialPort = new SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort.PortName = SetPortName(_serialPort.PortName);
        _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
        _serialPort.Parity = SetPortParity(_serialPort.Parity);
        _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
        _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
        _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);

        // Set the read/write timeouts
        _serialPort.ReadTimeout = 500;
        _serialPort.WriteTimeout = 500;

        _serialPort.Open();

        // readThread.Start();


        string phonenr = "";
        string mesaj;
        if (!_serialPort.IsOpen)
        {
            _serialPort.Open();
        }
        _serialPort.WriteLine("AT\r");

        {
            Console.WriteLine("Enter the phone number:", phonenr);
            phonenr = Console.ReadLine();
            _serialPort.WriteLine("ATD" + phonenr + ";" + "\r");            
            Console.WriteLine("Ring...");
            Thread.Sleep(1000);                               
            Speak(1);
            Console.WriteLine("Enter the message:");
            mesaj= Console.ReadLine();
            _serialPort.WriteLine("AT+CMGF=1\r");
            _serialPort.WriteLine("AT+CMGS=\"" + phonenr + "\"\r");
            _serialPort.WriteLine(mesaj + '\x001a');
             Thread.Sleep(500);
             Console.WriteLine("Message sent...");     
            _serialPort.DiscardInBuffer();
            _serialPort.DiscardOutBuffer();
            _serialPort.Close();


            _serialPort.Close();

            Console.ReadLine();
        }
    }


    static void Speak(int voiceIdx)
    {
        string text = "";
        SpeechSynthesizer syn = new SpeechSynthesizer();
        ReadOnlyCollection<InstalledVoice> voices = syn.GetInstalledVoices();
        if (voiceIdx < 0 || voiceIdx >= voices.Count)
        {
            Console.WriteLine("voice index out of range from [0-{0}]", voices.Count);
            return;
        }

        syn.SelectVoice(voices[voiceIdx].VoiceInfo.Name);

//tranforms the following given text in voice
        syn.Speak("the address is : constitution street number 69");

// here you can enter the text to be transformed in voice

        Console.WriteLine("Enter the text:");
        text = Console.ReadLine();
        syn.Speak(text);
    }



    static void ListVoice()
    {
        SpeechSynthesizer syn = new SpeechSynthesizer();
        ReadOnlyCollection<InstalledVoice> voices = syn.GetInstalledVoices();
        foreach (InstalledVoice voice in voices)
        {
            Console.WriteLine(voice.VoiceInfo.Description);
        }
    }



    public static string SetPortName(string defaultPortName)
    {
        string portName;

        Console.WriteLine("Available Ports:");
        foreach (string s in SerialPort.GetPortNames())
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("COM port({0}): ", defaultPortName);
        portName = Console.ReadLine();

        if (portName == "")
        {
            portName = defaultPortName;
        }
        return portName;
    }

    public static int SetPortBaudRate(int defaultPortBaudRate)
    {
        string baudRate;

        Console.Write("Baud Rate({0}): ", defaultPortBaudRate);
        baudRate = Console.ReadLine();

        if (baudRate == "")
        {
            baudRate = defaultPortBaudRate.ToString();
        }

        return int.Parse(baudRate);
    }

    public static Parity SetPortParity(Parity defaultPortParity)
    {
        string parity;

        Console.WriteLine("Available Parity options:");
        foreach (string s in Enum.GetNames(typeof(Parity)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Parity({0}):", defaultPortParity.ToString());
        parity = Console.ReadLine();

        if (parity == "")
        {
            parity = defaultPortParity.ToString();
        }

        return (Parity)Enum.Parse(typeof(Parity), parity);
    }

    public static int SetPortDataBits(int defaultPortDataBits)
    {
        string dataBits;

        Console.Write("Data Bits({0}): ", defaultPortDataBits);
        dataBits = Console.ReadLine();

        if (dataBits == "")
        {
            dataBits = defaultPortDataBits.ToString();
        }

        return int.Parse(dataBits);
    }

    public static StopBits SetPortStopBits(StopBits defaultPortStopBits)
    {
        string stopBits;

        Console.WriteLine("Available Stop Bits options:");
        foreach (string s in Enum.GetNames(typeof(StopBits)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString());
        stopBits = Console.ReadLine();

        if (stopBits == "")
        {
            stopBits = defaultPortStopBits.ToString();
        }

        return (StopBits)Enum.Parse(typeof(StopBits), stopBits);
    }

    public static Handshake SetPortHandshake(Handshake defaultPortHandshake)
    {
        string handshake;

        Console.WriteLine("Available Handshake options:");
        foreach (string s in Enum.GetNames(typeof(Handshake)))
        {
            Console.WriteLine("   {0}", s);
        }

        Console.Write("Stop Bits({0}):", defaultPortHandshake.ToString());
        handshake = Console.ReadLine();

        if (handshake == "")
        {
            handshake = defaultPortHandshake.ToString();
        }

        return (Handshake)Enum.Parse(typeof(Handshake), handshake);
    }
}

Calina