fix: TTS 중첩클릭 에코 버그 + 음성엔진 한/영 발음 개선 + 생성속도 2배

- web-ui: 🔊 버튼 연타/중첩 클릭 시 이전 요청이 완료되면서 새 요청과 오디오가
  겹쳐 재생되던 버그 수정 (playTTSText/playTTSMsg를 _ttsPlay 공용 코어로 통합,
  AbortController + 활성 버튼 가드로 stale response의 재생을 원천 차단)
- voice.tts.provider를 edge_tts(ko-KR-SunHiNeural)에서 xtts_gpu로 전환 —
  실제로는 실시간 통화와 동일한 GPU 엔진(OmniVoice)을 타서 영어 섞인 문장의
  발음이 훨씬 자연스러워짐
- voice_engine.py: OmniVoice num_step 기본값을 32→16으로 낮춤. STT 왕복
  검증으로 실측: ~1.9배 빠른 생성(2.94s→1.55s), 품질 저하 없음(8은 문장이
  깨져서 폐기). 텍스트 버튼/실시간 통화 양쪽에 공통 적용됨

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5 committed 2026-07-10 14:42:44 +09:00
1 parent f014fec7e2
commit adfa136597
3 files changed
+52 -59

No files matched your search

+6 -6
View File
@@ -21,7 +21,7 @@
"providers": {
"ollama": {
"endpoint": "http://localhost:11434",
"model": "gemma4:31b-cloud"
"model": "gemini-3-flash-preview:cloud"
},
"lm_studio": {
"endpoint": "http://host.docker.internal:1234",
@@ -45,11 +45,11 @@
}
},
"models": {
"primary": "gemma4:31b-cloud",
"primary": "gemini-3-flash-preview:cloud",
"roles": {
"manager": "gemma4:31b-cloud",
"executor": "gemma4:31b-cloud",
"verifier": "gemma4:31b-cloud",
"manager": "gemini-3-flash-preview:cloud",
"executor": "gemini-3-flash-preview:cloud",
"verifier": "gemini-3-flash-preview:cloud",
"background_task": ""
}
},
@@ -239,7 +239,7 @@
"language": "ko"
},
"tts": {
"provider": "edge_tts",
"provider": "xtts_gpu",
"model": "ko_KR-kss-medium",
"voice": "ko-KR-SunHiNeural"
},
+12 -2
View File
@@ -130,11 +130,19 @@ class Engine:
except OSError:
pass
def synthesize_full(self, text: str):
# num_step default lowered from the library default (32) to 16: measured
# ~1.9x faster generation with no detectable quality loss via STT
# round-trip (2026-07-10, see project_tts_edge memory). 8 was tested and
# rejected — clearly audible/transcribable garbling on a full clause.
def synthesize_full(self, text: str, speed=None, num_step=None):
if num_step is None:
num_step = 16
audio = self.tts_model.generate(
text=text[:4000],
language='Korean',
voice_clone_prompt=self.voice_clone_prompt,
speed=speed,
num_step=num_step,
)
pcm = pcm16_from_float(np.asarray(audio[0], dtype=np.float32))
return pcm, self._tts_sample_rate
@@ -257,8 +265,10 @@ async def handle_connection(ws, engine: Engine):
elif mtype == 'tts_synthesize_full':
text = msg.get('text', '')
speed = msg.get('speed')
num_step = msg.get('num_step')
loop = asyncio.get_event_loop()
pcm, sample_rate = await loop.run_in_executor(None, engine.synthesize_full, text)
pcm, sample_rate = await loop.run_in_executor(None, engine.synthesize_full, text, speed, num_step)
await ws.send(json.dumps({
'type': 'tts_result',
'audioBase64': base64.b64encode(pcm).decode('ascii'),
+34 -51
View File
@@ -5696,39 +5696,59 @@ function stopMicRecording() {
var _ttsEnabled = localStorage.getItem('ttsEnabled') !== 'false'; // default on
var _ttsAudio = null;
var _ttsBtnActive = null;
var _ttsAbort = null;
var _appSendFn = null;
function initAppVoice(sendFn) {
_appSendFn = sendFn || null;
}
function playTTSText(btn, text) {
text = (text||'').replace(/```[\s\S]*?```/g,'').replace(/[#*`_~>]/g,' ').replace(/\s+/g,' ').trim();
if (!text) return;
if (_ttsBtnActive === btn && _ttsAudio) {
_ttsAudio.pause(); _ttsAudio = null;
btn.textContent = '🔊'; btn.classList.remove('playing');
_ttsBtnActive = null; return;
}
// Stops whatever is currently loading/playing (abort in-flight fetch, pause audio, reset button).
function _ttsStop() {
if (_ttsAbort) { _ttsAbort.abort(); _ttsAbort = null; }
if (_ttsAudio) { _ttsAudio.pause(); _ttsAudio = null; }
if (_ttsBtnActive) { _ttsBtnActive.textContent = '🔊'; _ttsBtnActive.classList.remove('playing'); }
if (_ttsBtnActive) { _ttsBtnActive.textContent = '🔊'; _ttsBtnActive.classList.remove('playing'); _ttsBtnActive = null; }
}
// Shared core for playTTSText/playTTSMsg. Guards every async callback with a
// "is this still the active button?" check so a slow/stale response from a
// superseded click can never start overlapping playback (the echo bug).
function _ttsPlay(btn, text) {
if (!text) return;
var wasActive = (_ttsBtnActive === btn);
_ttsStop();
if (wasActive) return; // clicking the active button again = stop
btn.textContent = '⌛'; btn.classList.add('playing');
_ttsBtnActive = btn;
var ac = new AbortController();
_ttsAbort = ac;
fetch('/api/voice/tts', {
method: 'POST',
headers: Object.assign({ 'Content-Type': 'application/json' }, authHeaders()),
credentials: 'include',
body: JSON.stringify({ text: text.slice(0, 2000) }),
signal: ac.signal,
})
.then(function(r) { if (!r.ok) throw new Error(r.status); return r.blob(); })
.then(function(r) { if (!r.ok) throw new Error('TTS 오류 ' + r.status); return r.blob(); })
.then(function(blob) {
if (_ttsBtnActive !== btn) return; // superseded by a newer click
var url = URL.createObjectURL(blob);
_ttsAudio = new Audio(url);
_ttsAudio.onended = function() { URL.revokeObjectURL(url); _ttsAudio = null; btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null; };
_ttsAudio.onerror = function() { URL.revokeObjectURL(url); _ttsAudio = null; btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null; };
_ttsAudio.onended = function() { URL.revokeObjectURL(url); if (_ttsBtnActive === btn) _ttsStop(); };
_ttsAudio.onerror = function() { URL.revokeObjectURL(url); if (_ttsBtnActive === btn) _ttsStop(); };
btn.textContent = '⏹'; _ttsAudio.play();
})
.catch(function() { btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null; });
.catch(function(e) {
if (e.name === 'AbortError' || _ttsBtnActive !== btn) return;
_ttsStop();
alert('TTS 오류: ' + e.message);
});
}
function playTTSText(btn, text) {
text = (text||'').replace(/```[\s\S]*?```/g,'').replace(/[#*`_~>]/g,' ').replace(/\s+/g,' ').trim();
_ttsPlay(btn, text);
}
function updateTTSMode() {
@@ -5751,44 +5771,7 @@ function playTTSMsg(btn, idx) {
var msg = chatHistory[idx];
if (!msg) return;
var text = (msg.content || '').replace(/!\[.*?\]\(.*?\)/g, '').replace(/\[([^\]]+)\]\([^)]+\)/g, '$1').replace(/```[\s\S]*?```/g, '').replace(/[#*`_~>]/g, ' ').replace(/\s+/g, ' ').trim();
if (!text) return;
// Toggle off if same button is playing
if (_ttsBtnActive === btn && _ttsAudio) {
_ttsAudio.pause(); _ttsAudio = null;
btn.textContent = '🔊'; btn.classList.remove('playing');
_ttsBtnActive = null;
return;
}
// Stop previous
if (_ttsAudio) { _ttsAudio.pause(); _ttsAudio = null; }
if (_ttsBtnActive) { _ttsBtnActive.textContent = '🔊'; _ttsBtnActive.classList.remove('playing'); }
btn.textContent = '⌛'; btn.classList.add('playing');
_ttsBtnActive = btn;
fetch('/api/voice/tts', {
method: 'POST',
headers: Object.assign({ 'Content-Type': 'application/json' }, authHeaders()),
credentials: 'include',
body: JSON.stringify({ text: text.slice(0, 2000) }),
})
.then(function(r) { if (!r.ok) throw new Error('TTS 오류 ' + r.status); return r.blob(); })
.then(function(blob) {
var url = URL.createObjectURL(blob);
_ttsAudio = new Audio(url);
_ttsAudio.onended = function() {
URL.revokeObjectURL(url); _ttsAudio = null;
btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null;
};
_ttsAudio.onerror = function() {
URL.revokeObjectURL(url); _ttsAudio = null;
btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null;
};
btn.textContent = '⏹';
_ttsAudio.play();
})
.catch(function(e) {
btn.textContent = '🔊'; btn.classList.remove('playing'); _ttsBtnActive = null;
alert('TTS 오류: ' + e.message);
});
_ttsPlay(btn, text);
}
function saveLuckyModal() {