いろいろ備忘録

雑記です。

 ビッグエンディアンからリトルエンディアンに変換

google cloud speech APIを使用するときに書きました。

サンプルで使用されているLINEAR16はPCM16のリトルエンディアン版みたいです。

PCM16は16bit=2byteなので、bytes[i+1] bytes[i]に変換していく作業です。

short型でのコードはこちら。

public static byte[] short2little(short[] sData) {
ByteBuffer buffer = ByteBuffer.allocate(sData.length * 2);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.asShortBuffer().put(sData);
return buffer.array();
}