mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 17:19:52 +08:00
fix: fall back to configured expert voice when TTS discovery is empty
OpenAI-compatible TTS providers expose no voice-listing endpoint, so voice discovery returns nothing and the audio overview pipeline fails with 'Configure distinct host and expert voices' even when the active model has a voice configured. The chat entry point cannot recover because it never sends per-request voices. Add an optional expert_voice to the TTS catalog model (settings UI field + runtime resolution) and let the audio overview fall back to the catalog's voice/expert_voice pair when discovery yields no choices, with an explicit distinctness check.
This commit is contained in:
@@ -423,9 +423,14 @@ class AudioOverviewPipeline:
|
||||
choices = voice_model_options(tts.provider_name, "tts", tts.model).get("voices", [])
|
||||
host_voice = host_voice or tts.voice
|
||||
expert_voice = expert_voice or next(
|
||||
(str(item["id"]) for item in choices if item.get("id") != host_voice), None
|
||||
(str(item["id"]) for item in choices if str(item["id"]) != host_voice),
|
||||
None,
|
||||
)
|
||||
if not host_voice or not expert_voice:
|
||||
# Providers without live voice discovery report no choices, so the
|
||||
# catalog's own voices are the only way to pick a second speaker.
|
||||
expert_voice = expert_voice or (tts.expert_voice or None)
|
||||
host_voice = host_voice or (tts.expert_voice or None)
|
||||
if not host_voice or not expert_voice or host_voice == expert_voice:
|
||||
raise AudioOverviewError(
|
||||
"Configure distinct host and expert voices for the active TTS model."
|
||||
)
|
||||
|
||||
@@ -1383,6 +1383,7 @@ def resolve_tts_runtime_config(
|
||||
|
||||
options = voice_model_options(provider, "tts", resolved_model)
|
||||
voice = _as_str((model or {}).get("voice"))
|
||||
expert_voice = _as_str((model or {}).get("expert_voice"))
|
||||
response_format = _as_str((model or {}).get("response_format")) or options["formats"][0]
|
||||
raw_speed = (model or {}).get("speed")
|
||||
speed = _coerce_optional_float(raw_speed)
|
||||
@@ -1404,6 +1405,7 @@ def resolve_tts_runtime_config(
|
||||
api_version=_as_str((profile or {}).get("api_version")) or None,
|
||||
extra_headers=_to_headers((profile or {}).get("extra_headers")),
|
||||
voice=voice,
|
||||
expert_voice=expert_voice,
|
||||
response_format=response_format,
|
||||
speed=speed,
|
||||
language=_as_str((model or {}).get("language")) or None,
|
||||
|
||||
@@ -58,6 +58,10 @@ class TTSConfig:
|
||||
api_version: str | None = None
|
||||
extra_headers: dict[str, str] = field(default_factory=dict)
|
||||
voice: str = ""
|
||||
# Optional second configured voice. Providers without live voice discovery
|
||||
# (anything OpenAI-compatible) still need two distinct voices for the two-
|
||||
# speaker audio overview, so the catalog can state one explicitly.
|
||||
expert_voice: str = ""
|
||||
response_format: str = "mp3"
|
||||
speed: float | None = None
|
||||
language: str | None = None
|
||||
|
||||
@@ -16,6 +16,8 @@ from deeptutor.capabilities.audio_overview.capability import AudioOverviewCapabi
|
||||
from deeptutor.capabilities.audio_overview.pipeline import (
|
||||
AudioOverviewError,
|
||||
AudioOverviewPipeline,
|
||||
AudioOverviewScript,
|
||||
SourceCitation,
|
||||
_render_audio,
|
||||
normalize_rag_result,
|
||||
parse_script,
|
||||
@@ -243,6 +245,131 @@ async def test_pipeline_generates_two_voices_and_publishes_workspace_items(
|
||||
]
|
||||
|
||||
|
||||
def _two_speaker_pipeline(tmp_path: Path) -> AudioOverviewPipeline:
|
||||
# No injected speech_func: exercises the runtime path that resolves
|
||||
# voices from the catalog, like the real server does.
|
||||
return AudioOverviewPipeline(
|
||||
language="en",
|
||||
system_prompt="Return JSON.",
|
||||
instruction_prompt="Create the overview.",
|
||||
workspace_output_dir=tmp_path,
|
||||
)
|
||||
|
||||
|
||||
async def _silent_speech(text: str, **kwargs: Any) -> tuple[bytes, str]:
|
||||
buffer = io.BytesIO()
|
||||
with wave.open(buffer, "wb") as output:
|
||||
output.setnchannels(1)
|
||||
output.setsampwidth(2)
|
||||
output.setframerate(24000)
|
||||
output.writeframes(b"\x00\x00" * 2400)
|
||||
return buffer.getvalue(), "audio/wav"
|
||||
|
||||
|
||||
def _two_speaker_inputs() -> tuple[Any, Any]:
|
||||
script = AudioOverviewScript(
|
||||
title="Voices",
|
||||
segments=[
|
||||
{"speaker": "host", "text": "Let's begin.", "source_ids": []},
|
||||
{"speaker": "expert", "text": "Backoff controls retries.", "source_ids": []},
|
||||
],
|
||||
)
|
||||
context = SimpleNamespace(citations=[])
|
||||
return script, context
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_publish_falls_back_to_configured_voices_without_voice_discovery(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""OpenAI-compatible providers report no voices, so the catalog decides."""
|
||||
|
||||
import deeptutor.services.config.provider_runtime as provider_runtime
|
||||
import deeptutor.services.voice.options as voice_options
|
||||
|
||||
monkeypatch.setattr(
|
||||
provider_runtime,
|
||||
"resolve_tts_runtime_config",
|
||||
lambda: SimpleNamespace(
|
||||
provider_name="openai",
|
||||
model="some-tts",
|
||||
voice="female",
|
||||
expert_voice="male",
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
voice_options,
|
||||
"voice_model_options",
|
||||
lambda provider, service, model: {"voices": []},
|
||||
)
|
||||
|
||||
used_voices: list[str] = []
|
||||
|
||||
async def fake_speech(text: str, **kwargs: Any) -> tuple[bytes, str]:
|
||||
used_voices.append(str(kwargs.get("voice")))
|
||||
return await _silent_speech(text, **kwargs)
|
||||
|
||||
import deeptutor.services.voice as voice_module
|
||||
|
||||
monkeypatch.setattr(voice_module, "synthesize_speech", fake_speech)
|
||||
|
||||
script, context = _two_speaker_inputs()
|
||||
pipeline = _two_speaker_pipeline(tmp_path)
|
||||
|
||||
await pipeline.publish(
|
||||
turn_id="turn-voices",
|
||||
script=script,
|
||||
context=context,
|
||||
request_config=AudioOverviewRequestConfig(),
|
||||
)
|
||||
|
||||
assert used_voices == ["female", "male"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_publish_names_the_two_voice_requirement_when_nothing_is_configured(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
import deeptutor.services.config.provider_runtime as provider_runtime
|
||||
import deeptutor.services.voice.options as voice_options
|
||||
|
||||
monkeypatch.setattr(
|
||||
provider_runtime,
|
||||
"resolve_tts_runtime_config",
|
||||
lambda: SimpleNamespace(
|
||||
provider_name="openai",
|
||||
model="some-tts",
|
||||
voice="female",
|
||||
expert_voice="",
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
voice_options,
|
||||
"voice_model_options",
|
||||
lambda provider, service, model: {"voices": []},
|
||||
)
|
||||
|
||||
async def unused_speech(text: str, **kwargs: Any) -> tuple[bytes, str]:
|
||||
raise AssertionError("no audio should be requested without two voices")
|
||||
|
||||
import deeptutor.services.voice as voice_module
|
||||
|
||||
monkeypatch.setattr(voice_module, "synthesize_speech", unused_speech)
|
||||
|
||||
script, context = _two_speaker_inputs()
|
||||
pipeline = _two_speaker_pipeline(tmp_path)
|
||||
|
||||
with pytest.raises(AudioOverviewError, match="distinct host and expert voices"):
|
||||
await pipeline.publish(
|
||||
turn_id="turn-voices",
|
||||
script=script,
|
||||
context=context,
|
||||
request_config=AudioOverviewRequestConfig(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_capability_publishes_two_workspace_attachments() -> None:
|
||||
async def fake_retrieve(self, **kwargs: Any) -> Any:
|
||||
|
||||
@@ -30,6 +30,7 @@ export function VoiceModelFields({
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const speedId = useId()
|
||||
const expertVoiceId = useId()
|
||||
const instructionId = useId()
|
||||
const timeoutId = useId()
|
||||
const languages = preset?.languages ?? []
|
||||
@@ -73,6 +74,25 @@ export function VoiceModelFields({
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{service === 'tts' && (
|
||||
<div className="space-y-1.5">
|
||||
<label htmlFor={expertVoiceId} className="text-xs font-medium">
|
||||
{t('Expert voice')}
|
||||
</label>
|
||||
<input
|
||||
id={expertVoiceId}
|
||||
type="text"
|
||||
className={inputClass}
|
||||
disabled={disabled}
|
||||
value={model.expert_voice ?? ''}
|
||||
placeholder={t('Voice ID from your speech provider')}
|
||||
onChange={e => update('expert_voice', e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-[var(--muted-foreground)]">
|
||||
{t('Second speaker for audio overviews when your provider lists no voices.')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{(service === 'stt' || Boolean(preset?.languages.length)) && (
|
||||
<RegistryModelIdField
|
||||
label={t('Speech language')}
|
||||
|
||||
@@ -62,6 +62,9 @@ export type CatalogModel = {
|
||||
// codec (mp3/wav/...) and is reused by imagegen ("url"/"b64_json").
|
||||
// `language` is an optional STT hint.
|
||||
voice?: string;
|
||||
// Second TTS voice for two-speaker audio overviews when the provider has
|
||||
// no live voice discovery (anything OpenAI-compatible).
|
||||
expert_voice?: string;
|
||||
speed?: string;
|
||||
sample_rate?: string;
|
||||
instructions?: string;
|
||||
|
||||
@@ -6201,6 +6201,7 @@
|
||||
"Accept": "Accept",
|
||||
"Host voice": "Host voice",
|
||||
"Expert voice": "Expert voice",
|
||||
"Second speaker for audio overviews when your provider lists no voices.": "Second speaker for audio overviews when your provider lists no voices.",
|
||||
"Duration (minutes)": "Duration (minutes)",
|
||||
"Voice ID from your speech provider": "Voice ID from your speech provider",
|
||||
"Configure distinct host and expert voices for the active TTS model.": "Configure distinct host and expert voices for the active TTS model.",
|
||||
|
||||
@@ -6201,6 +6201,7 @@
|
||||
"Accept": "接受",
|
||||
"Host voice": "主持人声线",
|
||||
"Expert voice": "专家声线",
|
||||
"Second speaker for audio overviews when your provider lists no voices.": "音频概览中的第二说话人,适用于语音服务未提供声线列表时。",
|
||||
"Duration (minutes)": "时长(分钟)",
|
||||
"Voice ID from your speech provider": "填写语音服务支持的声线 ID",
|
||||
"Configure distinct host and expert voices for the active TTS model.": "请为当前语音模型配置两个不同的主持人和专家声线。",
|
||||
|
||||
Reference in New Issue
Block a user