public override void StartRecording() { if (!Application.HasUserAuthorization(UserAuthorization.Microphone)) { Debug.LogWarning("StartRecording(): Webplayer microphone access denied"); return; } device = DefaultMicrophone; prevReadPosition = 0; this.recordingFrequency = AudioUtils.GetFrequency(Mode); int min, max; Microphone.GetDeviceCaps(device, out min, out max); if (max == 0) { max = 48000; } //if( max == 0 ) max = 16000; int frequency = Mathf.Clamp(this.recordingFrequency, min, max); resampleBuffer = new BigArray <float>(ChunkSize, 0); recordedAudio = Microphone.Start(device, true, 5, frequency); }
private IEnumerator yieldChunks(BigArray <float> data, int chunkSize, float chunkDuration) { int readHead = 0; while (readHead < data.Length) { int remainder = chunkSize; if (readHead + chunkSize >= data.Length) { remainder = data.Length - readHead; } BigArray <float> temp = new BigArray <float>(remainder, 0); temp.Resize(remainder); temp.CopyFrom(data.Items, readHead * 4, 0, remainder * 4); AudioUtils.Resample(temp, testClip.frequency, AudioUtils.GetFrequency(ResampleFrequency)); bufferReady(temp, AudioUtils.GetFrequency(ResampleFrequency)); readHead += remainder; yield return(new WaitForSeconds(chunkDuration)); } }