Monday, June 19, 2006

I've gotten several questions on this topic so I thought it might be a good thing to show in a blog.  Recording with TAPI 3.1 is actually pretty easy if you are running on Windows XP or better.  TAPI 3.1 provides some simple filename-based methods to dump the conversation into a .WAV file.  If you want to control the file, or stream it somewhere else, it's a bit more difficult and Microsoft provides a decent sample with the platform SDK that does it.

Here's a simple example -- in this scenerio we will create a new outgoing call, connect it and then setup an outgoing stream to play a welcome message:

TapiCall currCall = selectedAddress.CreateCall(numberToDial, LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.AUDIO);
if (currCall != null)
{
   currCall.Connect(false);
   playbackTerminal = currCall.RequestTerminal(TTerminal.FilePlaybackTerminal, TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);
   if (playbackTerminal != null)
   {
      playbackTerminal.MediaPlayList = new string[] { MESSAGE_PROMPT };
      currCall.SelectTerminalOnCall(playbackTerminal);
   }
}

When the call is actually connected, then we will start the playbackTerminal stream and begin recording the conversation - this would typically be done in the TE_CALLSTATE handler:

if (e.State == CALL_STATE.CS_CONNECTED && playbackTerminal != null)
{
   // Start the playback message..
   playbackTerminal.Start();
  
// Begin recording the conversation - may be half-duplex..
   RecordConversation("RecordedMessage.wav");
}
else if (e.State == CALL_STATE.CS_DISCONNECTED)
{
   // Stop recording when the call terminates.
   if (recordTerminal != null)
      recordTerminal.Stop();

   recordTerminal = null;
   playbackTerminal = null;
}

The code for recording the conversation is pretty simple as well, given a filename, just get a recording terminal and assign it.  TAPI will take care of creating the file and writing contents into it.

private void RecordConversation(string fileName)
{
   // This code only works on XP or better (TAPI 3.1).
   if (currCall != null)
   {
      recordTerminal = currCall.RequestTerminal(TTerminal.FileRecordingTerminal, TAPIMEDIATYPES.MULTITRACK, TERMINAL_DIRECTION.TD_RENDER);
      if (recordTerminal != null)
      {
         recordTerminal.RecordFileName = fileName;
         currCall.SelectTerminalOnCall(recordTerminal);
         recordTerminal.Start();
      }
   }
}

Finis.

posted on 6/19/2006 9:41:45 AM (Central Standard Time, UTC-06:00)  #   

Related Posts:
Demos + Labs for the WPF+LINQ class this week
Implementing Drag/Drop with TabControl
ATAPI assembly updated!
Adding ILDasm to VS.NET with a keyboard shortcut
Creating Extensible Applications with MAF (System.AddIn)
Creating popup windows in XBAP applications

Tracked by:
"her first audition" (her first audition) [Trackback]
"gamblers" (gamblers) [Trackback]
"buyphentermineprozac" (buyphentermineprozac) [Trackback]
"annuncio affitti isernia" (annuncio affitti isernia) [Trackback]
"paul posey tallahassee florida" (paul posey tallahassee florida) [Trackback]
"sauna mista milano" (sauna mista milano) [Trackback]
"una sera nel parco" (una sera nel parco) [Trackback]
"Executive Office Furniture" (Executive Office Furniture) [Trackback]
"georgia bulldog" (georgia bulldog) [Trackback]
"pacifica armoire" (pacifica armoire) [Trackback]
"vecchie mature grasse donne" (vecchie mature grasse donne) [Trackback]
"cd organizers" (cd organizers) [Trackback]
"gadget audi" (gadget audi) [Trackback]
"female body builders posing" (female body builders posing) [Trackback]
"cameriere in autoreggenti" (cameriere in autoreggenti) [Trackback]
"Sports Betting Rss Feed" (Sports Betting Rss Feed) [Trackback]
"albuquerque respiratory jobs va medical center" (albuquerque respiratory jobs v... [Trackback]
"tiaras and headpieces" (tiaras and headpieces) [Trackback]
"used kountry aire camper trailer" (used kountry aire camper trailer) [Trackback]
"bollente fantastico nubile" (bollente fantastico nubile) [Trackback]
"invisibile pulcino dildo" (invisibile pulcino dildo) [Trackback]
"bitches getting fuck" (bitches getting fuck) [Trackback]
"fotografico" (fotografico) [Trackback]
"how to make a sword" (how to make a sword) [Trackback]
"sms gratis cellulare" (sms gratis cellulare) [Trackback]
"teen dating forum" (teen dating forum) [Trackback]
"west virginia dui law" (west virginia dui law) [Trackback]
"poor girls for marriage" (poor girls for marriage) [Trackback]
"viaggi abruzzo" (viaggi abruzzo) [Trackback]
"4tsq8" (4tsq8) [Trackback]
"y37bl" (y37bl) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"nk4ye" (nk4ye) [Trackback]
http://www.walshperformancegroup.com/contact.htm [Trackback]
"Welcome to linuxtld.com!" (Welcome to linuxtld.com!) [Trackback]
"oqxtu" (oqxtu) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"Welcome to linuxtld.com!" (Welcome to linuxtld.com!) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"fp8ll" (fp8ll) [Trackback]
"1k8jd" (1k8jd) [Trackback]
"default parking homes for sale at free815.com" (default parking homes for sale ... [Trackback]
"free815.com" (free815.com) [Trackback]
"nyav.purple-icing.com" (nyav.purple-icing.com) [Trackback]
"meskateboards.com/mesite01.swf" (meskateboards.com/mesite01.swf) [Trackback]
"search the web" (search the web) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"me Skateboards" (me Skateboards) [Trackback]
"d4gug" (d4gug) [Trackback]
"vkaed" (vkaed) [Trackback]
"o7w34" (o7w34) [Trackback]
"ue6ax" (ue6ax) [Trackback]
"purple-icing.com" (purple-icing.com) [Trackback]
"proscenium arch" (proscenium arch) [Trackback]
"jennifer lopez hold you down" (jennifer lopez hold you down) [Trackback]
"skelaxin prices" (skelaxin prices) [Trackback]
"Amitriptyline side effects" (Amitriptyline side effects) [Trackback]
"teens masturbating zipped video" (teens masturbating zipped video) [Trackback]
"FHA LOAN AND FORECLOSURE" (FHA LOAN AND FORECLOSURE) [Trackback]
"search gals" (search gals) [Trackback]
"Care Bear Tapestry" (Care Bear Tapestry) [Trackback]
"art supplies" (art supplies) [Trackback]
"savannah georgia prempro lawyer" (savannah georgia prempro lawyer) [Trackback]
"google satellite images" (google satellite images) [Trackback]
"hookah systems for diving" (hookah systems for diving) [Trackback]
"Boston Ephedra attorneys" (Boston Ephedra attorneys) [Trackback]
"how movies duplication" (how movies duplication) [Trackback]
"sleeping sexy girls fucked" (sleeping sexy girls fucked) [Trackback]
"no credit check credit cards" (no credit check credit cards) [Trackback]
"generic novel activities" (generic novel activities) [Trackback]
"teflon materiale" (teflon materiale) [Trackback]