修改资源URL模式,不再存储https://domain 前缀

This commit is contained in:
2025-10-25 12:19:53 +08:00
parent f94ef73518
commit e4339a5b91
27 changed files with 347 additions and 137 deletions
+49
View File
@@ -0,0 +1,49 @@
import fs from "fs";
import OpenAI from "openai";
import prompt from "./prompt.md";
import { prisma } from "@/lib/prisma";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_API_BASE_URL,
});
async function transcriptAudio(audio: Buffer | string) {
if (typeof audio === "string") {
audio = fs.readFileSync(audio);
}
const base64Audio = Buffer.from(audio).toString("base64");
const response = await client.chat.completions.create({
model: "gemini-2.5-flash-lite",
messages: [
{
role: "user",
content: [
{
type: "text",
text: prompt,
},
{
type: "input_audio",
input_audio: {
data: base64Audio,
format: "wav",
},
},
],
},
],
});
console.log(response.choices[0].message.content);
}
async function transcriptAweme(awemeId: string) {
const aweme = await prisma.video.findUnique({
where: { aweme_id: awemeId },
});
if (!aweme) {
throw new Error("Aweme not found or aweme is not a video post");
}
}
+51
View File
@@ -0,0 +1,51 @@
你将接收一段音频。请完成:
A.语音活动检测(VAD)与声源分类;
B.条件式处理:
- 若包含可辨识的人类发言:** 进行转录 **(保留原语言,不翻译),并尽可能给出说话人分离与时间戳;
- 若不包含人类发言:** 不转录 **,仅返回音频类型与简要描述。
C.严格输出为下方 JSON,字段不得缺失或额外编造。听不清处用“[听不清]”。
** 输出 JSON Schema(示例)**
```json
{
"speech_detected": true,
"language": "zh-CN",
"audio_type": null,
"background": "music | ambience | none | unknown",
"transcript": [
{
"start": 0.00,
"end": 3.42,
"text": "大家好,我是……"
},
{
"start": 3.50,
"end": 6.10,
"text": "欢迎来到今天的节目。"
}
],
"non_speech_summary": null,
}
```
>
** 当无发言时返回:**
```json
{
"speech_detected": false,
"language": null,
"audio_type": "music | ambience | animal | mechanical | other",
"background": "none",
"transcript": [],
"non_speech_summary": "示例:纯音乐-钢琴独奏,节奏舒缓;或 环境声-雨声伴随雷鸣。",
}
```
** 规则补充 **
* 只要存在可理解的人类发言(即便有音乐 / 噪声),就执行转录,并在 `background` 标注“music / ambience”。
* 不要将唱词 / 哼唱视为“发言”;若仅有人声演唱且无口语发言,视为 ** 音乐 **。
* 不要臆测未听清内容;不要添加与音频无关的信息。
* 时间单位统一为秒,保留两位小数。
* 允许`language` 为多标签(如 "zh-CN,en")或为 `null`(无发言时)。