|
1 | | -import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly"; |
2 | 1 | import { buildSolutionRevealText, isExplicitSolutionRequest } from "../../src/core/tutorSolution.js"; |
3 | 2 | import { evaluateBuild } from "./buildEvaluator.js"; |
4 | 3 | import { evaluateConcept, isTrivialInteraction } from "./conceptEvaluator.js"; |
@@ -33,19 +32,27 @@ Voice delivery rules: |
33 | 32 | - Never mention hidden system logic or internal evaluation.`; |
34 | 33 |
|
35 | 34 | let pollyClient = null; |
| 35 | +let PollyClientClass = null; |
36 | 36 |
|
37 | | -function getPollyClient() { |
| 37 | +async function getPollyClient() { |
38 | 38 | if (!pollyClient) { |
39 | | - pollyClient = new PollyClient({ |
40 | | - region: process.env.AWS_REGION || "us-east-1", |
41 | | - credentials: process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY |
42 | | - ? { |
43 | | - accessKeyId: process.env.AWS_ACCESS_KEY_ID, |
44 | | - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, |
45 | | - sessionToken: process.env.AWS_SESSION_TOKEN || undefined, |
46 | | - } |
47 | | - : undefined, |
48 | | - }); |
| 39 | + try { |
| 40 | + const pollyModule = await import("@aws-sdk/client-polly"); |
| 41 | + PollyClientClass = pollyModule.PollyClient; |
| 42 | + pollyClient = new PollyClientClass({ |
| 43 | + region: process.env.AWS_REGION || "us-east-1", |
| 44 | + credentials: process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY |
| 45 | + ? { |
| 46 | + accessKeyId: process.env.AWS_ACCESS_KEY_ID, |
| 47 | + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, |
| 48 | + sessionToken: process.env.AWS_SESSION_TOKEN || undefined, |
| 49 | + } |
| 50 | + : undefined, |
| 51 | + }); |
| 52 | + } catch (err) { |
| 53 | + console.warn("AWS Polly SDK not available:", err?.message || err); |
| 54 | + return null; |
| 55 | + } |
49 | 56 | } |
50 | 57 | return pollyClient; |
51 | 58 | } |
@@ -140,7 +147,16 @@ function voiceMetaShape(meta = null) { |
140 | 147 |
|
141 | 148 | async function synthesizeAssistantAudio({ assistantText = "", voiceId = null }) { |
142 | 149 | try { |
143 | | - const pollyResponse = await getPollyClient().send(new SynthesizeSpeechCommand({ |
| 150 | + const client = await getPollyClient(); |
| 151 | + if (!client) { |
| 152 | + return { |
| 153 | + audioChunks: [], |
| 154 | + sampleRateHertz: POLLY_PCM_SAMPLE_RATE, |
| 155 | + audioFallbackUsed: true, |
| 156 | + }; |
| 157 | + } |
| 158 | + const { SynthesizeSpeechCommand } = await import("@aws-sdk/client-polly"); |
| 159 | + const pollyResponse = await client.send(new SynthesizeSpeechCommand({ |
144 | 160 | Engine: "neural", |
145 | 161 | OutputFormat: "pcm", |
146 | 162 | SampleRate: String(POLLY_PCM_SAMPLE_RATE), |
|
0 commit comments