feat: tts语音生成
This commit is contained in:
20
web/src/utils/audio.ts
Normal file
20
web/src/utils/audio.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// 合并音频片段
|
||||
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);
|
||||
};
|
||||
7
web/src/utils/format.ts
Normal file
7
web/src/utils/format.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const formatTime = (seconds: number): string => {
|
||||
if (Number.isNaN(seconds) || !Number.isFinite(seconds)) return "00:00";
|
||||
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const secs = Math.floor(seconds % 60);
|
||||
return `${minutes.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
export * from "./audio";
|
||||
export * from "./context";
|
||||
export * from "./format";
|
||||
export * from "./media";
|
||||
export * from "./pcm";
|
||||
export * from "./title";
|
||||
|
||||
Reference in New Issue
Block a user