AdamInTheOculus
AdamInTheOculus

Reputation: 370

Issues decompressing (FlateDecode) audio data in XFDF from Adobe Acrobat

I'm trying to decompress AIFF audio data from an XFDF sound annotation, and play the audio in the browser. Any time I export a sound annotation from Adobe Acrobat and decompress the audio data it results in seemingly garbage data.

The code below works for compressed audio starting with 789C header, but a few compressed streams start with 4889 or 78DA and fail to play in the browser. After numerous tests with Acrobat, exported sound annotations in XFDF start with 4889.


// Two audio examples, one working and one failing.
// Can't paste it all due to char limit.
const compressedHexString_working = `789C3C9C059C13D7FBF5473293F55DBCB8BBBBBB53DC8ABB142FEE5AB4 ...`;
const compressedHexString_failing = `48892C97077C8FE716C7CFF9532EB7418D5E24768492DABB0862146DAF ...`;

// Convert hex string into ArrayBuffer.
const compressedByteArray = new Uint8Array(
  compressedHexString_working
    .match(/[a-fA-F0-9]{2}/g)
    .map((str: string) => parseInt(str, 16))
);

const { default: zlib } = await import('pako');
const audioData = await zlib.inflate(compressedByteArray);

// Parse header bytes to determine audio file.
const fileHeader = new TextDecoder().decode(audioData).substring(0, 4);
console.log('Sound File Header:', fileHeader);

The console.log usually prints ID3, RIFF, or FORM when decompression is successful. But when decompressing the failing example, the result is a garbage value: �D�C.

Am I doing the decompression incorrectly? Or am I missing a step?

Upvotes: 1

Views: 100

Answers (0)

Related Questions