static void Main(string[] args) { microphone = Microphone.GetDefaultDevice(); speaker = Speaker.GetDefaultDevice(); connector = new MediaConnector(); audioProcessor = new AudioQualityEnhancer(); audioProcessor.NoiseReductionLevel = NoiseReductionLevel.Medium; audioProcessor.SetEchoSource(speaker); connector.Connect(microphone, audioProcessor); connector.Connect(audioProcessor, speaker); microphone.Start(); speaker.Start(); Console.ReadLine(); }
static void Main(string[] args) { microphone = Microphone.GetDefaultDevice(); speaker = Speaker.GetDefaultDevice(); connector = new MediaConnector(); audioProcessor = new AudioQualityEnhancer(); audioProcessor.AcousticEchoCancellation = true; // acoustic echo cancellation is enabled audioProcessor.SetEchoSource(speaker); // sets the speaker to be the source of the echo connector.Connect(microphone, audioProcessor); // voice data is being sent through the enhancer connector.Connect(audioProcessor, speaker); audioProcessor.Start(); microphone.Start(); speaker.Start(); Console.ReadLine(); }
/// <summary> /// Initializes the audio handlers (microphone, speaker, DTMF player etc.). /// </summary> private void InitAudio() { // ----- CREATE ----- // devices Microphone = Microphone.GetDefaultDevice(); Speaker = Speaker.GetDefaultDevice(); // audio processors AudioEnhancer = new AudioQualityEnhancer(); AudioEnhancer.SetEchoSource(Speaker); dtmfPlayer = new DtmfEventWavePlayer(); // ringtones var ringbackStream = LoadRingbackStream(); var ringtoneStream = LoadRingtoneStream(); ringtonePlayer = new WaveStreamPlayback(ringtoneStream, true, false); ringbackPlayer = new WaveStreamPlayback(ringbackStream, true, false); // mixers outgoingDataMixer = new AudioMixerMediaHandler(); speakerMixer = new AudioMixerMediaHandler(); recordDataMixer = new AudioMixerMediaHandler(); // phone handlers phoneCallAudioSender = new PhoneCallAudioSender(); phoneCallAudioReceiver = new PhoneCallAudioReceiver(); // ----- CONNECT ----- // connect outgoing audioConnector.Connect(AudioEnhancer, outgoingDataMixer); audioConnector.Connect(outgoingDataMixer, phoneCallAudioSender); audioConnector.Connect(outgoingDataMixer, recordDataMixer); if (Microphone != null) { Microphone.LevelChanged += (Microphone_LevelChanged); audioConnector.Connect(Microphone, AudioEnhancer); } // connect incoming audioConnector.Connect(phoneCallAudioReceiver, speakerMixer); audioConnector.Connect(phoneCallAudioReceiver, recordDataMixer); audioConnector.Connect(ringtonePlayer, speakerMixer); audioConnector.Connect(ringbackPlayer, speakerMixer); audioConnector.Connect(dtmfPlayer, speakerMixer); if (Speaker != null) { Speaker.LevelChanged += (Speaker_LevelChanged); audioConnector.Connect(speakerMixer, Speaker); } // add to collection Dictionary<string, VoIPMediaHandler> collection = new Dictionary<string, VoIPMediaHandler>(); collection.Add("AudioEnhancer", AudioEnhancer); collection.Add("DTMFPlayer", dtmfPlayer); collection.Add("OutgoingDataMixer", outgoingDataMixer); collection.Add("SpeakerMixer", speakerMixer); collection.Add("PhoneCallAudioSender", phoneCallAudioSender); collection.Add("PhoneCallAudioReceiver", phoneCallAudioReceiver); audioCollection = new MediaHandlerCollection(audioConnector, collection); }
/// <summary> /// Initializes the audio handlers (microphone, speaker, DTMF player etc.). /// </summary> private void InitAudio() { // ----- CREATE ----- // devices Microphone = Microphone.GetDefaultDevice(); Speaker = Speaker.GetDefaultDevice(); // audio processors AudioEnhancer = new AudioQualityEnhancer(); AudioEnhancer.SetEchoSource(Speaker); dtmfPlayer = new DtmfEventWavePlayer(); // ringtones var ringbackStream = LoadRingbackStream(); var ringtoneStream = LoadRingtoneStream(); ringtonePlayer = new WaveStreamPlayback(ringtoneStream, true, false); ringbackPlayer = new WaveStreamPlayback(ringbackStream, true, false); // mixers outgoingDataMixer = new AudioMixerMediaHandler(); speakerMixer = new AudioMixerMediaHandler(); recordDataMixer = new AudioMixerMediaHandler(); // phone handlers phoneCallAudioSender = new PhoneCallAudioSender(); phoneCallAudioReceiver = new PhoneCallAudioReceiver(); // ----- CONNECT ----- // connect outgoing audioConnector.Connect(AudioEnhancer, outgoingDataMixer); audioConnector.Connect(outgoingDataMixer, phoneCallAudioSender); audioConnector.Connect(outgoingDataMixer, recordDataMixer); if (Microphone != null) { Microphone.LevelChanged += (Microphone_LevelChanged); audioConnector.Connect(Microphone, AudioEnhancer); } // connect incoming audioConnector.Connect(phoneCallAudioReceiver, speakerMixer); audioConnector.Connect(phoneCallAudioReceiver, recordDataMixer); audioConnector.Connect(ringtonePlayer, speakerMixer); audioConnector.Connect(ringbackPlayer, speakerMixer); audioConnector.Connect(dtmfPlayer, speakerMixer); if (Speaker != null) { Speaker.LevelChanged += (Speaker_LevelChanged); audioConnector.Connect(speakerMixer, Speaker); } // add to collection Dictionary <string, VoIPMediaHandler> collection = new Dictionary <string, VoIPMediaHandler>(); collection.Add("AudioEnhancer", AudioEnhancer); collection.Add("DTMFPlayer", dtmfPlayer); collection.Add("OutgoingDataMixer", outgoingDataMixer); collection.Add("SpeakerMixer", speakerMixer); collection.Add("PhoneCallAudioSender", phoneCallAudioSender); collection.Add("PhoneCallAudioReceiver", phoneCallAudioReceiver); audioCollection = new MediaHandlerCollection(audioConnector, collection); }
/// <summary> /// Creates a complex phone call listener, built up from microphone, speaker, waverecorder, waveplayer, dtmf and ringtone sounds. /// </summary> /// <returns>The media handler collection that represent the phone call listener.</returns> public MediaHandlerCollection CreateSoftPhoneCallListener() { var phoneCallAudioReceiver = new PhoneCallAudioReceiver(); var phoneCallAudioSender = new PhoneCallAudioSender(); var microphone = Microphone.GetDefaultDevice(); var speaker = Speaker.GetDefaultDevice(); var audioProcessor = new AudioQualityEnhancer(); audioProcessor.SetEchoSource(speaker); // Handles the audio that comes from the PhoneCallListener var outgoingDataMixer = new AudioMixerMediaHandler(); var recordDataMixer = new AudioMixerMediaHandler(); var speakerMixer = new AudioMixerMediaHandler(); var dtmf = new DtmfEventWavePlayer(); var ringtones = new PhoneCallStateWavePlayer( commonWaveFormat, outGoingToneStreams, incomingToneStreams ); if (microphone != null) { mediaConnector.Connect(microphone, audioProcessor); } mediaConnector.Connect(audioProcessor, outgoingDataMixer); mediaConnector.Connect(outgoingDataMixer, phoneCallAudioSender); // No WaveStreamPlayback (see CreateWaveStreamPlayback method) //mediaConnector.Connect(phoneCallAudioReceiver, speaker); mediaConnector.Connect(phoneCallAudioReceiver, speakerMixer); mediaConnector.Connect(dtmf, speakerMixer); mediaConnector.Connect(ringtones, speakerMixer); if (speaker != null) { mediaConnector.Connect(speakerMixer, speaker); } mediaConnector.Connect(phoneCallAudioReceiver, recordDataMixer); mediaConnector.Connect(outgoingDataMixer, recordDataMixer); // No WaveStreamRecorder (see CreateWaveStreamRecorder method) /* * Media Connections: * * +---------------------------------------------------------------+ * | PhoneCall |************** * +---------------------------------------------------------------+ * * * ^^ VV * * * +--------------------+ +----------------------+ +----+ +---------+ * |PhoneCallAudioSender| |PhoneCallAudioReceiver| |DMTF| |Ringtones| * +--------------------+ +----------------------+ +----+ +---------+ * ^^ V V V | * +-----------------+ +---------------+ +------------+ | * |OutgoingDataMixer|----- >> -----|RecordDataMixer| |SpeakerMixer|--<<--/ * +-----------------+ +---------------+ +------------+ * ^^ ^^ V | *+--------------+ +------------------+ +------------------+ | *|AudioProcessor| |WaveStreamPlayback| |WaveStreamRecorder| V *+--------------+ +------------------+ +------------------+ V * ^^ | * +----------+ +-------+ * |Microphone| |Speaker| * +----------+ +-------+ */ var mediaHandlers = new Dictionary <string, VoIPMediaHandler> { { "AudioProcessor", audioProcessor }, { "OutGoingDataMixer", outgoingDataMixer }, { "RecordDataMixer", recordDataMixer }, { "SpeakerMixer", speakerMixer }, { "DTMF", dtmf }, { "Ringtones", ringtones }, { "AudioSender", phoneCallAudioSender }, { "AudiReceiver", phoneCallAudioReceiver }, }; if (microphone != null) { mediaHandlers.Add("Microphone", microphone); } if (speaker != null) { mediaHandlers.Add("Speaker", speaker); } return(new MediaHandlerCollection(mediaConnector, mediaHandlers)); }
/// <summary> /// Creates a complex phone call listener, built up from microphone, speaker, waverecorder, waveplayer, dtmf and ringtone sounds. /// </summary> /// <returns>The media handler collection that represent the phone call listener.</returns> public MediaHandlerCollection CreateSoftPhoneCallListener() { var phoneCallAudioReceiver = new PhoneCallAudioReceiver(); var phoneCallAudioSender = new PhoneCallAudioSender(); var microphone = Microphone.GetDefaultDevice(); var speaker = Speaker.GetDefaultDevice(); var audioProcessor = new AudioQualityEnhancer(); audioProcessor.SetEchoSource(speaker); // Handles the audio that comes from the PhoneCallListener var outgoingDataMixer = new AudioMixerMediaHandler(); var recordDataMixer = new AudioMixerMediaHandler(); var speakerMixer = new AudioMixerMediaHandler(); var dtmf = new DtmfEventWavePlayer(); var ringtones = new PhoneCallStateWavePlayer( commonWaveFormat, outGoingToneStreams, incomingToneStreams ); if (microphone != null) mediaConnector.Connect(microphone, audioProcessor); mediaConnector.Connect(audioProcessor, outgoingDataMixer); mediaConnector.Connect(outgoingDataMixer, phoneCallAudioSender); // No WaveStreamPlayback (see CreateWaveStreamPlayback method) //mediaConnector.Connect(phoneCallAudioReceiver, speaker); mediaConnector.Connect(phoneCallAudioReceiver, speakerMixer); mediaConnector.Connect(dtmf, speakerMixer); mediaConnector.Connect(ringtones, speakerMixer); if (speaker != null) mediaConnector.Connect(speakerMixer, speaker); mediaConnector.Connect(phoneCallAudioReceiver, recordDataMixer); mediaConnector.Connect(outgoingDataMixer, recordDataMixer); // No WaveStreamRecorder (see CreateWaveStreamRecorder method) /* * Media Connections: * * +---------------------------------------------------------------+ * | PhoneCall |************** * +---------------------------------------------------------------+ * * * ^^ VV * * * +--------------------+ +----------------------+ +----+ +---------+ * |PhoneCallAudioSender| |PhoneCallAudioReceiver| |DMTF| |Ringtones| * +--------------------+ +----------------------+ +----+ +---------+ * ^^ V V V | * +-----------------+ +---------------+ +------------+ | * |OutgoingDataMixer|----- >> -----|RecordDataMixer| |SpeakerMixer|--<<--/ * +-----------------+ +---------------+ +------------+ * ^^ ^^ V | *+--------------+ +------------------+ +------------------+ | *|AudioProcessor| |WaveStreamPlayback| |WaveStreamRecorder| V *+--------------+ +------------------+ +------------------+ V * ^^ | * +----------+ +-------+ * |Microphone| |Speaker| * +----------+ +-------+ */ var mediaHandlers = new Dictionary<string, VoIPMediaHandler> { {"AudioProcessor", audioProcessor}, {"OutGoingDataMixer", outgoingDataMixer}, {"RecordDataMixer", recordDataMixer}, {"SpeakerMixer", speakerMixer}, {"DTMF", dtmf}, {"Ringtones", ringtones}, {"AudioSender",phoneCallAudioSender}, {"AudiReceiver",phoneCallAudioReceiver}, }; if(microphone != null) mediaHandlers.Add("Microphone", microphone); if (speaker != null) mediaHandlers.Add("Speaker", speaker); return new MediaHandlerCollection(mediaConnector,mediaHandlers); }