-1

I have a database with different words in it, and with the words is a wav file stored in a blob with the pronunciation. I'm stuck trying to get the BLOB to read as a AudioClip for Unity.

So far I have the sound file somewhat resembling my original in the fact that its the same length, but there's a lot of static.

private float [] ConvertByteToFloat ( byte [] array )
{
    float[] floatArr = new float [ array.Length / 4 ];
    for ( int i = 0; i < floatArr.Length; i++ )
    {
        if ( !System.BitConverter.IsLittleEndian )
            System.Array.Reverse( array, i * 4, 4 );
        floatArr [ i ] = System.BitConverter.ToSingle( array, i * 4 );
    }
    return floatArr;
}
float[] stream = ConvertByteToFloat((byte[]) reader["Sound"]);
AudioClip clip = AudioClip.Create( ( string ) reader [ "Name" ], stream.Length, 2, 44100, false, false );
clip.SetData( stream, 0 );

There was only static earlier when IsLittleEndian was if(true), if not true made it a little more accurate, but still not what it was before.

1 Answers1

0

Your question is how to read AudioClip data from memory? Use AudioClip.SetData API. For example,

AudioClip audioClip = AudioClip.Create("Sound", data.Length, 1, 44100, false, false);
audioClip.SetData(data, 0);

Or you can use AudioClip AssetBundle from sqlite3 blob data via AssetBundle.CreateFromMemory if you have Pro license.

Kazuki Sakamoto
  • 13,929
  • 2
  • 34
  • 96