private Dictionary <string, object> BuildAudioMessageAttrs(RTMAudioData audioData) { Dictionary <string, object> rtmAttrs = new Dictionary <string, object>(); rtmAttrs.Add("type", "audiomsg"); rtmAttrs.Add("codec", audioData.CodecType); rtmAttrs.Add("srate", audioData.Frequency); rtmAttrs.Add("lang", audioData.Language); rtmAttrs.Add("duration", audioData.Duration); return(rtmAttrs); }
public void Play(RTMAudioData data) { #if UNITY_ANDROID if (AudioRecord != null) { AudioRecord.Call("broadAudio", AudioConvert.ConvertToWav(data.Audio)); } #elif (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) byte[] wavBuffer = AudioConvert.ConvertToWav(data.Audio); startPlay(wavBuffer, wavBuffer.Length, PlayFinishCallback); #else startPlay(data.Audio, data.Audio.Length, PlayFinishCallback); #endif }
public void StopRecord() { #if UNITY_ANDROID AndroidJavaObject audio = AudioRecord.Call <AndroidJavaObject>("stopRecord"); int duration = audio.Get <int>("duration"); byte[] audioData = audio.Get <byte[]>("audioData"); //byte[] audioData = (byte[])(Array)audio.Get<sbyte[]>("audioData"); if (cancelRecord) { cancelRecord = false; return; } if (audioRecorderListener != null) { RTMAudioData data = new RTMAudioData(audioData, language, duration); audioRecorderListener.OnRecord(data); } #else stopRecord(StopRecordCallback); #endif }
private static void StopRecordCallback(IntPtr data, int length, long time) { recording = false; if (audioRecorderListener != null) { audioRecorderListener.RecordEnd(); if (cancelRecord) { cancelRecord = false; return; } byte[] payload = new byte[length]; Marshal.Copy(data, payload, 0, length); #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) RTMAudioData audioData = new RTMAudioData(AudioConvert.ConvertToAmrwb(payload), language, time); #else RTMAudioData audioData = new RTMAudioData(payload, language, time); #endif audioRecorderListener.OnRecord(audioData); } }
public int SendRoomFile(out long messageId, long roomId, RTMAudioData audioData, string attrs = "", int timeout = 120) { return(RealSendFile(out messageId, FileTokenType.Room, roomId, (byte)MessageType.AudioFile, audioData.Audio, "", "", attrs, BuildAudioMessageAttrs(audioData), timeout)); }
//===========================[ Sned Sned RTM-Audio Room File ]=========================// public bool SendRoomFile(MessageIdDelegate callback, long roomId, RTMAudioData audioData, string attrs = "", int timeout = 120) { return(RealSendFile(callback, FileTokenType.Room, roomId, (byte)MessageType.AudioFile, audioData.Audio, "", "", attrs, BuildAudioMessageAttrs(audioData), timeout)); }