Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ jobs:
node --check portal/static/js/youtube-connect.js
node --check portal/static/js/youtube-source.js
node --check portal/static/js/translation-fit.js
node --check portal/static/js/voice-fit.js
node --check portal/static/js/modal-dialog.js
node --check portal/static/js/developer.js
node --check portal/static/js/live-demo.js
Expand All @@ -323,6 +324,7 @@ jobs:
node tests/test_lang_picker.mjs
node tests/test_tabs.mjs
node tests/test_translation_fit.mjs
node tests/test_voice_fit.mjs
node tests/test_program_sender_source.mjs
node tests/test_youtube_connect.mjs
node tests/test_youtube_source.mjs
Expand Down
11 changes: 11 additions & 0 deletions portal/room_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class EngineCatalog:
locked_translation: tuple[str, ...] = ()
# Why a provider the server can't run is missing, by provider, so a saved booth can say so.
unavailable_reasons: dict[str, str] = field(default_factory=dict)
# The voice services the event has no key for, by provider, so the setup can name one that speaks a language.
locked_voice: tuple[str, ...] = ()

@property
def locked_voice_support(self) -> dict[str, list[str]]:
"""The languages each voice service the event has no key for can speak, by brand name, for the setup form."""
return {brand_name(provider): sorted(voice_languages_for(provider)) for provider in self.locked_voice}

@property
def voice_support(self) -> dict[str, list[str]]:
Expand Down Expand Up @@ -270,6 +277,7 @@ def engine_catalog(event: Event) -> EngineCatalog:
locked: list[str] = []
locked_speech: list[str] = []
locked_translation: list[str] = []
locked_voice: list[str] = []
unavailable: list[str] = []
unavailable_reasons: dict[str, str] = {}

Expand Down Expand Up @@ -321,11 +329,13 @@ def engine_catalog(event: Event) -> EngineCatalog:
voice.append(Engine("deepgram", "aura", "Deepgram Aura", _KEY_ADDED))
else:
locked.append(_BRANDS["deepgram"])
locked_voice.append("deepgram")
if event.encrypted_elevenlabs_api_key:
# Deepgram Aura has no Thai voice; Eleven v4 speaks Thai and 90+ other languages.
voice.append(Engine("elevenlabs", "eleven_v4", "ElevenLabs v4", _KEY_ADDED))
else:
locked.append(_BRANDS["elevenlabs"])
locked_voice.append("elevenlabs")
if find_spec("supertonic") is not None:
voice.append(Engine("supertonic", "supertonic", "Supertonic (built in)", _SELF_HOSTED))
else:
Expand All @@ -340,6 +350,7 @@ def engine_catalog(event: Event) -> EngineCatalog:
tuple(locked_speech),
tuple(locked_translation),
unavailable_reasons,
tuple(locked_voice),
)


Expand Down
30 changes: 11 additions & 19 deletions portal/static/js/room-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// speaker's own words and stay on whenever a language uses AI.

import { syncTranslationOptions } from './translation-fit.js';
import { listNames, voiceProblem as voiceFit } from './voice-fit.js';

const root = document.getElementById('room-setup');
const form = document.getElementById('room-setup-form');
Expand All @@ -26,6 +27,8 @@ if (root && form) {
const liveCodes = new Set(readJson(root.dataset.liveCodes || '[]', []));
const deliveryLabels = readJson(root.dataset.deliveryLabels || '{}', {});
const voiceSupport = readJson(root.dataset.voiceSupport || '{}', {});
// Voice services the event has no key for yet, by name, with the languages each can speak.
const lockedVoiceSupport = readJson(root.dataset.lockedVoiceSupport || '{}', {});
const translationSupport = readJson(root.dataset.translationSupport || '{}', {});

const steps = [...form.querySelectorAll('[data-rs-step]')];
Expand Down Expand Up @@ -74,11 +77,6 @@ if (root && form) {
const voiceLanguages = () => languages().filter((l) => l.delivery === 'ai_voice');
const spokenName = () => selectedText(spokenSelect) || 'the room\'s language';

function listNames(names) {
if (names.length < 2) return names.join('');
return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
}

// ── AI voice support ───────────────────────────────────────────────────

const voiceEngines = () => [...(voiceSelect?.options || [])].map((opt) => ({
Expand All @@ -88,20 +86,14 @@ if (root && form) {
const speaks = (provider, code) => (voiceSupport[provider] || []).includes(code);

// Why an AI voice can't be offered for this language with the services chosen, or ''.
function voiceProblem(code) {
const engines = voiceEngines();
if (!engines.length) {
return `AI voice isn't available for this event yet: no voice service is set up. Choose AI captions, or add a Deepgram key on the event's API keys page.`;
}
const chosen = engines.find((e) => e.provider === voiceSelect.value) || engines[0];
if (speaks(chosen.provider, code)) return '';
const name = nameOf(code);
const others = engines.filter((e) => e !== chosen && speaks(e.provider, code));
if (others.length) {
return `${chosen.label} can't speak ${name}. Choose AI captions, or switch the voice to ${others[0].label} under AI services in the review step.`;
}
return `AI voice isn't supported for ${name} yet. None of this event's voice services can speak it. Choose AI captions so listeners can read ${name}, or Interpreter.`;
}
const voiceProblem = (code) => voiceFit({
engines: voiceEngines(),
selected: voiceSelect?.value,
support: voiceSupport,
lockedSupport: lockedVoiceSupport,
code,
name: nameOf(code),
});

// A language with no voice service that can speak it can't use AI voice at all.
const voiceImpossible = (code) => !voiceEngines().some((e) => speaks(e.provider, code));
Expand Down
38 changes: 38 additions & 0 deletions portal/static/js/voice-fit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Why an AI voice cannot be offered for a language with the voice services an event has, kept apart
// from the room setup page so it can be tested without a DOM.

// "A", "A and B", "A, B and C".
export function listNames(names) {
if (names.length < 2) return names.join('');
return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
}

// The warning for one language, or '' when the chosen voice service can speak it.
// engines: the voice services the event can use now, as {provider, label}
// selected: the provider chosen on the page
// support: the languages each of those services speaks, by provider
// lockedSupport: the languages each service the event has no key for speaks, by name
export function voiceProblem({ engines, selected, support, lockedSupport, code, name }) {
const speaks = (provider) => (support[provider] || []).includes(code);
// Services the event could add a key for that do speak this language.
const addable = Object.keys(lockedSupport).filter((brand) => (lockedSupport[brand] || []).includes(code));
const addKey = `${listNames(addable)} can speak ${name}: add ${addable.length > 1 ? 'a key' : 'its key'} on the event's API keys page.`;
const captions = `choose AI captions so listeners can read ${name}, or Interpreter`;

if (!engines.length) {
if (addable.length) {
return `AI voice isn't available for this event yet: no voice service is set up. ${addKey} Until then, ${captions}.`;
}
return `AI voice isn't available for this event yet: no voice service is set up. Choose AI captions, or add a Deepgram key on the event's API keys page.`;
}
const chosen = engines.find((e) => e.provider === selected) || engines[0];
if (speaks(chosen.provider)) return '';
const others = engines.filter((e) => e !== chosen && speaks(e.provider));
if (others.length) {
return `${chosen.label} can't speak ${name}. Choose AI captions, or switch the voice to ${others[0].label} under AI services in the review step.`;
}
if (addable.length) {
return `AI voice for ${name} isn't supported by the voice services set up for this event. ${addKey} Until then, ${captions}.`;
}
return `AI voice isn't supported for ${name} yet. None of the voice services this server offers can speak it. Choose AI captions so listeners can read ${name}, or Interpreter.`;
}
1 change: 1 addition & 0 deletions portal/templates/admin/room_setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
data-booth-codes='{{ booth_codes | tojson }}'
data-live-codes='{{ live_codes | tojson }}'
data-voice-support='{{ catalog.voice_support | tojson }}'
data-locked-voice-support='{{ catalog.locked_voice_support | tojson }}'
data-translation-support='{{ catalog.translation_support | tojson }}'
data-delivery-labels='{{ delivery_labels | tojson }}'>

Expand Down
12 changes: 12 additions & 0 deletions tests/test_room_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,3 +1281,15 @@ def handle_endtag(self, tag):


_VOID_TAGS = {"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"}


def test_locked_voice_support_names_services_still_to_set_up():
"""The setup can tell a Thai talk that ElevenLabs speaks it once its key is added."""
catalog = engine_catalog(_event(encrypted_deepgram_api_key=encrypt_val("k")))
assert "th" in catalog.locked_voice_support["ElevenLabs"]
assert "Deepgram" not in catalog.locked_voice_support

catalog = engine_catalog(
_event(encrypted_deepgram_api_key=encrypt_val("k"), encrypted_elevenlabs_api_key=encrypt_val("k"))
)
assert catalog.locked_voice_support == {}
70 changes: 70 additions & 0 deletions tests/test_voice_fit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Unit tests for the AI voice warning on the room setup page (portal/static/js/voice-fit.js).
*
* Run with: node tests/test_voice_fit.mjs
*/
import assert from 'node:assert/strict';

import { listNames, voiceProblem } from '../portal/static/js/voice-fit.js';

const deepgram = { provider: 'deepgram', label: 'Deepgram Aura' };
const supertonic = { provider: 'supertonic', label: 'Supertonic (built in)' };
const support = { deepgram: ['fr', 'es'], supertonic: ['fr', 'es', 'hi'] };
const lockedSupport = { ElevenLabs: ['th', 'hi', 'fr'] };
const ask = (overrides) => voiceProblem({
engines: [deepgram], selected: 'deepgram', support, lockedSupport: {}, code: 'fr', name: 'French', ...overrides,
});

assert.equal(listNames([]), '');
assert.equal(listNames(['A']), 'A');
assert.equal(listNames(['A', 'B']), 'A and B');
assert.equal(listNames(['A', 'B', 'C']), 'A, B and C');

// The chosen service speaks it: no warning.
assert.equal(ask({}), '');

// A service the event has no key for speaks it: name it and point to the API keys page.
{
const text = ask({ code: 'th', name: 'Thai', lockedSupport });
assert.match(text, /isn't supported by the voice services set up for this event/);
assert.match(text, /ElevenLabs can speak Thai: add its key on the event's API keys page/);
assert.match(text, /AI captions/);
assert.doesNotMatch(text, /None of/);
}

// Two such services share the sentence.
{
const text = ask({ code: 'th', name: 'Thai', lockedSupport: { ElevenLabs: ['th'], Acme: ['th'] } });
assert.match(text, /ElevenLabs and Acme can speak Thai: add a key/);
}

// Only services that speak this language are named.
assert.doesNotMatch(ask({ code: 'th', name: 'Thai', lockedSupport: { ElevenLabs: ['th'], Acme: ['fr'] } }), /Acme/);

// Nothing speaks it, set up or not: a plain message, no service named.
{
const text = ask({ code: 'zz', name: 'Zulu', lockedSupport });
assert.match(text, /isn't supported for Zulu yet/);
assert.doesNotMatch(text, /ElevenLabs/);
}

// Another service already set up speaks it: switch to it.
{
const text = ask({ engines: [deepgram, supertonic], code: 'hi', name: 'Hindi', lockedSupport });
assert.match(text, /Deepgram Aura can't speak Hindi/);
assert.match(text, /switch the voice to Supertonic/);
}

// No voice service is set up, and one the event could add speaks the language (the review comment on #1447):
// the advice names that service instead of a Deepgram key that would not help.
{
const text = ask({ engines: [], code: 'th', name: 'Thai', lockedSupport });
assert.match(text, /no voice service is set up/);
assert.match(text, /ElevenLabs can speak Thai: add its key on the event's API keys page/);
assert.doesNotMatch(text, /Deepgram key/);
}

// No voice service is set up and none that could be added speaks it: the general advice.
assert.match(ask({ engines: [], code: 'zz', name: 'Zulu', lockedSupport }), /add a Deepgram key/);

console.log('voice-fit.js: ok');
Loading