- Home /
Getting at raw imported audio data via AssetDatabase.
Is there any way to get at the raw bytes that are created by the import process? We have a customized editor based bundle creation tool and I want to use the converted WAV->OGG bytes from the import process that Unity caches (as opposed to using Vorbis command line tools) to then write the OGG bytes into an OGG file to a well know location as part of the bundling process.
I get that I can mark the assets as OGG/Stream from disc in the editor and it will create a multi-part RIFF file to access like that but that's not what we want to do.
None of the AssetDatabase methods seem to deal in bytes so is there any other way to do this?
Edit: Also it looks like dealing with the asset in the Library/cache folder is not useful as it appears to be some (non .NET) object serialization scheme? Does anyone know what format these are?
Answer by Ray-Pendergraph · Jun 08, 2012 at 07:06 PM
After some brute force perusing through the editor APIs looks like EditorUtility.ExtractOggFile does the trick. Seems like a little of an odd place for it but it works. Here is a simple code example to demonstrate for searchers later on
[MenuItem("Assets/Export OGG")]
public static void ExportOgg()
{
UnityEngine.Object[] oggAsset = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel);
EditorUtility.ExtractOggFile(oggAsset[0],"a/special/place/assetname.ogg");
}
Edit: There is also the new ability build into the engine but of course this comes with some caveats.
The "StreamingAssets" folder seems to only be recognized in the root level unlike the "Resources" folder.
The files are moved untouched from their original format. So I wanted Unity's OGG output for a given WAV original, this will not work for me. It plops the WAV into the StreamingAssets folder in the game. Sometimes this is what you might want and sometimes it's not. It seems to me that this is a feature; the file should obey the import settings in the inspector even for streaming.
hi, with this is possible to save the sound to a file? i'm trying use it but i don't understand. could you help me? thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613072532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to import my own .ogg files? 1 Answer
Exporting large model / plant from navisworks as FBX for importing to Unity 5 Answers
Is there a way to stop Unity importing an asset? 1 Answer
Skybox Pixelated 0 Answers
Importing assets 0 Answers