private async Task ProcessAudioForTranscriptionAsync(string socketId, string payload)
        {
            byte[] payloadByteArray = Convert.FromBase64String(payload);
            byte[] decoded;

            MuLawDecoder.MuLawDecode(payloadByteArray, out decoded);
            var transcriptionEngine = GetSocketTranscriptionEngine(socketId);
            await transcriptionEngine.Transcribe(decoded);
        }
Example #2
0
        /*
         * Receive audio data coming on port 1550 and feed it to the speakers to be played.
         */
        private void Receive()
        {
            try
            {
                bStop = false;
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);

                while (!bStop)
                {
                    //Receive data.
                    byte[] byteData = udpClient.Receive(ref remoteEP);

                    //G711 compresses the data by 50%, so we allocate a buffer of double
                    //the size to store the decompressed data.
                    byte[] byteDecodedData = new byte[byteData.Length * 2];

                    //Decompress data using the proper vocoder.
                    if (vocoder == Vocoder.ALaw)
                    {
                        ALawDecoder.ALawDecode(byteData, out byteDecodedData);
                    }
                    else if (vocoder == Vocoder.uLaw)
                    {
                        MuLawDecoder.MuLawDecode(byteData, out byteDecodedData);
                    }
                    else
                    {
                        byteDecodedData = new byte[byteData.Length];
                        byteDecodedData = byteData;
                    }


                    //Play the data received to the user.
                    playbackBuffer = new SecondaryBuffer(playbackBufferDescription, device);
                    playbackBuffer.Write(0, byteDecodedData, LockFlag.None);
                    playbackBuffer.Play(0, BufferPlayFlags.Default);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-Receive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                nUdpClientFlag += 1;
            }
        }
Example #3
0
        // 서버로부터 음성정보를 전달받는다.
        private void ReceiveVoiceInfo(byte[] byteData)
        {
            try
            {
                //Initialize();
                bStop = false;

                //G711 compresses the data by 50%, so we allocate a buffer of double
                //the size to store the decompressed data.
                byte[] byteDecodedData = new byte[byteData.Length * 2];

                //Decompress data using the proper vocoder.
                if (vocoder == Vocoder.ALaw)
                {
                    ALawDecoder.ALawDecode(byteData, out byteDecodedData);
                }
                else if (vocoder == Vocoder.uLaw)
                {
                    MuLawDecoder.MuLawDecode(byteData, out byteDecodedData);
                }
                else
                {
                    byteDecodedData = new byte[byteData.Length];
                    byteDecodedData = byteData;
                }


                //Play the data received to the user.
                playbackBuffer = new SecondaryBuffer(playbackBufferDescription, device);
                playbackBuffer.Write(0, byteDecodedData, LockFlag.None);
                playbackBuffer.Play(0, BufferPlayFlags.Default);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                nUdpClientFlag += 1;
            }
        }
Example #4
0
 /// <summary>
 /// The purpose of this method is to decode the RTP payload into raw audio.
 /// </summary>
 private void DecodePayload()
 {
     // u-law decoding
     if (this.payloadType == 0)
     {
         decodedPayload = MuLawDecoder.MuLawDecode(payload);
     }
     // a-law decoding
     else if (this.payloadType == 1)
     {
         decodedPayload = ALawDecoder.ALawDecode(payload);
     }
     else if (this.payloadType == 101)
     {
         decodedPayload = null;
     }
     else
     {
         throw new InvalidRTPPacketException();
         // unknown decoding --- more may need to be added in the future.
     }
 }
Example #5
0
 public short[] Decode(byte[] data, BandMode mode)
 {
     return(MuLawDecoder.MuLawDecode(data));
 }
Example #6
0
        /*
         * Receive audio data coming on port 1550 and feed it to the speakers to be played.
         */
        private void Receive()
        {
            try
            {
                IsThreadReceiveEnd = false;

                byte[] byteData;
                bStop = false;
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);

                if (eMode == Mode.Server)
                {
                    LogAppend("Server Started");
                    LogUsersConnected();
                }
                else
                {
                    LogAppend("Client Audio Connected");
                }

                while (!bStop)
                {
                    //Receive data.
                    try
                    {
                        //bytes_received = udp_socket.ReceiveFrom(data, ref ep);

                        try
                        {
                            byteData = udpClient.Receive(ref remoteEP);
                        }
                        catch (Exception)
                        {
                            return;
                        }

                        //G711 compresses the data by 50%, so we allocate a buffer of double
                        //the size to store the decompressed data.
                        byte[] byteDecodedData = new byte[byteData.Length * 2];

                        if (vocoder == Vocoder.ALaw)
                        {
                            ALawDecoder.ALawDecode(byteData, out byteDecodedData);  //Vocoder.ALaw
                        }
                        else if (vocoder == Vocoder.uLaw)
                        {
                            MuLawDecoder.MuLawDecode(byteData, out byteDecodedData);  //Vocoder.uLaw
                        }
                        else
                        {
                            byteDecodedData = new byte[byteData.Length];
                            byteDecodedData = byteData;
                        }


                        if (eMode == Mode.Server)
                        {
                            lock (otherPartyIPs)
                            {
                                for (int i = 0; i < otherPartyIPs.Count; i++)
                                {
                                    udpClient.Send(byteDecodedData, byteDecodedData.Length, otherPartyIPs[i].Address.ToString(), 1550);
                                }
                            }
                        }

                        //Play the data received to the user.
                        playbackBuffer = new SecondaryBuffer(playbackBufferDescription, device);
                        playbackBuffer.Write(0, byteDecodedData, LockFlag.None);
                        playbackBuffer.Play(0, BufferPlayFlags.Default);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (eMode == Mode.Server)
                {
                    LogAppend("Server Stopped");
                    LogUsersConnected();
                }
                else
                {
                    LogAppend("Client Audio Disconnected");
                }
            }
            catch (Exception ex)
            {
                LogAppend("Voice Receive > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-Receive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                nUdpClientFlag += 1;
            }

            IsThreadReceiveEnd = true;
        }
Example #7
0
        /*
         * Receive audio data coming on port 1550 and feed it to the speakers to be played.
         */
        public void Receive()
        {
            //TODO: Receive Sound DATA

            try
            {
                byte[] byteData;
                bStop = false;
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);

                if (eMode == Mode.Server)
                {
                    cGlobalVars.AddLogChat("Server Started");
                    LogUsersConnected();
                }
                else
                {
                    cGlobalVars.AddLogChat("Client Audio Connected");
                }

                while (!bStop)
                {
                    //Receive data.
                    try
                    {
                        //bytes_received = udp_socket.ReceiveFrom(data, ref ep);

                        try
                        {
                            byteData = udpClient.Receive(ref remoteEP);
                        }
                        catch (Exception)
                        {
                            return;
                        }

                        //G711 compresses the data by 50%, so we allocate a buffer of double
                        //the size to store the decompressed data.
                        byte[] byteDecodedData = new byte[byteData.Length * 2];

                        if (vocoder == Vocoder.ALaw)
                        {
                            ALawDecoder.ALawDecode(byteData, out byteDecodedData); //Vocoder.ALaw
                        }
                        else if (vocoder == Vocoder.uLaw)
                        {
                            MuLawDecoder.MuLawDecode(byteData, out byteDecodedData); //Vocoder.uLaw
                        }
                        else
                        {
                            byteDecodedData = new byte[byteData.Length];
                            byteDecodedData = byteData;
                        }

                        if (eMode == Mode.Server)
                        {
                            lock (clientIPs)
                            {
                                // udpClient.Send(byteData, byteData.Length, clientIPs[i].Address.ToString(), 1550);


                                //Parallel.For(0, clientIPs.Count, delegate(int i)
                                //     {
                                //
                                //     }
                                // );
                            }
                        }

                        //LogAppend("2Receibed Data!");

                        bwp_internet.AddSamples(byteData, 0, byteData.Length);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (eMode == Mode.Server)
                {
                    cGlobalVars.AddLogChat("Server Stopped");
                    LogUsersConnected();
                }
                else
                {
                    cGlobalVars.AddLogChat("Client Audio Disconnected");
                }
            }
            catch (Exception ex)
            {
                cGlobalVars.AddLogChat("Voice Receive > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-Receive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                nUdpClientFlag += 1;
            }
        }
Example #8
0
        /*
         * Receive audio data coming on port 1550 and feed it to the speakers to be played.
         */
        public void Receive()
        {
            //TODO: Receive Sound DATA

            try
            {
                byte[] byteData;
                bStop = false;
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
                cGlobalVars.AddLogChat("Client Audio Connected");

                while (!bStop)
                {
                    //Receive data.
                    try
                    {
                        //bytes_received = udp_socket.ReceiveFrom(data, ref ep);

                        try
                        {
                            byteData = udpClient.Receive(ref remoteEP);
                        }
                        catch (Exception)
                        {
                            return;
                        }

                        //G711 compresses the data by 50%, so we allocate a buffer of double
                        //the size to store the decompressed data.
                        byte[] byteDecodedData = new byte[byteData.Length * 2];

                        if (vocoder == VoiceCommon.Vocoder.ALaw)
                        {
                            ALawDecoder.ALawDecode(byteData, out byteDecodedData); //Vocoder.ALaw
                        }
                        else if (vocoder == VoiceCommon.Vocoder.uLaw)
                        {
                            MuLawDecoder.MuLawDecode(byteData, out byteDecodedData); //Vocoder.uLaw
                        }
                        else
                        {
                            byteDecodedData = new byte[byteData.Length];
                            byteDecodedData = byteData;
                        }

                        bwp_internet.AddSamples(byteData, 0, byteData.Length);
                    }
                    catch (Exception)
                    {
                    }
                }
                cGlobalVars.AddLogChat("Client Audio Disconnected");
            }
            catch (Exception ex)
            {
                cGlobalVars.AddLogChat("Voice Receive > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-Receive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                nUdpClientFlag += 1;
            }
        }