Making a call
Programs and scripts can use the Component API in either 'blocking' or 'non-blocking' mode.
The following examples use 'blocking' mode because this is the simplest. For more complex scripts
and applications 'non-blocking' mode can make it easier to create programs that can cope with unforeseen
sequences of events or errors.
See the section 'Handling multiple calls' for more information.
We can create the DivaCall object directly here because we are handling only one call;
if we were creating more than one DivaCall object then we would have to use
DivaSystem and
DivaInstance and the
DivaCall
objects would be created using the
CreateCall method of DivaInstance.
To make a call
The following code makes a call with
Connect
, plays the wave file with
SendVoiceFile
when the call is answered and
Disconnects.
VB example: (Show C# version)
Imports DivaSDKlib
...
Dim res As DivaResultCodes
Dim num As String = "1234567"
' Single call program, so create DivaCall directly
Dim CallObj As New DivaCall()
res = CallObj.Connect(num)
If res = DivaResultCodes.DivaResultSuccess Then
res = CallObj.SendVoiceFile("defaultgreeting.wav")
' Using synchronous (blocking) mode so next line is executed after
' completion of previous operation
res = CallObj.Disconnect
End If
C# example: (Show VB version)
using DIVASDKLib;
...
DivaResultCodes res ;
String num = "384720";
// Single call program, so create DivaCall directly
DivaCall CallObj = new DivaCall();
res = CallObj.Connect(num, DivaCallTypes.DivaCallType_Voice );
if (res == DivaResultCodes.DivaResultSuccess)
{
res = CallObj.SendVoiceFile("defaultgreeting.wav", DivaAudioFmt.DivaAudioAutodetect);
// Using synchronous (blocking) mode so next line is executed after
// completion of previous operation
res = CallObj.Disconnect();
}
To receive a call
The following code waits for a call using
WaitForCall
and records a wave file with
RecordVoiceFile
when a call is received.
VB example: (Show C# version)
Imports DivaSDKlib
...
Dim res As DivaResultCodes
' Single call program, so create DivaCall directly
Dim CallObj As New DivaCall()
' Using synchronous (blocking) mode with 'WaitForCall' rather than Asynchronous 'Listen'
res = CallObj.WaitForCall
If res = DivaResultCodes.DivaResultSuccess Then
res = CallObj.RecordVoiceFile("myfile.wav")
' Using synchronous (blocking) mode so next line is executed after
' completion of previous operation
res = CallObj.Disconnect
End If
C# example: (Show VB version)
using DIVASDKLib;
...
DivaResultCodes res ;
// Single call program, so create DivaCall directly
DivaCall CallObj = new DivaCall();
// Using synchronous (blocking) mode with 'WaitForCall' rather than Asynchronous 'Listen'
res = CallObj.WaitForCall((int)DivaCallTypes.DivaCallType_Voice, "", 0);
if (res == DivaResultCodes.DivaResultSuccess)
{
res = CallObj.RecordVoiceFile("myfile.wav",DivaAudioFmt.DivaAudioWav_PCM_8K8BitMono, 100, 10, "#");
// Using synchronous (blocking) mode so next line is executed after
// completion of previous operation
res = CallObj.Disconnect();
}
Of course, these samples are too simple for real-life use;
for instance, they do not report to you whether they worked or not.
However, they do show how simple it is to use the Diva Component API.