Ejemplo 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));
            });
        }
Ejemplo n.º 2
0
        public void FinishInput()
        {
            if (micPhone == null)
            {
                return;
            }

            bool timeDown = false;

            lock (selfLocker) {
                if (isRecording)
                {
                    timeDown    = true;
                    isRecording = false;
                    position    = Microphone.GetPosition(device);
                    micPhone.End();
                }
            }

            if (timeDown)
            {
                StopCoroutine("TimeDown");

                if (micPhone != null && clipRecord != null)
                {
                    micPhone.OnRecord(GetAudioData(clipRecord));
                }
            }
        }