x


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?

more ▼

asked Jun 08 '12 at 03:13 PM

raypendergraph gravatar image

raypendergraph
1.6k 15 21 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jun 08 '12 at 07:06 PM

raypendergraph gravatar image

raypendergraph
1.6k 15 21 37

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

Nov 26 '12 at 02:53 PM fil
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1027
x970
x419
x21

asked: Jun 08 '12 at 03:13 PM

Seen: 502 times

Last Updated: Nov 26 '12 at 02:53 PM