export const convertToPCM16 = (float32Array: Float32Array): Uint8Array => {
  const int16Buffer = new Int16Array(float32Array.length);
  for (let i = 0; i < float32Array.length; i++) {
    int16Buffer[i] = Math.max(-1, Math.min(1, float32Array[i])) * 0x7FFF;
  }
  const buffer = new ArrayBuffer(int16Buffer.length * 2);
  const view = new DataView(buffer);
  for (let i = 0; i < int16Buffer.length; i++) {
    view.setInt16(i * 2, int16Buffer[i], true);
  }
  return new Uint8Array(buffer);
};
