Spaces:
Running
Running
File size: 3,798 Bytes
aa9892b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | -- 031_user_voice_prompts.sql (2026-05-18, Phase 2 of CosyVoice 3.0 ๋ค์ค ์์ง).
--
-- engine ๋ณ voice_clone_prompt ์์ ์บ์ฑ ๋งคํ.
--
-- ๋ฐฐ๊ฒฝ: sql/024 ์ user_voices.embedding_storage_path ๋ ๋จ์ผ ์์ง (Qwen3) ๊ฐ์ .
-- CosyVoice 3.0 (Phase 1 admin spawn ์๋ฃ) ๊ฐ์ ๋ค๋ฅธ ์์ง์ด ์ถ๊ฐ๋๋ฉด์, ๊ฐ์
-- ref_audio ์์ ์์ง๋ณ๋ก ๋ค๋ฅธ prompt ๊ฐ ๋ง๋ค์ด์ง๋ค (Qwen3 = ICL prompt items
-- dict, CosyVoice = campplus 192-dim speaker embedding). ํ ์ฌ์ฉ์ voice ๊ฐ ๋
-- ์์ง ๋ชจ๋ prompt ์บ์๋ฅผ ๊ฐ์ง ์ ์์ด์ผ ํ๋ค.
--
-- ์ค๊ณ:
-- - ๋ณ๋ ๋งคํ ํ
์ด๋ธ (PK = user_id + voice_name + engine_kind)
-- - ๊ธฐ์กด user_voices.embedding_storage_path ๋ ํธํ์ฑ ์ํด ์ ์ง (Qwen3 fast-path)
-- - ๋ฐฑํ: ๊ธฐ์กด embedding_storage_path ๊ฐ ์ฑ์์ง row โ engine_kind='qwen3' ๋ก ๋งคํ
--
-- ํ๊ท 0 ๊ฐ๋:
-- - ๊ธฐ์กด ์ฝ๋ ๊ฒฝ๋ก (`update_voice_embedding_path` + `user_voices.embedding_storage_path`)
-- ๋ ๊ทธ๋๋ก ๋์ (Qwen3 ํธํ). ์ ๋งคํ ํ
์ด๋ธ์ ์ถ๊ฐ ์ ๋ณด์ผ ๋ฟ.
-- - ์ ์์ง prompt ๊ฐ ์์ผ๋ฉด polling ์ผ๋ก ์ row ๊ฐ ์๊ธด ๋ค์ set_voice_clone ์
-- ์ฌ์ฉ. ๊ทธ ์ฌ์ด์ ref_audio b64 ํด๋ฐฑ (์์ ๋ง).
--
-- ์ฐธ์กฐ:
-- - doc/runbook/tts_engine_multi.md Phase 2 (voice_clone_prompt ์บ์ฑ ๋ถ๊ธฐ)
-- - doc/runbook/tts_prompt_cache.md (Qwen3 prompt ์บ์ฑ ๊ธฐ์กด ํ๋ฆ)
-- - doc/runbook/voice_dual_register.md (4๋จ๊ณ UI ํธํ)
CREATE TABLE IF NOT EXISTS public.user_voice_prompts (
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
voice_name TEXT NOT NULL,
engine_kind TEXT NOT NULL,
storage_path TEXT NOT NULL,
ref_transcript TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (user_id, voice_name, engine_kind),
CONSTRAINT user_voice_prompts_engine_kind_check
CHECK (engine_kind IN ('qwen3', 'cosyvoice35'))
);
CREATE INDEX IF NOT EXISTS idx_user_voice_prompts_engine
ON public.user_voice_prompts (engine_kind, user_id);
COMMENT ON TABLE public.user_voice_prompts IS
'์์ง๋ณ voice_clone_prompt ์์ ์บ์ฑ ๋งคํ. ๊ฐ์ (user_id, voice_name) ๊ฐ ์ฌ๋ฌ engine_kind ์ prompt ๋ฅผ ๋์ ๋ณด์ ๊ฐ๋ฅ. ์์ธํ ๋ฐฐ๊ฒฝ์ doc/runbook/tts_engine_multi.md Phase 2.';
COMMENT ON COLUMN public.user_voice_prompts.engine_kind IS
'TTS ์์ง ์ข
๋ฅ. qwen3 (์ด์ default) | cosyvoice35 (Phase 1 beta). tts_scale_instances.engine_kind ์ ๋์ผ enum.';
COMMENT ON COLUMN public.user_voice_prompts.storage_path IS
'voice-clones bucket ์ prompt ํ์ผ ๊ฒฝ๋ก. ์: <user_id>/<stem>.qwen3.prompt.pt ๋๋ <user_id>/<stem>.cosyvoice35.prompt.pt';
COMMENT ON COLUMN public.user_voice_prompts.ref_transcript IS
'์ถ์ถ ์์ ์ ref_text ์ค๋
์ท. ๋ณ๊ฒฝ๋๋ฉด prompt ์ฌ์ถ์ถ ํธ๋ฆฌ๊ฑฐ (apply_dual_register).';
-- ๋ฐฑํ: ๊ธฐ์กด user_voices.embedding_storage_path ๊ฐ NOT NULL ์ธ row ๋ฅผ qwen3 ๋ก ๋งคํ.
-- (์ฒด์ด๋๋์ด๋ ON CONFLICT DO NOTHING ์ผ๋ก idempotent.)
INSERT INTO public.user_voice_prompts (user_id, voice_name, engine_kind, storage_path, ref_transcript)
SELECT user_id, name, 'qwen3', embedding_storage_path, transcript
FROM public.user_voices
WHERE embedding_storage_path IS NOT NULL AND embedding_storage_path <> ''
ON CONFLICT (user_id, voice_name, engine_kind) DO NOTHING;
-- RLS โ user_voices ์ ๋์ผ ์ ์ฑ
(๋ณธ์ธ ๋ฐ์ดํฐ๋ง).
ALTER TABLE public.user_voice_prompts ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS user_voice_prompts_owner ON public.user_voice_prompts;
CREATE POLICY user_voice_prompts_owner ON public.user_voice_prompts
FOR ALL
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);
|