Click here to Skip to main content
11,415,074 members (76,787 online)
Click here to Skip to main content

Sending and playing microphone audio over network

, 3 Aug 2007
Rate this:
Please Sign up or sign in to vote.
Sending and playing microphone audio over network

Screenshot - view.jpg

Introduction

This example shows you how to receive data from a microphone and stream it over UDP to another computer. The example application can act like a direct phone, if both endpoints listen for data and send microphone data to each other. One would probably suspect that no source code exists for that, but of course it does. I hate those who will do commercial advertising. There is also a second related project what will contain a UDP server that we need to send/receive audio and compress it with g711 codec.Though only UDP is not the best way to transport audio data, RTP is the right way to go. RTP adds quality of service to transported audio, you can see how many packets are lost and can even arrange disordered packets. I will try to add an RTP example soon, so be calm, it's under way. There are some similar example applications, but most of them aren't well commented and missing some parts, so I will try to fill this part.

The package contains:

  • LumiSoft.Media - Audio related API (Included in example app)
  • LumiSoft.Net - UDP server, G711 codec
  • Example Application

Using the code

  • WaveIn - class provides a simple way to receive audio from a microphone.
    Actually all what you need to do is:
    WavIn.Devices - returns all available input devices from where we can get data.
    /// <summary>
    /// Application main class.
    /// </summary>
    public class Test
    {
        private WavIn m_pSoundReceiver = null;
    
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Test()
        {
            // G711 needs 8KHZ 16 bit 1 channel audio, 
            // 400kb buffer gives us 25ms audio frame.
            m_pSoundReceiver = new WavIn(WavIn.Devices[0],8000,16,1,400);
            m_pSoundReceiver.BufferFull += new BufferFullHandler 
                                             (m_pSoundReceiver_BufferFull);
            m_pSoundReceiver.Start();
        }
    
        /// <summary>
        /// This method is called when recording buffer is full 
        /// and we need to process it.
        /// </summary>
        /// <param name="buffer">Recorded data.</param>
        private void m_pSoundReceiver_BufferFull(byte[] buffer)
        {
            // Just store audio data or stream it over the network ... 
        }
    }
    

  • WaveOut - class provides methods for playing out streaming data.
    The only thing you need to do is just call waveoutInstance.Play method.
    In my opinion, the whole example application has been coded well enough, so dig into the code.

    Note: Sound quality depends on network delay jittering, if there will be too big a variance in delays, voice will have holes in it. In addition, UDP packet loss and disordered packets will affect it too.

History

  • 03.08.2006 - Initial release

Links

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Ivar Lumi

Estonia Estonia
No Biography provided

Comments and Discussions

 
QuestionCan I Use This Code In Web Application ? Pin
amr ismail24-Mar-15 23:10
memberamr ismail24-Mar-15 23:10 
QuestionWant Same VB.Net code Pin
adil mazher22-Feb-15 8:23
memberadil mazher22-Feb-15 8:23 
Questionhow to get a stream out of it..?? Pin
Mohammed Owais15-Feb-15 3:48
professionalMohammed Owais15-Feb-15 3:48 
QuestionUsing for Commercial Use Pin
Member 111262592-Oct-14 10:28
memberMember 111262592-Oct-14 10:28 
AnswerRe: Using for Commercial Use Pin
Ivar Lumi2-Oct-14 20:11
memberIvar Lumi2-Oct-14 20:11 
GeneralRe: Using for Commercial Use Pin
Member 111262593-Oct-14 11:10
memberMember 111262593-Oct-14 11:10 
QuestionGreat program! Audio issues however Pin
Blazing Ardor8-Aug-14 5:59
memberBlazing Ardor8-Aug-14 5:59 
AnswerRe: Great program! Audio issues however Pin
Blazing Ardor8-Aug-14 8:28
memberBlazing Ardor8-Aug-14 8:28 
GeneralYou are great! Pin
Zain Ul Abidin22-Jul-14 19:55
memberZain Ul Abidin22-Jul-14 19:55 
QuestionNewbie Help Pin
Member 109132312-Jul-14 13:13
memberMember 109132312-Jul-14 13:13 
AnswerRe: Newbie Help Pin
Member 109132313-Jul-14 12:39
memberMember 109132313-Jul-14 12:39 
QuestionSend voice over the global net Pin
modarD1-Jul-14 21:55
membermodarD1-Jul-14 21:55 
AnswerRe: Send voice over the global net Pin
Ivar Lumi2-Jul-14 6:09
memberIvar Lumi2-Jul-14 6:09 
GeneralRe: Send voice over the global net [modified] Pin
modarD2-Jul-14 7:58
membermodarD2-Jul-14 7:58 
QuestionHow to relay over wifi Pin
Member 109132311-Jul-14 21:16
memberMember 109132311-Jul-14 21:16 
AnswerRe: How to relay over wifi Pin
Member 109132312-Jul-14 18:55
memberMember 109132312-Jul-14 18:55 
QuestionExcellent code Pin
Raúl Emir Gutiérrez López6-Apr-14 8:35
memberRaúl Emir Gutiérrez López6-Apr-14 8:35 
AnswerRe: Excellent code Pin
Ivar Lumi6-Apr-14 20:05
memberIvar Lumi6-Apr-14 20:05 
GeneralMy vote of 5 Pin
Amir Mohammad Nasrollahi10-Aug-13 22:36
professionalAmir Mohammad Nasrollahi10-Aug-13 22:36 
QuestionDevice disconnect = memory leak and crash Pin
Luis Miguel Jacobetty Soares11-Dec-12 12:56
memberLuis Miguel Jacobetty Soares11-Dec-12 12:56 
QuestionMemory leaks Pin
allen3311-May-12 18:51
memberallen3311-May-12 18:51 
Hi, DO you know of any memory leaks in your code?

I get a OutOfMemoryException in my code and I'm not sure why?
AnswerRe: Memory leaks Pin
Ivar Lumi1-May-12 19:49
memberIvar Lumi1-May-12 19:49 
GeneralRe: Memory leaks Pin
Member 77299501-Aug-12 2:15
memberMember 77299501-Aug-12 2:15 
QuestionExample Panasonic TDA100D PBX and I want to get the calls records Pin
medop8214-Dec-11 1:18
membermedop8214-Dec-11 1:18 
QuestionPlease help me? About get CDR from PBX? Pin
medop8214-Dec-11 1:13
membermedop8214-Dec-11 1:13 
QuestionStream to two clients Pin
allen33129-Nov-11 18:37
memberallen33129-Nov-11 18:37 
AnswerRe: Stream to two clients Pin
Ivar Lumi29-Nov-11 20:58
memberIvar Lumi29-Nov-11 20:58 
Questionnewbie question Pin
Member 79558493-Sep-11 20:43
memberMember 79558493-Sep-11 20:43 
AnswerRe: newbie question Pin
Ivar Lumi3-Sep-11 20:45
memberIvar Lumi3-Sep-11 20:45 
GeneralRe: newbie question Pin
Member 79558494-Sep-11 7:09
memberMember 79558494-Sep-11 7:09 
GeneralRe: newbie question Pin
Ivar Lumi4-Sep-11 19:57
memberIvar Lumi4-Sep-11 19:57 
GeneralRe: newbie question Pin
Member 79558494-Sep-11 20:20
memberMember 79558494-Sep-11 20:20 
GeneralRe: newbie question Pin
Ivar Lumi4-Sep-11 20:21
memberIvar Lumi4-Sep-11 20:21 
GeneralRe: newbie question Pin
Member 79558494-Sep-11 20:28
memberMember 79558494-Sep-11 20:28 
GeneralRe: newbie question Pin
Ivar Lumi4-Sep-11 20:37
memberIvar Lumi4-Sep-11 20:37 
GeneralRe: newbie question Pin
Member 795584916-Sep-11 2:24
memberMember 795584916-Sep-11 2:24 
GeneralRe: newbie question Pin
Ivar Lumi16-Sep-11 2:29
memberIvar Lumi16-Sep-11 2:29 
GeneralRe: newbie question Pin
Member 795584916-Sep-11 2:38
memberMember 795584916-Sep-11 2:38 
GeneralRe: newbie question Pin
Ivar Lumi16-Sep-11 2:40
memberIvar Lumi16-Sep-11 2:40 
GeneralRe: newbie question Pin
Member 795584916-Sep-11 5:24
memberMember 795584916-Sep-11 5:24 
GeneralDelay in Audio Pin
allen33117-Apr-11 19:04
memberallen33117-Apr-11 19:04 
GeneralRe: Delay in Audio Pin
Ivar Lumi17-Apr-11 20:01
memberIvar Lumi17-Apr-11 20:01 
GeneralRe: Delay in Audio Pin
Zypper22-Jan-12 4:30
memberZypper22-Jan-12 4:30 
GeneralRe: Delay in Audio Pin
Ivar Lumi22-Jan-12 7:14
memberIvar Lumi22-Jan-12 7:14 
GeneralRe: Delay in Audio Pin
Zypper22-Jan-12 7:57
memberZypper22-Jan-12 7:57 
GeneralRe: Delay in Audio Pin
Ivar Lumi22-Jan-12 20:59
memberIvar Lumi22-Jan-12 20:59 
GeneralRe: Delay in Audio [modified] Pin
Zypper23-Jan-12 9:17
memberZypper23-Jan-12 9:17 
GeneralRe: Delay in Audio Pin
Ivar Lumi23-Jan-12 20:31
memberIvar Lumi23-Jan-12 20:31 
GeneralRe: Delay in Audio Pin
Zypper24-Jan-12 4:53
memberZypper24-Jan-12 4:53 
GeneralRe: Delay in Audio Pin
Ivar Lumi24-Jan-12 5:10
memberIvar Lumi24-Jan-12 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150427.4 | Last Updated 3 Aug 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid