Files
openmaic/OpenMAIC/tests/audio/wav-utils.test.ts
2026-08-16 14:58:47 +08:00

50 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { isWavBlob, normalizeASRUploadAudio } from '@/lib/audio/wav-utils';
describe('isWavBlob', () => {
it('detects audio/wav MIME type', () => {
const blob = new Blob([new Uint8Array(4)], { type: 'audio/wav' });
expect(isWavBlob(blob)).toBe(true);
});
it('detects audio/x-wav MIME type', () => {
const blob = new Blob([new Uint8Array(4)], { type: 'audio/x-wav' });
expect(isWavBlob(blob)).toBe(true);
});
it('detects .wav file extension when MIME is missing', () => {
const blob = new Blob([new Uint8Array(4)]);
expect(isWavBlob(blob, 'recording.wav')).toBe(true);
expect(isWavBlob(blob, 'recording.WAV')).toBe(true);
});
it('returns false for non-WAV blobs without a wav filename', () => {
const blob = new Blob([new Uint8Array(4)], { type: 'audio/webm' });
expect(isWavBlob(blob)).toBe(false);
expect(isWavBlob(blob, 'recording.webm')).toBe(false);
});
});
describe('normalizeASRUploadAudio', () => {
it('passes through providers without WAV normalization unchanged', async () => {
const input = new Blob([new Uint8Array([1, 2, 3])], { type: 'audio/webm' });
const result = await normalizeASRUploadAudio('openai-whisper', input);
expect(result.blob).toBe(input);
expect(result.fileName).toBe('recording.webm');
});
it('keeps WAV blobs unchanged for lemonade-asr', async () => {
const input = new Blob([new Uint8Array([1, 2, 3])], { type: 'audio/wav' });
const result = await normalizeASRUploadAudio('lemonade-asr', input);
expect(result.blob).toBe(input);
expect(result.fileName).toBe('recording.wav');
});
it('keeps WAV blobs unchanged for funasr-asr', async () => {
const input = new Blob([new Uint8Array([1, 2, 3])], { type: 'audio/wav' });
const result = await normalizeASRUploadAudio('funasr-asr', input);
expect(result.blob).toBe(input);
expect(result.fileName).toBe('recording.wav');
});
});