chore: speech to text
This commit is contained in:
@@ -156,6 +156,26 @@ export const platformCall = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const formatTime = (seconds: number) => {
|
||||
if (isNaN(seconds) || !seconds || seconds === Infinity) {
|
||||
return '00:00';
|
||||
}
|
||||
const hrs = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
const secs = Math.floor(seconds % 60);
|
||||
|
||||
const formatted = [
|
||||
hrs.toString().padStart(2, '0'),
|
||||
mins.toString().padStart(2, '0'),
|
||||
secs.toString().padStart(2, '0')
|
||||
];
|
||||
|
||||
if (hrs > 0) {
|
||||
return `${formatted[0]}:${formatted[1]}:${formatted[2]}`;
|
||||
}
|
||||
return `${formatted[1]}:${formatted[2]}`;
|
||||
};
|
||||
|
||||
export const formatNumber = (num: number) => {
|
||||
if (!num) {
|
||||
return '0';
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { convertFileSize } from './index';
|
||||
|
||||
export const loadAudioData = async (data: any, type: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const audioBlob = new Blob([data], { type: type });
|
||||
const fileSize = convertFileSize(audioBlob.size);
|
||||
|
||||
const audio = document.createElement('audio');
|
||||
const url = URL.createObjectURL(audioBlob);
|
||||
audio.src = url;
|
||||
|
||||
audio.addEventListener('loadedmetadata', () => {
|
||||
const duration = audio.duration;
|
||||
resolve({ size: fileSize, duration: Math.ceil(duration), url: url });
|
||||
});
|
||||
|
||||
audio.addEventListener('ended', () => {
|
||||
URL.revokeObjectURL(audio.src);
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const readAudioFile = async (file: File) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = async function (e: any) {
|
||||
try {
|
||||
// const size = convertFileSize(file.size);
|
||||
console.log('file====', file);
|
||||
const arrayBuffer = e.target.result;
|
||||
const audioData = await loadAudioData(arrayBuffer, file.type);
|
||||
resolve({
|
||||
...(audioData || {}),
|
||||
name: file.name
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user