모델

AWS WhisperX SageMaker:语音转录部署

The AWS WhisperX Deep Learning Container packages Whisper, wav2vec2 forced alignment, and speaker diarization into a GPU-ready image. Learn how to deploy it to Amazon SageMaker AI

본문은 SEO 깊이를 위해 주로 중국어입니다. 위는 현지화 요점입니다. 언어 전환·딥링크로 글로벌 탐색하세요.

# AWS WhisperX SageMaker:语音转录部署

AWS WhisperX Deep Learning Container 将 Whisper、wav2vec2 强制对齐和说话者二值化打包为 GPU 就绪镜像,可直接部署到 Amazon SageMaker AI 实时或异步端点。适用于需要精确时间戳和说话者标签的语音任务,如会议记录、客服电话分析和广播媒体字幕生成。

部署决策取决于音频时长:实时端点适合短片段(必须在 60 秒内完成),异步端点适合长音频或批量处理,后者支持自动扩缩零成本。选择基于任务交互性和吞吐量,无需自定义镜像即可实现专业级转录。

WhisperX 与 SageMaker 适配方案

WhisperX 在 OpenAI Whisper 基础上扩展,支持逐词时间戳和说话者识别。AWS 提供的 Deep Learning Container 已包含所有模型权重和依赖,无需 Hugging Face Token。

SageMaker AI 提供两种端点模式,满足不同场景:

维度实时端点异步端点
适用场景短交互片段(<60 秒)长音频、高量批处理
延迟同步调用,响应上限 60 秒提交后轮询,无时间限制
调用方式InvokeEndpoint(inline 体)InvokeEndpointAsync(S3 引用)
I/O请求/响应体直接传输输入输出均存 Amazon S3
扩展方式增加实例数增加实例,可自动扩缩至零
成本模式端点运行时持续计费空闲时缩零,节省成本

实时端点:适用于快速反馈场景,响应必须符合 SageMaker 60 秒上限。 异步端点:适用于长音频或批量任务,可自动扩缩至零,适合不强调即时性的分析。

环境准备

准备 AWS 账户、执行角色(需权限创建模型、端点和 S3 操作)及 GPU 配额。选择实例类型如 ml.g4dn.xlarge(成本优先)或 ml.g5.2xlarge(性能裕量)。

推荐镜像 URI 示例(us-west-2 区域,3.8.6 版本): 763104351884.dkr.ecr.us-west-2.amazonaws.com/whisperx:3.8.6-cu128-amzn2023-sagemaker

AWS Samples GitHub 仓库提供完整 JupyterLab 笔记本,可直接在 SageMaker Studio 中运行并自定义音频测试。

实时端点部署与调用

  1. 创建模型:

``python sm.create_model( ModelName="whisperx-model", PrimaryContainer={"Image": IMAGE_URI}, ExecutionRoleArn=ROLE_ARN, ) ``

  1. 创建端点配置(必须固定 InferenceAmiVersion 为 al2-ami-sagemaker-inference-gpu-3-1):

``python sm.create_endpoint_config( EndpointConfigName="whisperx-config", ProductionVariants=[{ "VariantName": "AllTraffic", "ModelName": "whisperx-model", "InitialInstanceCount": 1, "InstanceType": "ml.g4dn.xlarge", "InferenceAmiVersion": "al2-ami-sagemaker-inference-gpu-3-1", "ContainerStartupHealthCheckTimeoutInSeconds": 900, }], ) ``

  1. 创建并等待端点上线。
  1. 构建 multipart/form-data 请求(音频作为 file 部分,字段包括 language、diarize、timestamp_granularities[]、response_format):

``python resp = sm_runtime.invoke_endpoint( EndpointName="whisperx-endpoint", ContentType=content_type, Body=body, ) transcription = json.loads(resp["Body"].read) ``

端点返回 JSON 格式包含逐词时间戳和说话者标签。示例测试音频为美国航空1549号紧急降落录音,输出格式如 [00:02] SPEAKER_01: Cactus 1549, turn left heading 270.。

异步端点部署与调用

异步模式移除 60 秒限制,通过 S3 中转输入输出。

  1. 创建模型和端点配置(同样需 AMI pin,设置 MaxConcurrentInvocationsPerInstance=1):

``python sm.create_endpoint_config( EndpointConfigName="whisperx-async-config", ProductionVariants=[{...}] # 同实时配置 AsyncInferenceConfig={ "OutputConfig": { "S3OutputPath": f"s3://{BUCKET}/output/", "S3FailurePath": f"s3://{BUCKET}/failure/", }, "ClientConfig": {"MaxConcurrentInvocationsPerInstance": 1}, }, ) ``

  1. 构建请求并调用 invoke_endpoint_async(传递 S3 输入位置)。
  1. 轮询输出路径获取结果,检查失败路径。

异步端点示例输出为完整长音频转录,保留逐词和说话者信息,适合高吞吐量场景。

生产最佳实践

  • 固定 GPU AMI 版本,避免启动失败。
  • 按实例而非并发扩展(容器单请求限制)。
  • 异步端点可自动扩缩至零,结合 SNS 完成通知优化成本。
  • 优先实例池,列出多个类型自动降级。
  • S3 开启 Block Public Access 和加密,保护敏感数据。
  • 监控 CloudWatch,记录冷启动行为并重试。

成本与扩展

GPU 端点按实例小时计费。实时端点适合低频短任务,异步端点适合批量或长时间运行。建议监控实例使用率,优先异步端点空闲时缩零。

延伸阅读

  • [API 中转工具]
  • [本地部署实验室]
  • [模型天梯排行]
  • [开源部署资源]
  • [vLLM 部署指南]

风险与边界

部署于 AWS SageMaker AI 可能因计费、权限或镜像更新导致意外费用或功能变动。建议先在非生产环境测试,实际结果以官方文档为准。非法律意见,仅供参考。

English summary

AWS WhisperX SageMaker deployment delivers speaker-labeled, word-timed transcription by leveraging the official Deep Learning Container. Choose real-time endpoints for short clips under the 60-second limit or asynchronous endpoints for long audio with S3-based input/output and zero-scale cost control. Prerequisites include GPU quota and execution role. The deployment uses boto3 SDK for model registration, endpoint creation with AMI pinning, and multipart-form-data invocation. Best practices cover instance scaling, S3 security, and CloudWatch monitoring. This setup transforms raw audio into structured transcripts for contact centers, media, and regulated industries. Test with the provided GitHub notebook for your own audio files. Production costs scale with instance hours, optimized via async autoscale.

(正文字数统计:约 2480 字符)

适用于 GrokCode 倍率榜。信息仅供参考,不构成购买、投资或法律意见。