Skip to content

Commit 675244b

Browse files
committed
Fix emotion preview parent voice inheritance
1 parent 3c08e1d commit 675244b

6 files changed

Lines changed: 400 additions & 2126 deletions

File tree

assets/toolbox/text-to-speech/js/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,29 @@ function createDefaultTextToSpeechProfiles(voiceOptions = []) {
347347
];
348348
}
349349

350+
function isDefaultBrowserVoice(value) {
351+
return ["browser default", "default", "default browser voice"].includes(String(value || "").trim().toLowerCase());
352+
}
353+
354+
function previewVoiceForProfile({ language = "", voice = "", voiceOptions = [] } = {}) {
355+
const normalizedVoice = String(voice || "").trim();
356+
const selectedVoice = voiceOptions.find((option) => String(option.value) === normalizedVoice
357+
|| String(option.name) === normalizedVoice
358+
|| String(option.label) === normalizedVoice);
359+
if (selectedVoice) {
360+
return { defaultBrowserVoice: false, voice: selectedVoice };
361+
}
362+
if (!isDefaultBrowserVoice(normalizedVoice)) {
363+
return { defaultBrowserVoice: false, voice: null };
364+
}
365+
const selectedDefault = voiceOptions.find((option) => !language || option.language === language)
366+
|| voiceOptions[0]
367+
|| null;
368+
return { defaultBrowserVoice: true, voice: selectedDefault };
369+
}
370+
350371
function createSpeechPreviewRequest({
372+
language = TEXT_TO_SPEECH_DEFAULTS.language,
351373
pitch = TEXT_TO_SPEECH_DEFAULTS.pitch,
352374
rate = TEXT_TO_SPEECH_DEFAULTS.rate,
353375
text = "",
@@ -360,21 +382,22 @@ function createSpeechPreviewRequest({
360382
return { ok: false, message: "Speech text is required before preview." };
361383
}
362384

363-
const selectedVoice = voiceOptions.find((option) => String(option.value) === String(voice)) || null;
385+
const previewVoice = previewVoiceForProfile({ language, voice, voiceOptions });
386+
const selectedVoice = previewVoice.voice;
364387
if (!selectedVoice) {
365388
return { ok: false, message: "Select an available browser voice before preview." };
366389
}
367390

368391
return {
369-
language: selectedVoice.language || TEXT_TO_SPEECH_DEFAULTS.language,
392+
language: language || selectedVoice.language || TEXT_TO_SPEECH_DEFAULTS.language,
370393
ok: true,
371394
pitch: boundedNumber(pitch, TEXT_TO_SPEECH_RANGE_DEFAULTS.pitch),
372395
rate: boundedNumber(rate, TEXT_TO_SPEECH_RANGE_DEFAULTS.rate),
373396
speechItemId: "browser-preview",
374397
speechItemName: "Browser Preview",
375398
text: normalizedText,
376399
voice: selectedVoice.value,
377-
voiceName: selectedVoice.name || selectedVoice.label || "selected voice",
400+
voiceName: previewVoice.defaultBrowserVoice ? "Default browser voice" : selectedVoice.name || selectedVoice.label || "selected voice",
378401
volume: boundedNumber(volume, TEXT_TO_SPEECH_RANGE_DEFAULTS.volume)
379402
};
380403
}
@@ -1150,6 +1173,7 @@ function initializeTextToSpeechTool(root = document, { engine = new TextToSpeech
11501173
return;
11511174
}
11521175
const result = engine.speak({
1176+
gender: profile.gender,
11531177
language: request.language,
11541178
pitch: request.pitch,
11551179
rate: request.rate,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# PR_26177_BRAVO_004 Fix Emotion Preview Parent Voice
2+
3+
## Branch Validation
4+
5+
| Check | Result | Notes |
6+
| --- | --- | --- |
7+
| Active branch | PASS | `bravo/26177-text-to-speech` |
8+
| Did not switch to main | PASS | Work stayed on the active Bravo branch. |
9+
| Scope | PASS | Changed only Text To Speech emotion preview behavior and targeted tests. |
10+
| No governance changes | PASS | No governance docs or process files were edited. |
11+
| No `start_of_day` changes | PASS | `git status --short -- docs_build/dev/start_of_day start_of_day` returned no changed files. |
12+
13+
## Requirement Checklist
14+
15+
| Requirement | Result | Notes |
16+
| --- | --- | --- |
17+
| 1. Emotion Play inherits parent profile voice settings | PASS | Emotion preview now passes parent language, voice, gender, and age controls through the preview request/engine flow. |
18+
| 2. Default browser voice is valid for preview | PASS | `Default browser voice`, `default`, and `browser default` resolve to an available browser voice, preferring the parent profile language. |
19+
| 3. No separate emotion-row voice selection | PASS | Emotion rows still use pitch/rate/volume only; no emotion voice selector was added. |
20+
| 4. Preserve emotion settings | PASS | Pitch, rate, and volume remain sourced from the selected Emotion row. |
21+
| 5. Scope to Text To Speech V2 | PASS | The change is contained to `assets/toolbox/text-to-speech/js/index.js` and its tests. |
22+
| 6. Targeted tests | PASS | Added unit coverage for parent-profile default browser voice inheritance and Playwright coverage for the API-backed default profile Neutral play action. |
23+
| 7. No governance changes | PASS | No governance files changed. |
24+
| 8. No unrelated cleanup | PASS | Generated coverage report artifacts from the Playwright attempt were restored and not included. |
25+
| 9. No repo-wide refactors | PASS | No shared engine/core refactor was introduced. |
26+
27+
## File Inventory
28+
29+
| File | Purpose |
30+
| --- | --- |
31+
| `assets/toolbox/text-to-speech/js/index.js` | Resolves parent profile `Default browser voice` to an available browser voice for preview while keeping parent language/gender/age and emotion pitch/rate/volume. |
32+
| `tests/tools/Text2SpeechShell.test.mjs` | Adds a focused unit test proving default browser voice resolves by parent language and preserves emotion audio values. |
33+
| `tests/playwright/tools/TextToSpeechFunctional.spec.mjs` | Updates the impacted API-backed TTS profile/emotion assertions and adds a parent-default-voice Emotion Play assertion. |
34+
| `docs_build/dev/reports/codex_review.diff` | Required scoped diff report. |
35+
| `docs_build/dev/reports/codex_changed_files.txt` | Required changed-file inventory. |
36+
| `docs_build/dev/reports/PR_26177_BRAVO_004-fix-emotion-preview-parent-voice.md` | This PR-specific implementation report. |
37+
38+
## Validation Lane Report
39+
40+
| Command | Result | Notes |
41+
| --- | --- | --- |
42+
| `node --check assets/toolbox/text-to-speech/js/index.js` | PASS | Syntax check passed. |
43+
| `node --check tests/playwright/tools/TextToSpeechFunctional.spec.mjs` | PASS | Syntax check passed. |
44+
| `node --test tests/tools/Text2SpeechShell.test.mjs` | PASS | 6/6 tests passed. |
45+
| `git diff --check` | PASS | No whitespace errors. Git warned that touched test files may be normalized from LF to CRLF when Git writes them. |
46+
| `npx playwright test tests/playwright/tools/TextToSpeechFunctional.spec.mjs --project=playwright` | BLOCKED/FAIL | Browser launch failed before page runtime because Chromium is missing at `C:\Users\davidq\AppData\Local\ms-playwright\chromium-1217\chrome-win64\chrome.exe`. |
47+
48+
## Playwright Impacted Assessment
49+
50+
- Impacted spec: `tests/playwright/tools/TextToSpeechFunctional.spec.mjs`.
51+
- The spec now covers the exact issue path: expanded Default Balanced Profile, Neutral Emotion Play, parent `Default browser voice`, parent `en-US`, and no row-level voice selector.
52+
- Local execution is blocked by the missing configured Chromium binary, so browser runtime validation remains pending in an environment with Playwright browsers installed.
53+
54+
## Manual Validation Notes
55+
56+
- Manual browser validation was not completed because the configured Playwright Chromium executable is missing locally.
57+
- Source inspection confirmed Emotion rows do not add voice controls.
58+
- Source inspection confirmed the preview path does not introduce browser-owned product data, hidden defaults, or `imageDataUrl`.
59+
- Source inspection confirmed no `start_of_day` files changed.
60+
61+
## Known Issues
62+
63+
- Local Playwright browser validation remains blocked until Chromium is installed for the configured Playwright version.
64+
- No remaining implementation issue is known from focused source and unit validation for the parent-profile default voice inheritance fix.
65+
66+
## Output Files
67+
68+
- `docs_build/dev/reports/codex_review.diff`
69+
- `docs_build/dev/reports/codex_changed_files.txt`
70+
- `docs_build/dev/reports/PR_26177_BRAVO_004-fix-emotion-preview-parent-voice.md`
71+
- `tmp/PR_26177_BRAVO_004-fix-emotion-preview-parent-voice_delta.zip`
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
assets/toolbox/text-to-speech/js/index.js
2-
docs_build/database/ddl/messages.sql
3-
docs_build/dev/reports/PR_26177_BRAVO_002-complete-text-to-speech-gap-fixes.md
42
docs_build/dev/reports/codex_changed_files.txt
53
docs_build/dev/reports/codex_review.diff
6-
src/dev-runtime/messages/messages-postgres-service.mjs
7-
tests/dev-runtime/MessagesPublishValidation.test.mjs
8-
tests/playwright/tools/MessagesTool.spec.mjs
9-
tests/tools/MessagesPlaybackSource.test.mjs
4+
docs_build/dev/reports/PR_26177_BRAVO_004-fix-emotion-preview-parent-voice.md
5+
tests/playwright/tools/TextToSpeechFunctional.spec.mjs
106
tests/tools/Text2SpeechShell.test.mjs
11-
toolbox/messages/messages-api-client.js
12-
toolbox/messages/messages.js
13-
toolbox/text-to-speech/index.html

0 commit comments

Comments
 (0)