Recording Skype
Written by Harry Fairhead   
Sunday, 12 July 2009
Article Index
Recording Skype
Getting started
Message in a queue
Talking to Skype
Make the call

Make the call

That’s all there is to it. We now have complete “send a message” and “get the response” mechanisms implemented. To see them in action the simplest thing to do is to use it to call the Skype testing service. In the button’s click handler enter the following code:

private void button1_Click(
object sender,EventArgs e)
{
SkypeFirstConnect();
IntPtr result =
SendCommand("CALL echo123");
WaitForSkype("INPROGRESS");
}

If you run the program and click the button you will see the various Skype status message scrolling past and you should successfully place the test call. The WaitForSkype allows the program to continue as soon as the call is actually connected. Of course you need to write some code that handles the possibility that call will fail but this at least gives you the overall principle of how things are done.

call1

You can see the status messages scrolling passed as the call progresses

 

Now that we have the basics implemented most of the rest of what there is to do consists of finding out what commands Skype supports and how to use them. Sometimes you will need to add additional processing to the existing methods. For an example of the sort of powerful things you can do easily, let’s record the incoming side of the call to a file. The command that does this job is the “ALTER CALL called SET OUTPUT destination” command. The problem is that to use it we need the call’s ID which is returned as part of status message during the call. Extracting the ID from the status is fairly easy and we can create a method to do the job:

private string getCallId()
{
string[] items =
skypedata.data.Split(' ');
return items[1];
}

This simply splits the string into separate words separated by spaces and returns the second item (remember the first item is items[0]) which is always the call ID in a call status message). Now all we have to do is to redefine the button’s click event handler:

private void button1_Click(
object sender,EventArgs e)
{
SkypeFirstConnect();
IntPtr result =
SendCommand("CALL echo123");
WaitForSkype("INPROGRESS");
string CallID = getCallId();
string filename = @"""c:\test.wav"" ";
string cmd = "ALTER CALL " + CallID +
" SET_OUTPUT file=" + filename;
result = SendCommand(cmd);
WaitForSkype("FINISHED");
}

Once we know that the call is in progress we get the call ID, construct the text for the command to save the audio output in a file called test.wav and send the command.

When the call is FINISHED you can open the test.wav file and hear the Skype testing service go through its usual script. You can divert the input audio stream in exactly the same way to build your own answering machine or automatic messaging system. If you are going to do something like this then don’t simply use the example program listed here. You need to implement a Skype object complete with asynchronous methods and events and you need to put in lots of error checking and recovery. It’s not difficult but it would have made for example code that was much more difficult to understand. Happy Skypeing.

If you would like the code for this project then register and click on CodeBin.

<ASIN:B000GRUNEU>

<ASIN:032140940X>

<ASIN:159257551X>



Last Updated ( Monday, 27 July 2009 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.