You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
45 lines
1.0 KiB
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class RecSystemAudio : MonoBehaviour, IRecAudio |
|
{ |
|
List<float> audioData = new List<float>(); |
|
float startTime; |
|
int channelsCount; |
|
|
|
void Awake() |
|
{ |
|
enabled = false; |
|
} |
|
|
|
public void StartRecording() |
|
{ |
|
enabled = true; |
|
startTime = Time.time; |
|
} |
|
|
|
void OnAudioFilterRead(float[] data, int channels) |
|
{ |
|
audioData.AddRange(data); |
|
channelsCount = channels; |
|
} |
|
|
|
public void StopRecording(string savePath) |
|
{ |
|
enabled = false; |
|
int durationInSec = Mathf.CeilToInt(Time.time - startTime); |
|
|
|
//Create file |
|
AudioClip buffer = |
|
AudioClip.Create( |
|
"SystemSound", |
|
AudioSettings.outputSampleRate * channelsCount * durationInSec, |
|
channelsCount, |
|
AudioSettings.outputSampleRate, |
|
false); |
|
|
|
buffer.SetData(audioData.ToArray(), 0); |
|
|
|
SavWav.Save(savePath, buffer); |
|
} |
|
}
|
|
|