opensi·si

Written by Enrique Hernández CalabrésLast updated 2026-10-23

Deploy Qwen3-TTS for ad voiceovers on Amazon SageMaker AI

Written by Enrique Hernández CalabrésLast updated 2026-10-23

In this notebook, we'll deploy Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice with the Hugging Face vLLM-Omni Deep Learning Container (DLC) on Amazon SageMaker. To make the example concrete, we'll use it as an ad voiceover studio: turn short marketing scripts into natural speech with a predefined speaker and optional delivery instructions. As an advanced optional path, we'll also show how to deploy the Base model for authorized voice cloning.

We'll walk through the following steps:

  • Select a text-to-speech model and a SageMaker DLC for your use case
  • Deploy the TTS model to SageMaker using the SageMaker Python SDK
  • Invoke the endpoint to generate a sample audio
  • Create a Gradio app to interact with the CustomVoice endpoint
  • Optionally deploy the Base model for authorized voice cloning
  • Optionally expose the app as an MCP server so agents can call it

For this example, you'll need AWS credentials and a SageMaker execution role. A Hugging Face token is optional for these public models, but recommended for authenticated Hub downloads from managed environments.

How a TTS model works

Text-to-speech (TTS) models convert written text into audio. Modern neural TTS systems typically encode the text, map it to acoustic features (or discrete audio tokens), and decode those features into a waveform.

Qwen3-TTS CustomVoice goes a step further: besides synthesizing speech, it lets you pick from a set of predefined premium voices and steer delivery with natural-language instructions (tone, pacing, emotion). That makes it a strong fit for ad voiceovers, where brand tone and consistency matter as much as intelligibility.

The Qwen3-TTS family also includes Base variants for voice cloning from a reference audio clip and transcript. We'll keep that as an optional advanced section because it requires a second SageMaker endpoint and should only be used with authorized voice samples.

What's vLLM-Omni

vLLM-Omni is an extension of the vLLM inference engine built for multimodal and multi-task serving. It keeps vLLM's high-throughput serving stack and adds support for additional modalities and tasks beyond classic text generation.

In this example, we'll use its text-to-speech capabilities to generate voiceovers from a script, a chosen speaker, a language, and optional delivery instructions.

Setup

To run this example, we'll install the SageMaker Python SDK for model deployment, plus huggingface_hub for authentication and gradio[mcp] for the interactive voiceover app and its MCP server.

%pip install -q "sagemaker>=3" huggingface_hub "gradio[mcp]"

We are going to need:

  • An optional HF_TOKEN: used for authenticated model downloads from Hugging Face.
  • A SageMaker execution role: used to pull the DLC from ECR and deploy the model to SageMaker.

Let's start by detecting any existing token and setting up the execution role.

>> from huggingface_hub import get_token

>> HF_TOKEN = get_token()

>> if HF_TOKEN:
...     print("HF_TOKEN_LOADED")
>> else:
...     print("No HF_TOKEN found. Public Qwen3-TTS downloads should still work.")

HF_TOKEN_LOADED

>> import os

>> import boto3
>> from sagemaker.core.helper.session_helper import Session, get_execution_role

>> REGION = boto3.Session().region_name or os.environ.get("AWS_REGION", "us-east-1")
>> boto_sess = boto3.Session(region_name=REGION)
>> sess = Session(boto_session=boto_sess)

>> try:
...     role = get_execution_role(sagemaker_session=sess)
...     print(f"Role extracted from execution role: {role}")
>> except Exception:
...     role_name = "sagemaker_execution_role"
...     iam_client = boto_sess.client("iam")
...     role = iam_client.get_role(RoleName=role_name)["Role"]["Arn"]
...     print(f"Role extracted from iam client: {role}")

Role extracted from iam client: arn:aws:iam::754289655784:role/sagemaker_execution_role

Choosing a model and a DLC

There are many TTS models on the Hugging Face Hub, from lightweight monolingual synthesizers to large multilingual systems with style control.

The main path in this notebook uses Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice, which has 9 premium speakers and instruction-based style control. Use it when a predefined voice matches the campaign.

As an optional advanced path, we'll also include Qwen/Qwen3-TTS-12Hz-1.7B-Base, which supports zero-shot voice cloning from a reference recording and transcript. Use it only with authorized voice samples.

Both models support languages such as Chinese, English, Japanese, Korean, and several European languages. We'll serve them with the Hugging Face vLLM-Omni DLC, which exposes a speech API suitable for SageMaker hosting. You can browse supported models in the vLLM-Omni docs, and other official Hugging Face DLCs on the AWS Available Images page.

We'll target an ml.g5.xlarge instance for the core CustomVoice endpoint. If you run the optional voice-cloning section, it creates a second ml.g5.xlarge endpoint. For higher concurrency or larger models, consider larger GPU instance types (for example ml.g5.2xlarge or ml.g6e.*).

from time import strftime

CUSTOM_VOICE_MODEL_ID = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
BASE_MODEL_ID = "Qwen/Qwen3-TTS-12Hz-1.7B-Base"

RESOURCE_SUFFIX = strftime("%Y%m%d-%H%M%S")

CUSTOM_VOICE_MODEL_NAME = f"qwen-tts-custom-voice-model-{RESOURCE_SUFFIX}"
CUSTOM_VOICE_ENDPOINT_CONFIG_NAME = f"qwen-tts-custom-voice-config-{RESOURCE_SUFFIX}"
CUSTOM_VOICE_ENDPOINT_NAME = f"qwen-tts-endpoint-{RESOURCE_SUFFIX}"

BASE_MODEL_NAME = f"qwen-tts-base-model-{RESOURCE_SUFFIX}"
BASE_ENDPOINT_CONFIG_NAME = f"qwen-tts-base-config-{RESOURCE_SUFFIX}"
BASE_ENDPOINT_NAME = f"qwen-tts-base-endpoint-{RESOURCE_SUFFIX}"
BASE_ENDPOINT_DEPLOYED = False

DLC = "huggingface-vllm-omni"
INSTANCE_TYPE = "ml.g5.xlarge"

In order to tell AWS which DLC we want to use, we need to specify its image_uri. As mentioned before, this URI can be found in the AWS Available Images page. If you want to obtain it programmatically, the SageMaker Python SDK also provides a helper:

>> from sagemaker.core import image_uris

>> VLLM_OMNI_IMAGE_TAG = "0.20.0-transformers5.8.1-gpu-py312-cu130-amzn2023"

>> try:
...     image_uri = image_uris.retrieve(
...         DLC,
...         region=REGION,
...         image_scope="inference",
...         instance_type=INSTANCE_TYPE,
...     )
>> except Exception as e:
...     image_uri = f"763104351884.dkr.ecr.{REGION}.amazonaws.com/huggingface-vllm-omni:{VLLM_OMNI_IMAGE_TAG}"
...     print(f"SageMaker SDK image lookup failed ({e}); using fallback URI.")

>> print(image_uri)

763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-vllm-omni:0.20.0-transformers5.8.1-gpu-py312-cu130-amzn2023

If the helper does not yet return the image URI you need (SDK catalogs can lag behind new DLC releases), set the URI explicitly to a vLLM-Omni SageMaker image in your region. Also, if you are not sure where to find the image URI, you can always check the AWS Available Images page for the latest image URIs from Hugging Face.

Deploying the model to SageMaker

Now that we have the image URI, we can deploy the model to SageMaker. The SageMaker Python SDK v3 supports several deployment styles. In this notebook we'll use the low-level resource APIs — Model, EndpointConfig, and Endpoint — which give explicit control over the container environment, instance type, and optional inference AMI.

Before creating the endpoint, we'll define the environment variables used to configure the DLC and the TTS task.

custom_voice_env_vars = {
    "HF_TASK": "text-to-speech",  # Task to perform
    "SM_VLLM_MODEL": CUSTOM_VOICE_MODEL_ID,  # Model ID
}
if HF_TOKEN:
    custom_voice_env_vars["HF_TOKEN"] = HF_TOKEN

base_env_vars = {
    **custom_voice_env_vars,
    "SM_VLLM_MODEL": BASE_MODEL_ID,
}

A few notes on those variables:

  • HF_TOKEN authenticates downloads from the Hub when a token is available.
  • HF_TASK tells the serving stack this is a text-to-speech workload.
  • SM_VLLM_MODEL selects the model loaded by the container. We define one environment for CustomVoice and one for Base voice cloning.

Each SageMaker endpoint loads one model. The core notebook creates one CustomVoice endpoint; the optional voice-cloning section creates a second Base endpoint, which incurs its own charges while it is running.

The inference_ami_version on the production variant pins the host GPU driver / CUDA stack on the instance (separate from the OS inside the container image). For ml.g5.* instances, al2-ami-sagemaker-inference-gpu-2-1 is a solid default; omit it if you prefer SageMaker's instance-type default.

Cost note: the next cell creates a billable GPU-backed SageMaker real-time endpoint. Delete it in the cleanup section when you are done.

Create the CustomVoice endpoint and wait for it to become InService:

from sagemaker.core.resources import Endpoint, EndpointConfig, Model
from sagemaker.core.shapes import ContainerDefinition, ProductionVariant

custom_voice_model = Model.create(
    model_name=CUSTOM_VOICE_MODEL_NAME,
    primary_container=ContainerDefinition(
        image=image_uri,
        environment=custom_voice_env_vars,
    ),
    execution_role_arn=role,
    region=REGION,
)

custom_voice_endpoint_config = EndpointConfig.create(
    endpoint_config_name=CUSTOM_VOICE_ENDPOINT_CONFIG_NAME,
    production_variants=[
        ProductionVariant(
            variant_name="default",
            model_name=CUSTOM_VOICE_MODEL_NAME,
            instance_type=INSTANCE_TYPE,
            initial_instance_count=1,
            inference_ami_version="al2-ami-sagemaker-inference-gpu-2-1",
        ),
    ],
    region=REGION,
)

custom_voice_endpoint = Endpoint.create(
    endpoint_name=CUSTOM_VOICE_ENDPOINT_NAME,
    endpoint_config_name=CUSTOM_VOICE_ENDPOINT_CONFIG_NAME,
    region=REGION,
)
custom_voice_endpoint.wait_for_status("InService")

Testing the endpoint

Once the endpoint is in service, we can call it with the SageMaker Runtime invoke_endpoint API. For TTS through this DLC, requests go to the speech route via CustomAttributes="route=/v1/audio/speech".

The payload expects:

  • input: the script / caption to narrate
  • voice: one of the predefined CustomVoice speakers (for example vivian, ryan, aiden)
  • language: target language (or let the model adapt)
  • instructions (optional): natural-language delivery guidance (tone, pacing, emotion)

The response body is raw WAV audio, which we can save and play back in the notebook.

Routing requests through the vLLM-Omni middleware

SageMaker sends real-time endpoint requests to the container's standard /invocations route. The vLLM-Omni DLC includes middleware that reads SageMaker's CustomAttributes request property and uses it to forward the request internally to the matching vLLM-Omni API route.

For text-to-speech, set:

CustomAttributes="route=/v1/audio/speech"

The middleware then redirects the request from SageMaker's /invocations entry point to vLLM-Omni's OpenAI-compatible /v1/audio/speech endpoint. This is why the invocation payload follows the vLLM-Omni speech API format while the request is still made through SageMaker Runtime's invoke_endpoint API.

import json

from IPython.display import Audio

client = boto_sess.client("sagemaker-runtime")

response = client.invoke_endpoint(
    EndpointName=CUSTOM_VOICE_ENDPOINT_NAME,
    ContentType="application/json",
    Body=json.dumps(
        {
            "model": CUSTOM_VOICE_MODEL_ID,
            "input": "Did you know how easy it is to deploy a model to Amazon SageMaker?",
            "voice": "vivian",
            "language": "English",
            "instructions": "Please speak in a slow and clear manner, like in a professional ad for a product.",
        }
    ),
    CustomAttributes="route=/v1/audio/speech",
)

# Save and play the generated WAV audio.
with open("custom-voice-response.wav", "wb") as f:
    f.write(response["Body"].read())

Audio("custom-voice-response.wav")

Optional: Voice cloning with Qwen3-TTS Base

Qwen/Qwen3-TTS-12Hz-1.7B-Base supports zero-shot voice cloning. Instead of selecting a predefined speaker, provide a short reference audio clip and its transcript; the model uses them to synthesize new text in a similar voice.

Only use reference audio when you have the speaker's consent and the rights to use their voice. Do not use this capability to impersonate people or create deceptive content.

The Base model is deployed to its own endpoint because a SageMaker endpoint loads a single model image and model ID at a time. Skip this section if you only need predefined CustomVoice speakers.

Cost note: running this section creates a second billable GPU-backed endpoint.

>> from sagemaker.core.resources import Endpoint, EndpointConfig, Model
>> from sagemaker.core.shapes import ContainerDefinition, ProductionVariant

>> base_model = Model.create(
...     model_name=BASE_MODEL_NAME,
...     primary_container=ContainerDefinition(
...         image=image_uri,
...         environment=base_env_vars,
...     ),
...     execution_role_arn=role,
...     region=REGION,
... )

>> base_endpoint_config = EndpointConfig.create(
...     endpoint_config_name=BASE_ENDPOINT_CONFIG_NAME,
...     production_variants=[
...         ProductionVariant(
...             variant_name="default",
...             model_name=BASE_MODEL_NAME,
...             instance_type=INSTANCE_TYPE,
...             initial_instance_count=1,
...             inference_ami_version="al2-ami-sagemaker-inference-gpu-2-1",
...         ),
...     ],
...     region=REGION,
... )

>> base_endpoint = Endpoint.create(
...     endpoint_name=BASE_ENDPOINT_NAME,
...     endpoint_config_name=BASE_ENDPOINT_CONFIG_NAME,
...     region=REGION,
... )
>> base_endpoint.wait_for_status("InService")
>> BASE_ENDPOINT_DEPLOYED = True

sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml sagemaker.config INFO - Not applying SDK defaults from location: /Users/ehcalabres/Library/Application Support/sagemaker/config.yaml

Invoke the Voice Cloning endpoint

The speech API accepts ref_audio as a URL, a data URI, or a base64-encoded audio payload. The helper below converts a local audio file into a data: URI so it can be sent in the SageMaker request. Supplying ref_text is recommended because it improves voice-cloning quality.

Set REFERENCE_AUDIO_PATH to a local WAV, MP3, or other supported reference file and replace the transcript with the words spoken in that clip.

import base64
import mimetypes
from pathlib import Path

def encode_audio_to_data_uri(audio_path):
    mime_type = mimetypes.guess_type(str(audio_path))[0] or "audio/wav"
    with open(audio_path, "rb") as f:
        encoded_audio = base64.b64encode(f.read()).decode("utf-8")
    return f"data:{mime_type};base64,{encoded_audio}"

REFERENCE_AUDIO_PATH = Path("audio_message.wav")
REFERENCE_TRANSCRIPT = "Hello, my friend Enrique, I here working while there is noise in the street and I cannot focus and I seeing people in the swimming pool right now and I'm jealous and I will have chicken for lunch today."

if not REFERENCE_AUDIO_PATH.is_file():
    raise FileNotFoundError("Set REFERENCE_AUDIO_PATH to a local audio file before running this cell.")

response = client.invoke_endpoint(
    EndpointName=BASE_ENDPOINT_NAME,
    ContentType="application/json",
    Body=json.dumps(
        {
            "model": BASE_MODEL_ID,
            "task_type": "Base",
            "input": "Hello, this is a cloned voice.",
            "voice": "default",
            "language": "English",
            "ref_audio": encode_audio_to_data_uri(REFERENCE_AUDIO_PATH),
            "ref_text": REFERENCE_TRANSCRIPT,
            "response_format": "wav",
        }
    ),
    CustomAttributes="route=/v1/audio/speech",
)

with open("cloned-voice-response.wav", "wb") as f:
    f.write(response["Body"].read())

Audio("cloned-voice-response.wav")

Note that results may vary depending on the reference audio and transcript provided to the model. If your results are not satisfactory, record a new reference audio and try again.