Created
June 8, 2019 06:14
-
-
Save identity2/cec6d1994d90be4309968faa49ce24c9 to your computer and use it in GitHub Desktop.
Serialize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void SaveAudioClipToDisk(AudioClip audioClip, string filename) | |
{ | |
//create file | |
BinaryFormatter bf = new BinaryFormatter (); | |
FileStream file = File.Create (Application.persistentDataPath+ "/" + filename); | |
//serialize by setting the sample, frequency, samples, and channels to the new AudioClipSample instance | |
AudioClipSample newSample = new AudioClipSample(); | |
newSample.sample = new float[audioClip.samples * audioClip.channels]; | |
newSample.frequency = audioClip.frequency; | |
newSample.samples = audioClip.samples; | |
newSample.channels = audioClip.channels; | |
//get the actual sample from the AudioClip | |
audioClip.GetData (newSample.sample, 0); | |
bf.Serialize (file, newSample); | |
file.Close (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment