Skip to content

Commit 7bbd3a8

Browse files
committed
fix(mappings): /v1/audio/voices returns id/name objects (#462) to align with OpenWebUI
1 parent 4ecbfe4 commit 7bbd3a8

5 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎api/src/core/openai_mappings.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"echo": "af_v0bella",
1313
"fable": "af_sarah",
1414
"onyx": "bm_george",
15-
"nova": "bf_isabella",
15+
"nova": "bf_v0isabella",
1616
"sage": "am_michael",
1717
"shimmer": "af_sky"
1818
}

‎api/src/routers/openai_compatible.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,20 @@ async def retrieve_model(model: str):
546546

547547

548548
@router.get("/audio/voices")
549-
async def list_voices():
550-
"""List all available voices for text-to-speech"""
549+
async def list_voices(legacy: bool = False):
550+
"""List all available voices for text-to-speech.
551+
552+
Returns `[{"id": ..., "name": ...}, ...]` by default so OpenAI-compatible
553+
clients (Open WebUI in particular, which does `voice['id']` directly and
554+
silently falls back to a hardcoded 6-voice list otherwise) can render the
555+
full voice list. Pass `?legacy=true` for the pre-0.3.x plain-string shape.
556+
"""
551557
try:
552558
tts_service = await get_tts_service()
553559
voices = await tts_service.list_voices()
554-
return {"voices": voices}
560+
if legacy:
561+
return {"voices": voices}
562+
return {"voices": [{"id": v, "name": v} for v in voices]}
555563
except Exception as e:
556564
logger.error(f"Error listing voices: {str(e)}")
557565
raise HTTPException(

‎api/tests/test_openai_endpoints.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,12 @@ def test_list_voices(mock_tts_service):
402402
data = response.json()
403403
assert "voices" in data
404404
assert len(data["voices"]) == 2
405-
assert "voice1" in data["voices"]
406-
assert "voice2" in data["voices"]
405+
assert {"id": "voice1", "name": "voice1"} in data["voices"]
406+
assert {"id": "voice2", "name": "voice2"} in data["voices"]
407+
408+
legacy = client.get("/v1/audio/voices?legacy=true")
409+
assert legacy.status_code == 200
410+
assert legacy.json()["voices"] == ["voice1", "voice2"]
407411

408412

409413
@patch("api.src.routers.openai_compatible.settings")

‎ui/lib/api.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def check_api_status() -> Tuple[bool, List[str]]:
1616
timeout=30, # Increased timeout for initial startup period
1717
)
1818
response.raise_for_status()
19-
voices = response.json().get("voices", [])
19+
raw_voices = response.json().get("voices", [])
20+
voices = [v["id"] if isinstance(v, dict) else v for v in raw_voices]
2021
if voices:
2122
return True, voices
2223
print("No voices found in response")

‎web/src/services/VoiceService.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class VoiceService {
2020
throw new Error('No voices available');
2121
}
2222

23-
this.availableVoices = data.voices;
23+
this.availableVoices = data.voices.map(v => typeof v === 'string' ? v : v.id);
2424

2525
// Select first voice if none selected
2626
if (this.selectedVoices.size === 0) {

0 commit comments

Comments
 (0)