This article is a detailed guide about playing incoming voice on a speaker
in relation with Ozeki VoIP SIP SDK. After reading through this page you
will be fully familiar with all the essential terms concerning playing incoming voice
and what you will need for creating your own solution using Ozeki VoIP SIP SDK.
VoIP communication is essentially based on voice and therefore audio data. The analog voice
is digitized and sent as an audio stream to the remote computer where it is played
as a decoded voice through the speaker or a headset.
Figure 1 - VoIP speaker handling
The following program code uses the background support of Ozeki VoIP SIP SDK, therefore
you will need to download and install the SDK before starting to use the code. You will also
need to have Visual Studio 2010 and .NET Framework installed on your computer as
the code below is written in C# programming language.
Using the speaker for playing incoming voice
The speaker is an output device that is modeled in Ozeki VoIP SIP SDK
with a MediaHandler object called Speaker. This object needs to be initialized for
being able to use the speaker for playing any audio data be its source a voice call,
a text to speech machine speaking or an audio file.
The speaker is initialized during its declaration (Code 1) and it can be used during any
further calls or audio playing. You won't need to make more than one instances of
the Speaker later on.
Speaker speaker = Speaker.GetDefaultDevice();
Code 1 - The initialization of the speaker
You also need a MediaConnector object to connect the proper media handler object together.
In case of the speaker, when an incoming call is accepted you need to connect the
PhoneCallAudioReceiver object to the speaker. The order is important.
Code 2 shows the code snippet for an accepted incoming call when the speaker is started and
connected to the receiver. The speaker can be turned only by only calling the Start() method.
Yes, it is that simple.
Code 2 - The code that runs in case of an accepted call
When you start a call, the call status is also set to InCall, so the same code
will run as in case of an accepted incoming call.
When the call is ended, either by the local or by the remote party, the call status
changes to Completed, and the code shown in Code 3 will run. This code
snippet stops the peripheral devices and disconnects them from the MediaHandlers.
Code 3 - The code that runs in the case when the call has been ended
The speaker can also be used when playing an audio file or in text to speech conversion
for playing the machine voice. In these cases the MediaConnector connects the proper
handlers (WaveStreamPlayer, TextToSpeech) to the speaker.
This article introduced you the basic knowledge about playing incoming voice on a speaker
and showed how Ozeki VoIP SIP SDK can help you to fulfill your wishes about this topic.
If you have read through this page carefully, you already have all the knowledge you need to start on your own solution.
As you are now familiar with all the terms concerning this topic, now it is time
to take a step further and explore what other extraordinary solution Ozeki VoIP SIP SDK can provide to you.