//语音聊天消息 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); }
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"); }
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()); }
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); }