示例#1
0
    //语音聊天消息
    public void ChewTheRag(byte[] buffer)
    {
        CMD_GF_C_UserVoice userVoice = new CMD_GF_C_UserVoice();

        userVoice.dwTargetUserID = 0;
        userVoice.dwVoiceLength  = (uint)buffer.Length;
        byte[] buffer1 = NetUtil.StructToBytes(userVoice);
        MyDebug.TestLog("buffer.Length==" + buffer.Length);
        sendData = new byte[8 + buffer.Length];
        Array.Copy(buffer1, sendData, buffer1.Length);
        Array.Copy(buffer, 0, sendData, buffer1.Length, buffer.Length);
        SocketEngine.Instance.SendScoketData((int)GameServer.MDM_GF_FRAME, (int)SUB_GF_GAME_STATUS.SUB_GF_USER_VOICE, sendData,
                                             sendData.Length);
    }
示例#2
0
 public void StartRecord()
 {
     SoundManager.Instance.GamePlayAudio.Stop();
     if (micArray.Length == 0)
     {
         MyDebug.TestLog("No Record Device!");
         return;
     }
     redioclip = Microphone.Start("inputMicro", false, RECORD_TIME, 600); //22050
     while (!(Microphone.GetPosition(null) > 0))
     {
     }
     MyDebug.TestLog("StartRecord");
 }
示例#3
0
    public void StopRecord()
    {
        MyDebug.TestLog("StopRecord");
        if (micArray.Length == 0)
        {
            MyDebug.TestLog("No Record Device!");
            return;
        }
        if (!Microphone.IsRecording(null))
        {
            MyDebug.TestLog("StopRecord 1111111111");
            return;
        }

        MyDebug.TestLog("StopRecord 2222222222222");
        Microphone.End(null);
        MyDebug.TestLog("StopRecord 3333333333333");
        SoundManager.Instance.GamePlayAudio.clip = redioclip;
        MyDebug.TestLog("StopRecord 444444444444444444");
        // Test(GetClipData());
        SocketSendManager.Instance.ChewTheRag(GetClipData());
    }
示例#4
0
    public Byte[] GetClipData()
    {
        if (SoundManager.Instance.GamePlayAudio.clip == null)
        {
            MyDebug.TestLog("GetClipData audio.clip is null");
            return(null);
        }
        MyDebug.TestLog("GetClipData audio.clip is 1111111111");
        var samples = new float[SoundManager.Instance.GamePlayAudio.clip.samples];

        MyDebug.TestLog("samples.Length = " + samples.Length);
        SoundManager.Instance.GamePlayAudio.clip.GetData(samples, 0);
        var outData = new byte[samples.Length * 2];

        MyDebug.TestLog("GetClipData audio.clip is 2222022222222");
        //Int16[] intData = new Int16[samples.Length];
        //converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]
        const int rescaleFactor = 32767; //to convert float to Int16

        for (int i = 0; i < samples.Length; i++)
        {
            var temshort = (short)(samples[i] * rescaleFactor);
            var temdata  = BitConverter.GetBytes(temshort);
            outData[i * 2]     = temdata[0];
            outData[i * 2 + 1] = temdata[1];
        }
        MyDebug.TestLog("GetClipData audio.clip is 3333333333333");
        if (outData == null || outData.Length <= 0)
        {
            MyDebug.TestLog("GetClipData intData is null");
            return(null);
        }
        MyDebug.TestLog("GetClipData audio.clip is 41444444444444");
        //return intData;
        return(outData);
    }