SpeechEncoderStreamType Property |
Namespace: StreamCoders.Encoder
StreamCoders.Codec codec = StreamCoders.Codec.AMRNB; int samplerate = 8000; int bitrate = 10200; // Open default wavein WaveInput win = new WaveInput(); win.BitsPerSample = 16; win.Channels = 1; win.SampleRate = samplerate; win.OpenDevice(null); win.Start(); // Create G.711 alaw encoder SpeechEncoder enc = new SpeechEncoder(); enc.InputBitsPerSample = 16; enc.InputChannels = 1; enc.InputSampleRate = samplerate; enc.SetCodec(codec); enc.OutputBitrate = bitrate; enc.PacketDuration = 20; enc.StreamType = StreamCoders.SpeechStreamType.StorageFormat; bool res = enc.Init(); if(res == false) { return; } // Create G.711 alaw decoder SpeechDecoder dec = new SpeechDecoder(); dec.Bitrate = bitrate; dec.StreamType = StreamCoders.SpeechStreamType.StorageFormat; dec.SetCodec(codec); res = dec.Init(); if (res == false) { return; } // Open default waveout WaveOutput wout = new WaveOutput(); wout.Channels = 1; wout.SampleRate = samplerate; wout.BitsPerSample = 16; wout.Init(); wout.OpenDevice(null); int bytescollected = 0; win.ClearBuffers(); while (true) { // is data available from device if (win.SamplesAvailable == true) { // get all queued data byte[] samples = win.GetAllData(); bytescollected += samples.Length; // encode data to g.711 byte stream byte[] g711bytes = enc.EncodeToBuffer(samples); if (g711bytes != null) { // decode byte stream byte[] raw = dec.Decode(g711bytes); // output to sound device and enjoy the echo wout.Enqueue(raw); } } } }