Speech Services via SDK Best Practices
This is the checklist to run before and after taking a Transcribe or Polly workload to production from the SDK.
Busque em todas as páginas da documentação
This is the checklist to run before and after taking a Transcribe or Polly workload to production from the SDK.
Each item is a rule stated positively, with a one-line rationale. Work top to bottom - the groups run from audio format correctness, through job sizing and cost, to reliability and security. Most rules apply whether you call these services from boto3 or the AWS SDK v3.
Declare format settings explicitly rather than relying on defaults.
# --- Python (boto3) ---
import boto3
transcribe = boto3.client("transcribe")
# Explicit format and language rather than auto-detection defaults.
transcribe.start_transcription_job(
TranscriptionJobName="support-call-4471",
Media={"MediaFileUri": "s3://my-bucket/calls/support-call-4471.wav"},
MediaFormat="wav",
LanguageCode="en-US",
OutputBucketName="my-bucket",
)// --- TypeScript (AWS SDK v3) ---
import { TranscribeClient, StartTranscriptionJobCommand } from "@aws-sdk/client-transcribe";
const transcribe = new TranscribeClient({});
// Explicit format and language rather than auto-detection defaults.
await transcribe.send(new StartTranscriptionJobCommand({
TranscriptionJobName: "support-call-4471",
Media: { MediaFileUri: "s3://my-bucket/calls/support-call-4471.wav" },
MediaFormat: "wav",
LanguageCode: "en-US",
OutputBucketName: "my-bucket",
}));standard for cost-sensitive high-volume text, neural/long-form where natural sound justifies the higher per-character price.OutputFormat: "json" call costs another request - skip it if you're only playing audio.Cache aggressively for anything that doesn't change per user.
# --- Python (boto3) ---
import hashlib
import boto3
polly = boto3.client("polly")
_cache: dict[str, bytes] = {}
def synthesize_cached(text: str, voice_id: str = "Joanna") -> bytes:
key = hashlib.sha256(f"{voice_id}:{text}".encode()).hexdigest()
if key in _cache:
return _cache[key]
response = polly.synthesize_speech(
Text=text, OutputFormat="mp3", VoiceId=voice_id, Engine="neural",
)
audio = response["AudioStream"].read()
_cache[key] = audio
return audio// --- TypeScript (AWS SDK v3) ---
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
import { createHash } from "node:crypto";
const polly = new PollyClient({});
const cache = new Map<string, Uint8Array>();
async function synthesizeCached(text: string, voiceId = "Joanna"): Promise<Uint8Array> {
const key = createHash("sha256").update(`${voiceId}:${text}`).digest("hex");
const cached = cache.get(key);
if (cached) return cached;
const response = await polly.send(new SynthesizeSpeechCommand({
Text: text, OutputFormat: "mp3", VoiceId: voiceId, Engine: "neural",
}));
const audio = await response.AudioStream?.transformToByteArray() ?? new Uint8Array();
cache.set(key, audio);
return audio;
}A mismatched MediaSampleRateHertz or MediaEncoding on a streaming session. It doesn't produce an error - it silently degrades transcription quality, which is much harder to notice and debug than an outright failure.
No. Jobs take at minimum tens of seconds, so a sub-second poll wastes API calls for no benefit. Use a multi-second interval, or better, S3 event notifications or EventBridge for job completion.
Yes, for any text that repeats - IVR menus, standard notifications, common prompts. Resynthesizing identical text on every request pays for work that never changes.
Only if you're processing real protected health information under HIPAA. The service being HIPAA-eligible is necessary but not sufficient - your account needs the BAA and your broader pipeline needs to meet your own HIPAA obligations.
Only for live display purposes like a captioning overlay. Any logic that triggers an action (routing, alerts) should wait for IsPartial: false, since partial segments can still change.
Yes. Format correctness, job sizing, caching, and reliability patterns are the same regardless of which SDK you call Transcribe or Polly from - only the syntax differs.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+).
Revisado por Chris St. John·Última atualização: 24 de jul. de 2026