|
| 1 | +/** |
| 2 | + * Tests for Azure SSML generation correctness (issue #42) |
| 3 | + */ |
| 4 | + |
| 5 | +import * as SSMLUtils from "../src/core/ssml-utils"; |
| 6 | + |
| 7 | +// Minimal stub so we can import AzureTTSClient without real credentials |
| 8 | +jest.mock("../src/core/abstract-tts", () => { |
| 9 | + return { |
| 10 | + AbstractTTSClient: class { |
| 11 | + voiceId = "en-US-AriaNeural"; |
| 12 | + lang = "en-US"; |
| 13 | + properties: Record<string, unknown> = { rate: "medium", pitch: "medium", volume: 100 }; |
| 14 | + timings: unknown[] = []; |
| 15 | + on() {} |
| 16 | + emit() {} |
| 17 | + }, |
| 18 | + }; |
| 19 | +}); |
| 20 | + |
| 21 | +// We test the SSML utilities directly — no network calls needed. |
| 22 | + |
| 23 | +describe("createProsodyTag — volume format", () => { |
| 24 | + it("emits an absolute volume value without a % suffix", () => { |
| 25 | + const result = SSMLUtils.createProsodyTag("hello", { volume: 75 }); |
| 26 | + // volume="75" is the absolute format (0-100 scale). |
| 27 | + // volume="75%" would be a relative +75% change — wrong. |
| 28 | + expect(result).toContain('volume="75"'); |
| 29 | + expect(result).not.toContain('volume="75%"'); |
| 30 | + }); |
| 31 | + |
| 32 | + it("emits volume=100 without % when at full volume", () => { |
| 33 | + const result = SSMLUtils.createProsodyTag("hello", { volume: 100 }); |
| 34 | + expect(result).toContain('volume="100"'); |
| 35 | + expect(result).not.toContain('volume="100%"'); |
| 36 | + }); |
| 37 | + |
| 38 | + it("emits volume=0 without % when muted", () => { |
| 39 | + const result = SSMLUtils.createProsodyTag("hello", { volume: 0 }); |
| 40 | + expect(result).toContain('volume="0"'); |
| 41 | + expect(result).not.toContain('volume="0%"'); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +describe("Azure prepareSSML — no spurious xmlns/version warnings", () => { |
| 46 | + let warnSpy: jest.SpyInstance; |
| 47 | + |
| 48 | + beforeEach(() => { |
| 49 | + warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {}); |
| 50 | + }); |
| 51 | + |
| 52 | + afterEach(() => { |
| 53 | + warnSpy.mockRestore(); |
| 54 | + }); |
| 55 | + |
| 56 | + it("does not warn about missing xmlns or version when synthesising plain text", async () => { |
| 57 | + // Import lazily so mock is in place |
| 58 | + const { AzureTTSClient } = await import("../src/engines/azure"); |
| 59 | + const client = new AzureTTSClient({ subscriptionKey: "key", region: "eastus" }); |
| 60 | + |
| 61 | + // Access the private method via type cast |
| 62 | + const ssml = await (client as any).prepareSSML("Hello world"); |
| 63 | + |
| 64 | + const xmnsWarning = warnSpy.mock.calls.some((args) => |
| 65 | + args.some( |
| 66 | + (a: unknown) => |
| 67 | + typeof a === "string" && a.includes("xmlns") || |
| 68 | + (Array.isArray(a) && a.some((s: unknown) => typeof s === "string" && s.includes("xmlns"))) |
| 69 | + ) |
| 70 | + ); |
| 71 | + const versionWarning = warnSpy.mock.calls.some((args) => |
| 72 | + args.some( |
| 73 | + (a: unknown) => |
| 74 | + typeof a === "string" && a.includes("version") || |
| 75 | + (Array.isArray(a) && a.some((s: unknown) => typeof s === "string" && s.includes("version"))) |
| 76 | + ) |
| 77 | + ); |
| 78 | + |
| 79 | + expect(xmnsWarning).toBe(false); |
| 80 | + expect(versionWarning).toBe(false); |
| 81 | + |
| 82 | + // Sanity: output should actually have the attributes |
| 83 | + expect(ssml).toContain('xmlns="http://www.w3.org/2001/10/synthesis"'); |
| 84 | + expect(ssml).toContain('version="1.0"'); |
| 85 | + }); |
| 86 | +}); |
0 commit comments