음성 엔진: 음성 종류 설정(voice.engine.ttsVoice) — 여/남/어린이/노인 등 음성 디자인 + 기준 음성 파일 고정으로 문장 간 음색 일관

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-20 16:40:27 +09:00
1 parent 3db0545207
commit 62c4eae8a3
3 files changed
+43 -1

No files matched your search

+3
View File
@@ -11,6 +11,7 @@ interface EngineConfig {
speakerWav: string;
device: string;
ttsSpeed: number;
ttsVoice: string;
}
function getEngineConfig(): EngineConfig {
@@ -22,6 +23,7 @@ function getEngineConfig(): EngineConfig {
speakerWav: engine.speakerWav || path.join(REPO_ROOT, '.smallclaw', 'voice', 'speaker_ko.wav'),
device: engine.device || 'cuda',
ttsSpeed: Math.min(1.4, Math.max(0.8, Number(engine.ttsSpeed) || 1.15)), // 낭독 배속(0.8~1.4)
ttsVoice: String(engine.ttsVoice || 'clone'), // clone | female | male | child | girl | boy | elderly_female | elderly_male | 영어 지시문
};
}
@@ -63,6 +65,7 @@ function spawnEngine(): ChildProcess {
'--speaker-wav', cfg.speakerWav,
'--device', cfg.device,
'--tts-speed', String(cfg.ttsSpeed),
'--tts-voice', cfg.ttsVoice,
'--stt-hotwords', buildSttHotwords(),
];
log('spawning', VENV_PYTHON, args.join(' '));
+38 -1
View File
@@ -113,7 +113,22 @@ def load_models(args):
import torch
from omnivoice import OmniVoice
tts_model = OmniVoice.from_pretrained(args.tts_model, device_map=args.device, dtype=torch.float16, load_asr=False)
voice_clone_prompt = tts_model.create_voice_clone_prompt(ref_audio=args.speaker_wav, ref_text=ref_text)
instruct = resolve_tts_voice(args.tts_voice)
if instruct:
# 음성 디자인: instruct만으로 매 문장 생성하면 문장마다 음색이 달라진다(실측 화자 유사도 0.30~0.58).
# 한 번 만든 기준 음성을 파일로 저장해 두고 그걸로 복제하면 일관된다(0.76~0.85). 다시 뽑으려면 그 파일을 지운다.
ref_path = os.path.join(os.path.dirname(args.speaker_wav) or '.', 'designed_%s.wav' % re.sub(r'[^A-Za-z0-9_-]+', '_', args.tts_voice.strip().lower())[:40])
if not os.path.exists(ref_path):
log.info('Designing voice %r (%s) -> %s', args.tts_voice, instruct, ref_path)
ref_audio = tts_model.generate(text=DESIGN_REF_TEXT, language='Korean', instruct=instruct)[0]
import wave
with wave.open(ref_path, 'wb') as w:
w.setnchannels(1); w.setsampwidth(2); w.setframerate(tts_model.sampling_rate)
w.writeframes(pcm16_from_float(np.asarray(ref_audio, dtype=np.float32)))
ref_text = DESIGN_REF_TEXT
voice_clone_prompt = tts_model.create_voice_clone_prompt(ref_audio=ref_path, ref_text=ref_text)
else:
voice_clone_prompt = tts_model.create_voice_clone_prompt(ref_audio=args.speaker_wav, ref_text=ref_text)
log.info('Warming up OmniVoice ...')
tts_model.generate(text='안녕하세요.', language='Korean', voice_clone_prompt=voice_clone_prompt)
log.info('OmniVoice ready (sample_rate=%d).', tts_model.sampling_rate)
@@ -121,6 +136,27 @@ def load_models(args):
return stt_model, tts_model, voice_clone_prompt, tts_model.sampling_rate
DESIGN_REF_TEXT = '안녕하세요. 오늘도 좋은 하루 보내세요. 필요한 게 있으면 말씀해 주세요.'
# 음성 종류(voice.engine.ttsVoice) → OmniVoice 음성 디자인 지시문. 'clone'/빈 값이면 speaker_wav 복제(기본).
TTS_VOICE_PRESETS = {
'female': 'female, young adult, moderate pitch', '여자': 'female, young adult, moderate pitch', '여성': 'female, young adult, moderate pitch',
'male': 'male, middle-aged, low pitch', '남자': 'male, middle-aged, low pitch', '남성': 'male, middle-aged, low pitch',
'child': 'child, high pitch', '어린이': 'child, high pitch', '아이': 'child, high pitch',
'girl': 'female, child, high pitch', '여자아이': 'female, child, high pitch',
'boy': 'male, child, high pitch', '남자아이': 'male, child, high pitch',
'elderly_female': 'female, elderly, moderate pitch', '할머니': 'female, elderly, moderate pitch',
'elderly_male': 'male, elderly, low pitch', '할아버지': 'male, elderly, low pitch', 'elderly': 'elderly, low pitch', '노인': 'elderly, low pitch',
}
def resolve_tts_voice(name):
"""'clone'/빈 값 → None(speaker_wav 복제). 프리셋 이름 → 지시문. 그 밖의 문자열은 영어 지시문으로 그대로 쓴다."""
n = (name or '').strip()
if not n or n.lower() in ('clone', 'default', '기본'):
return None
return TTS_VOICE_PRESETS.get(n.lower()) or TTS_VOICE_PRESETS.get(n) or n
def pcm16_from_float(audio: np.ndarray) -> bytes:
clipped = np.clip(audio, -1.0, 1.0)
return (clipped * 32767.0).astype('<i2').tobytes()
@@ -548,6 +584,7 @@ async def main():
parser.add_argument('--stt-model', default='medium')
parser.add_argument('--stt-hotwords', default='', help='Whisper hotwords (space-separated vocabulary)')
parser.add_argument('--tts-model', default='k2-fsa/OmniVoice')
parser.add_argument('--tts-voice', default='clone', help='clone | female | male | child | girl | boy | elderly_female | elderly_male | custom English instruct')
parser.add_argument('--tts-speed', type=float, default=1.15, help='TTS speed multiplier (0.8-1.4)')
parser.add_argument('--speaker-wav', default='')
parser.add_argument('--device', default='cuda')
+2
View File
@@ -378,6 +378,8 @@ export interface SmallClawConfig {
device?: string;
/** TTS 낭독 배속(0.8~1.4, 기본 1.15) */
ttsSpeed?: number;
/** 음성 종류: clone(기본, speaker_wav) | female | male | child | girl | boy | elderly_female | elderly_male | 영어 지시문 */
ttsVoice?: string;
};
ffmpegPath?: string;
maxVoiceDurationSeconds?: number;