// 合并音频片段
export const mergeAudioChunks = (chunks: ArrayBuffer[]): Uint8Array => {
  const totalLength = chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
  const merged = new Uint8Array(totalLength);
  let offset = 0;
  chunks.forEach((chunk) => {
    merged.set(new Uint8Array(chunk), offset);
    offset += chunk.byteLength;
  });
  return merged;
};

// 创建音频播放URL
export const createAudioUrl = (
  audioData: Uint8Array,
  mimeType = "audio/mp3"
): string => {
  const blob = new Blob([audioData as BlobPart], { type: mimeType });
  return URL.createObjectURL(blob);
};
