feat: 将视频转写重构为纯文字异步语音识别

This commit is contained in:
2026-10-03 21:58:06 +08:00
parent 040273586b
commit 6f0e38054b
34 changed files with 2283 additions and 1771 deletions
@@ -0,0 +1,47 @@
BEGIN;
ALTER TABLE "VideoTranscript"
DROP COLUMN IF EXISTS speech_detected,
DROP COLUMN IF EXISTS language,
DROP COLUMN IF EXISTS audio_type,
DROP COLUMN IF EXISTS non_speech_summary,
DROP COLUMN IF EXISTS content_tags;
CREATE TABLE IF NOT EXISTS "TranscriptionTask" (
"videoId" TEXT PRIMARY KEY REFERENCES "Video"(aweme_id) ON DELETE CASCADE ON UPDATE CASCADE,
status TEXT NOT NULL DEFAULT 'QUEUED' CHECK (status IN ('QUEUED', 'PROCESSING', 'SUCCEEDED', 'FAILED')),
"providerTaskId" TEXT,
"submittingAt" TIMESTAMP(3),
"submittedAt" TIMESTAMP(3),
"nextPollAt" TIMESTAMP(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'),
"leaseUntil" TIMESTAMP(3),
"leaseToken" TEXT,
attempts INTEGER NOT NULL DEFAULT 0,
"lastError" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'),
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
);
CREATE INDEX IF NOT EXISTS "TranscriptionTask_status_nextPollAt_idx" ON "TranscriptionTask"(status, "nextPollAt");
-- Preserve an existing Chinese parser configuration. Fresh databases use simple
-- until the operator installs a Chinese parser and configures public.zhcfg.
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_ts_config c JOIN pg_namespace n ON n.oid = c.cfgnamespace
WHERE n.nspname = 'public' AND c.cfgname = 'zhcfg') THEN
CREATE TEXT SEARCH CONFIGURATION public.zhcfg (COPY = pg_catalog.simple);
END IF;
END $$;
ALTER TABLE "VideoTranscript" ADD COLUMN IF NOT EXISTS transcript_zh_tsv tsvector;
CREATE OR REPLACE FUNCTION public.refresh_video_transcript_search() RETURNS trigger AS $$
BEGIN
NEW.transcript_zh_tsv := to_tsvector('public.zhcfg'::regconfig, COALESCE(array_to_string(NEW.transcript, ' '), ''));
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Replace the legacy live trigger as well as our own trigger on repeat deployment.
DROP TRIGGER IF EXISTS trg_vt_transcript_zh_tsv ON "VideoTranscript";
DROP TRIGGER IF EXISTS video_transcript_search_update ON "VideoTranscript";
CREATE TRIGGER video_transcript_search_update BEFORE INSERT OR UPDATE OF transcript
ON "VideoTranscript" FOR EACH ROW EXECUTE FUNCTION public.refresh_video_transcript_search();
UPDATE "VideoTranscript" SET transcript_zh_tsv = to_tsvector('public.zhcfg'::regconfig, COALESCE(array_to_string(transcript, ' '), ''));
CREATE INDEX IF NOT EXISTS video_transcript_zh_idx ON "VideoTranscript" USING GIN (transcript_zh_tsv);
COMMIT;
+49 -34
View File
@@ -24,29 +24,30 @@ model Author {
}
model Video {
aweme_id String @id
desc String
preview_title String?
duration_ms Int
created_at DateTime
share_url String
digg_count BigInt @default(0)
comment_count BigInt @default(0)
share_count BigInt @default(0)
collect_count BigInt @default(0)
authorId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tags String[]
video_url String
height Int?
width Int?
cover_url String?
fps Int?
raw_json Json?
comments Comment[]
author Author @relation(fields: [authorId], references: [sec_uid], onDelete: Cascade)
transcript VideoTranscript?
aweme_id String @id
desc String
preview_title String?
duration_ms Int
created_at DateTime
share_url String
digg_count BigInt @default(0)
comment_count BigInt @default(0)
share_count BigInt @default(0)
collect_count BigInt @default(0)
authorId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
tags String[]
video_url String
height Int?
width Int?
cover_url String?
fps Int?
raw_json Json?
comments Comment[]
author Author @relation(fields: [authorId], references: [sec_uid], onDelete: Cascade)
transcript VideoTranscript?
transcriptionTask TranscriptionTask?
@@index([authorId])
@@index([created_at])
@@ -138,18 +139,32 @@ model ImageFile {
}
model VideoTranscript {
id String @id @default(cuid())
videoId String @unique
speech_detected Boolean
language String?
audio_type String?
transcript String[]
non_speech_summary String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
transcript_zh_tsv Unsupported("tsvector")?
video Video @relation(fields: [videoId], references: [aweme_id], onDelete: Cascade)
id String @id @default(cuid())
videoId String @unique
transcript String[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
transcript_zh_tsv Unsupported("tsvector")?
video Video @relation(fields: [videoId], references: [aweme_id], onDelete: Cascade)
@@index([videoId])
@@index([transcript_zh_tsv], map: "video_transcript_zh_idx", type: Gin)
}
model TranscriptionTask {
videoId String @id
status String @default("QUEUED")
providerTaskId String?
submittingAt DateTime?
submittedAt DateTime?
nextPollAt DateTime @default(now())
leaseUntil DateTime?
leaseToken String?
attempts Int @default(0)
lastError String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
video Video @relation(fields: [videoId], references: [aweme_id], onDelete: Cascade)
@@index([status, nextPollAt])
}