DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Elevate your data management. Join a lively chat to learn how streaming data can improve real-time decision-making, and how to reduce costs.

Platform Engineering: Enhance the developer experience, establish secure environments, automate self-service tools, and streamline workflows

Build Cloud resilience. High-profiled cloud failures have shown us one thing – traditional approaches aren't enough. Join the discussion.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Avatar

Jay Hillary

HU

Joined Feb 2015

Stats

Reputation: 0
Pageviews: 6.3K
Articles: 1
Comments: 0
  • Articles

Articles

article thumbnail
How to record voice calls (C#, SIP)
Do you need a couple of lines of codes to implement voice call recording? Just copy and use this code! It really helped me! To share my success, this content is intended to be a short tutorial on how to record SIP voice calls using C#.NET. This guide is recommended for intermediate-level C# developers primarily, since only one complete code is presented instead of explaining its snippets step-by-step. First of all, carry out the following configuration steps to make sure that your system is ready for coding: Create a new project (Visual C# Console Application) in Visual Studio Add the VoIPSDK.dll file to your references - it is available on this website Install a VoIP PBX (allowing you to initiate and accept voice calls) and create a new SIP account for the call recorder The brief description of the code: After the necessary using lines there is a need a softphone and a phone line object, and some further media handler objects to be able to record audio streams into .wav audio files. Thereafter, you need to specify a SIP account for the call recorder (including the data of your PBX). To ensure that the two audio streams will be mixed you need to connect the microphone and the mediaReceiver objects to the mixer. After this you need to connect the mixer to the recorder that will record the mixed audio stream into the file specified by the filename parameter. The rest of the code presents how to save and store a call as .wav file. using System; using Ozeki.Media.MediaHandlers; using Ozeki.VoIP; using Ozeki.VoIP.SDK; namespace Record_Voice_Call { class Program { static ISoftPhone softphone; // softphone object static IPhoneLine phoneLine; // phoneline object static IPhoneCall call; static string caller; static string filename; static Microphone microphone; static Speaker speaker; static PhoneCallAudioSender mediaSender; static PhoneCallAudioReceiver mediaReceiver; static MediaConnector connector; static WaveStreamRecorder recorder; 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 = "100"; var displayName = "100"; var authenticationId = "100"; var registerPassword = "100"; var domainHost = "192.168.114.7"; var domainPort = 5060; var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort); // Send SIP registration request RegisterAccount(account); microphone = Microphone.GetDefaultDevice(); speaker = Speaker.GetDefaultDevice(); mediaSender = new PhoneCallAudioSender(); 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.IncomingCall += softphone_IncomingCall; 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!"); } static void softphone_IncomingCall(object sender, VoIPEventArgs e) { call = e.Item; caller = call.DialInfo.CallerID; call.CallStateChanged += call_CallStateChanged; call.Answer(); } static void call_CallStateChanged(object sender, CallStateChangedArgs e) { Console.WriteLine("Call state: {0}.", e.State); if (e.State == CallState.Answered) SetupDevices(); if (e.State.IsCallEnded()) CloseDevices(); } static void SetupDevices() { microphone.Start(); connector.Connect(microphone, mediaSender); speaker.Start(); connector.Connect(mediaReceiver, speaker); filename = string.Format("{0}-{1}-{2}-{3}.wav", caller, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); // a string to generate file name recorder = new WaveStreamRecorder(filename); // new recorder object connector.Connect(microphone, recorder); // connects the outgoing voice to the recorder connector.Connect(mediaReceiver, recorder); // connects the incoming voice to the recorder mediaSender.AttachToCall(call); mediaReceiver.AttachToCall(call); recorder.Start(); // starts the recording } static void CloseDevices() { recorder.Dispose(); microphone.Dispose(); speaker.Dispose(); mediaReceiver.Detach(); mediaSender.Detach(); connector.Dispose(); } } }
February 2, 2015
· 6,330 Views

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: