Rooz
Rooz

Reputation: 225

How encode Audio file and save it with unity?

I want to encode some type of file from my assetbundle and save those files to my path. I use this code for encoding Texture2D file to ".jpg" and save it:

(my assetbundle method work fine)
texTmp = (Texture2D) Instantiate (assetRequest.asset);
SaveSaveToJpg(texTmp);

and save with:

void SaveToJpg(Texture2D texture)
{
byte[] bytes = texture.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/"+ texture.name + ".jpg", bytes);
}

So in Unity documentation, I saw how can encode the .mp4 file, but how can I encode the Audio file and save it with unity?

Edit: I use https://gist.github.com/darktable/2317063#file-savwav-cs class, but is there any unity official method for this?

Upvotes: 3

Views: 1872

Answers (1)

Hadi HD
Hadi HD

Reputation: 26

SavWav Script

public AudioClip myAudio;

SavWav.Save(Application.persistentDataPath + "/audio.wav", myAudio);

Upvotes: 1

Related Questions