update 优化录音功能模块的代码和火山模块

This commit is contained in:
2025-10-22 03:24:08 +08:00
parent c1072c3896
commit edace856ab
26 changed files with 1634 additions and 101 deletions

View File

@@ -0,0 +1,41 @@
import { nanoid } from "nanoid";
// Speak 类型定义
export type Speak = {
id: string;
no: number; // 序号, 当天的序号
file?: string; // base64 编码的音频文件
text?: string; // 文字内容,识别的内容
timestamp: number; // 生成时间戳
day: number; // 365天中的第几天
duration: number; // 音频时长,单位秒
url?: string; // 音频文件的 URL 地址
speaker?: string; // 说话人
type?: 'merge' | 'normal'; // 语音类型,默认录制或者合并的
createdAt?: Date; // 创建时间
updatedAt?: Date; // 更新时间
}
// 语音类型枚举
export type SpeakType = 'merge' | 'normal';
// 创建 Speak 时的数据类型(排除自动生成的字段)
export type CreateSpeakData = Omit<Speak, 'id' | 'createdAt' | 'updatedAt'>;
// 更新 Speak 时的数据类型
export type UpdateSpeakData = Partial<Omit<Speak, 'id' | 'createdAt'>>;
// 获取今天是一年中的第几天
export function getDayOfYear(date: Date = new Date()): number {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date.getTime() - start.getTime();
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
// 一天是86400秒获取是当天第几秒
export const getNo = () => {
const now = new Date();
const secondsSinceMidnight = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
return secondsSinceMidnight;
}