!WARNING!
Probably, saving to mp3, broken for Unity 2020+. But all other stuff working
FormatException: Not a WAVE file - no RIFF header
Sorry, no time to look into that
With this package you can save an audioclip to mp3 in unity3d. Also plugin can save audioclip to wav and convert wav to mp3.
It works with Windows, Android and IOS(tested). And probably on Mac(untested, but should work).
Lame unity port from https://github.com/3wz/Lame-For-Unity
Wav save script from https://gist.github.com/darktable/2317063
public AudioClip clip;
void Start(){
// Convert wav clip to mp3 bytes array
//128 is recommend bitray for mp3 files
byte[] mp3 = WavToMp3.ConvertWavToMp3(clip, 128);
}
// THIS METHOD PROBABLY BROKEN FOR UNITY 2020+
public AudioClip clip;
void Start(){
// Save AudioClip at assets path with defined bitray as mp3
//128 is recommend bitray for mp3 files
EncodeMP3.SaveMp3(clip, $"{Application.dataPath}/mp3File", 128);
}
public AudioClip clip;
void Start(){
// Save AudioClip at assets path as wav
SavWav.SaveWav($"{Application.dataPath}/wavFile", clip);
}
- Download a source code zip this page
- Extract it
- Import it into the following directory in your Unity project
Packages
(It works as an embedded package. For Unity 2018.1 or later)Assets
(Legacy way. For Unity 2017.1 or later)
- https://assetstore.unity.com/packages/tools/audio/save-audioclip-to-mp3-189071
- Add it to project as usual