Esempio n. 1
0
        private void GetAudioData(AudioClip clip)
        {
            var soundData = new float[clip.samples * clip.channels];

            clip.GetData(soundData, 0);
            var newData = new float[position * clip.channels];

            for (int i = 0; i < newData.Length; i++)
            {
                newData[i] = soundData[i];
            }
            var newClip = AudioClip.Create(clip.name,
                                           position,
                                           clip.channels,
                                           clip.frequency,
                                           false);

            newClip.SetData(newData, 0);
            long duration = (long)(newClip.length * 1000);

            MemoryStream amrStream = new MemoryStream();

            ConvertAndWriteWav(amrStream, newClip);
            WriteWavHeader(amrStream, newClip);
            int lengthSamples = newClip.samples;

            ClientEngine.RunTask(() => {
                micPhone.OnRecord(new RTMAudioData(AudioConvert.ConvertToAmrwb(amrStream.ToArray()), newData, RTMAudioData.DefaultCodec, lang, duration, lengthSamples, RECORD_SAMPLE_RATE));
            });
        }
Esempio n. 2
0
        private byte[] GetRtmAudioData(RTMAudioHeader rtmAudioHeader, AudioClip clip, long duration)
        {
            MemoryStream amrStream = new MemoryStream();

            ConvertAndWriteWav(amrStream, clip);
            WriteWavHeader(amrStream, clip);
            byte[] amrArray = AudioConvert.ConvertToAmrwb(amrStream.ToArray());

            MemoryStream audioStream = new MemoryStream();

            byte[] rtmHeader = rtmAudioHeader.HeaderArray;
            audioStream.Write(rtmHeader, 0, rtmHeader.Length);
            audioStream.Write(amrArray, 0, amrArray.Length);
            return(audioStream.ToArray());
        }
        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);
            }
        }