- Introduction
- VoIP Technology
- Ozeki VoIP SDK
- Developers Guide
- Softphone Development
- Basic softphone examples
- Build a softphone
- Register to a SIP PBX
- Ozeki VoIP SIP Softphone
- SIP encryption
- RTP encryption
- Ring a SIP extension
- Make a SIP voice call
- Multiple phone lines
- Voice via microphone
- Receive call via speaker
- Make conference call
- Play mp3 into call
- Use TextToSpeech
- MS Speech Platform 11
- Record voice call
- Accept incoming call
- Reject incoming call
- Bluetooth Headset
- Auto Answer
- Voice Recognition
- Forward incoming calls
- Blind Transfer
- Attended call transfer
- Do not Disturb
- Call holding
- Show message waiting
- Use DTMF signaling
- Work with SIP and SDP
- Work with RTP
- Make video calls
- Video codecs
- Google SpeechToText
- Google TextToSpeech
- Advanced examples
- Sound quality
- Direct calls among clients
- Manage NAT traversal
- Webphone Development
- Voice Recording
- IVR Development
- PBX Development
- Call Center Development
- VoIP CRM Integration
- Alert systems
- IP Camera
- Mobile phones and platforms
- Billing
- Tutorial
- Appendix
- FAQ
Ozeki brings you outstanding
SMS Gateway technology. Use our SMS Server products on Windows,Linux, or Android
C# SMS API
Developers can use our C# SMS API to send SMS from C#.Net. The C# SMS API comes with full source code
PHP SMS API
The ozeki PHP SMS gateway software can be used to send SMS from PHP and to receive SMS usig PHP on your website
SMPP SMS Gateway
SMS service providers use our SMPP gateway solution, that offers a high performance SMPP server and SMPP client gateway with amazing routing capabilities
How to receive voice data from SIP voice call using C# speaker?
![]() |
Download: | sdk-speaker.zip |
This example demonstrates how to get speaker using c#, how to connect
media handlers and attach speaker to call, how to receive and play audio stream
from a call in c#, using Ozeki VoIP SIP SDK.
To fully understand this example, you might have to study the
How to register to a SIP PBX chapter and the
How to ring a SIP extension chapter first.
To use this example, you need to have Ozeki VoIP SIP SDK installed,
and a reference to ozeki.dll should be added to your visual studio project.
What is speaker used for during a SIP voice call? How does it work?
A speaker is an electroacoustic transducer that produces sound in response to an electrical audio signal input. In other words, speakers convert electrical signals into audible signals.
Softphones are using speakers as audio receiver devices for the purpose to play the received voice stream through them. Since the audio voice stream arrives as digital numbers which are representing the quantity's amplitude, a digital-to-analog device automatically converts the received digital voice data to electrical signals, which the speaker can send into the air as sound.
How to access speaker and play audio stream as sound using c#?
Ozeki VoIP SIP SDK provides C# Speaker class for the purpose to create speaker object. With this c# virtual speaker, users are able to reach system speaker and change speaker volume, manage speaker sound. A speaker object is able to be attached to a call with the correct media receiver object, to play the received audio from the call.
Connect speaker to call example in C#
using System; using Ozeki.Media; using Ozeki.VoIP; namespace SDK_Speaker { class Program { static ISoftPhone softphone; // softphone object static IPhoneLine phoneLine; // phoneline object static IPhoneCall call; static Speaker speaker; static MediaConnector connector; static PhoneCallAudioReceiver mediaReceiver; private static void Main(string[] args) { // Create a softphone object with RTP port range 5000-10000 softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000); // SIP account registration data, (supplied by your VoIP service provider) var registrationRequired = true; var userName = "858"; var displayName = "858"; var authenticationId = "858"; var registerPassword = "858"; var domainHost = "192.168.115.100"; var domainPort = 5060; var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort); // Send SIP regitration request RegisterAccount(account); speaker = Speaker.GetDefaultDevice(); mediaReceiver = new PhoneCallAudioReceiver(); connector = new MediaConnector(); // Prevents the termination of the application Console.ReadLine(); } static void RegisterAccount(SIPAccount account) { try { phoneLine = softphone.CreatePhoneLine(account); phoneLine.RegistrationStateChanged += line_RegStateChanged; softphone.RegisterPhoneLine(phoneLine); } catch (Exception ex) { Console.WriteLine("Error during SIP registration: " + ex); } } static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e) { if (e.State == RegState.NotRegistered || e.State == RegState.Error) Console.WriteLine("Registration failed!"); if (e.State == RegState.RegistrationSucceeded) { Console.WriteLine("Registration succeeded - Online!"); CreateCall(); } } private static void CreateCall() { var numberToDial = "853"; call = softphone.CreateCallObject(phoneLine, numberToDial); call.CallStateChanged += call_CallStateChanged; call.Start(); } private static void SetupSpeaker() { connector.Connect(mediaReceiver, speaker); mediaReceiver.AttachToCall(call); speaker.Start(); Console.WriteLine("The speaker is functioning."); } static void call_CallStateChanged(object sender, CallStateChangedArgs e) { Console.WriteLine("Call state: {0}.", e.State); if (e.State == CallState.Answered) SetupSpeaker(); } } }
Communication through the network
When the call has been accepted by the called party, the softphone is ready to receive the voice stream from the source through the UDP network as RTP packages. This example also writes to the console that the speaker has been successfully started.
Step 1: the application notifies the user about the success of starting the speaker
The speaker is functioning.
Step 2: RTP packages are being received from the source (a sample package)
[Stream setup by SDP (frame 28)] 10.. .... = Version: RFC 1889 Version (2) ..0. .... = Padding: False ...0 .... = Extension: False .... 0000 = Contributing source identifiers count: 0 1... .... = Marker: True Payload type: ITU-T G.711 PCMU (0) Sequence number: 7133 [Extended sequence number: 72669] Timestamp: 85000 Synchronization Source identifier: 0x712f7356 (1898935126) Payload: d55555545657545756565455575051575650515557515050...
Related Pages
More information
- How to build a softphone voip sip client
- Register to SIP PBX
- Voip softphone development
- How to encrypt voip sip calls with sip encryption
- How to encrypt voip sip calls with rtp encryption
- How to ring a sip extension csharp example for sip invite
- How to make a sip voice call using csharp
- Voip multiple phone lines
- How to send stream of voice data into call using csharp microphone
- How to make conference voice call using voip sip
- How to play an mp3 file into a voice call using csharp
- How to convert text to speech and play that into a call using csharp
- How to use Microsoft Speech Platform 11 for TTS and STT
- How to record voip sip voice call
- How to accept incoming call using csharp
- How to reject incoming call using csharp
- How to read Headset buttons using Bluetooth
- How to implement auto answer using csharp
- How to recognize incoming voice using speech to text conversion
- Voip forward call
- Voip blind transfer
- Voip attended transfer
- Voip do not disturb
- Voip call hold
- SIP Message Waiting Indication
- Voip DTMF signaling
- How to work with sip and sdp in voip sip calls
- How to work with rtp in voip sip calls
- How to make voip video calls in csharp
- Voip video codec
- Shows how to use SpeechToText Google API
- How to convert Text to Speech using C# and Google