fix: wav format audio, #2317

This commit is contained in:
jialin
2025-07-16 13:06:01 +08:00
parent f4d6abace7
commit 14d60264c7
9 changed files with 68 additions and 24 deletions
+4 -2
View File
@@ -28,12 +28,14 @@ export const convertFileSize = (
): string | number => {
if (!sizeInBytes) return allowEmpty ? '' : 0;
const fmt = 1024;
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
let size = sizeInBytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
while (size >= fmt && unitIndex < units.length - 1) {
size /= fmt;
unitIndex++;
}
+14
View File
@@ -1,5 +1,13 @@
import { message } from 'antd';
import { convertFileSize } from './index';
export const audioTypeMap: Record<string, string> = {
'audio/wav': 'wav',
'audio/mp3': 'mp3',
'audio/mpeg': 'mp3',
'audio/x-wav': 'wav'
};
export const convertFileToBase64 = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
@@ -42,6 +50,12 @@ export const loadAudioData = async (
audio.addEventListener('ended', () => {
URL.revokeObjectURL(audio.src);
});
audio.addEventListener('error', () => {
URL.revokeObjectURL(url);
message.error('Failed to load audio metadata invalid file');
reject(new Error('Failed to load audio metadata invalid file'));
});
} catch (error) {
console.log('error====', error);
reject(error);