Skip to main content
You can convert text to speech (TTS) by using Serverless AI. To do so:
  1. Create a Docker image powered by the Piper engine for TTS.
  2. Run a fine-tuning job based on this image. This job produces an Open Neural Network Exchange (ONNX) model for TTS.
  3. Deploy the model as a Serverless AI endpoint.
  4. Synthesize speech from text by using the deployed model.

Costs

Nebius AI Cloud charges you for the following billing items:

Prerequisites

Make sure you are in a group that has at least the editor role within your tenant or project; for example, the default editors group. You can check this in the Administration → IAM section of the web console.

Steps

Prepare infrastructure

Locate all resources in the same project.
  1. Create a CPU-only VM. The VM is required to build the Docker image based on the VM’s Linux operating system (OS). If you build the image on a non-Linux OS, the image architecture will be incompatible with Serverless AI, and the fine-tuning job will fail. Configure SSH access to the VM so that you can connect to it later.
    1. In the web console, go to ComputeVirtual machines.
    2. Click Create resourceVirtual machine.
    3. On the page that opens, set the following VM configuration:
      • Computing resources: Without GPU.
      • Platform: Non-GPU AMD EPYC Genoa.
      • Preset: 16 CPUs — 64 GiB RAM.
      • Boot disk size: At least 100 GiB.
      • Public IP address: Auto assign dynamic IP.
      • Username and SSH key: Configure access credentials.
    4. Click Create VM.
  2. Create a bucket to store fine-tuning artifacts.
    1. In the web console, go to  Storage → Object Storage.
    2. Click  Create bucket.
    3. In the Maximum size field, select Unlimited. Leave the other settings at their default values.
    4. Click Create bucket.

Prepare a dataset

On a local machine, prepare a dataset for training the ONNX model. After that, upload the dataset to the bucket.
  1. Create a working directory:
  2. Create and activate a virtual Python environment:
  3. In this environment, install the required Python dependencies for the dataset preparation:
  4. Install FFmpeg. This is a tool that allows you to record and convert audio, and that is required for TorchCodec. You can install FFmpeg by running conda install "ffmpeg" or brew install "ffmpeg" (macOS only).
  5. Download five training samples from Hugging Face:
  6. After the script prints Done, check that the samples are downloaded:
    The output should be the following:
  7. Upload the input folder to the bucket created earlier:
    1. In the web console, go to  Storage → Object Storage.
    2. Open the bucket page.
    3. Create the /mnt/data/input/raw directory. To do so, click Add → Folder for every directory in this path.
    4. Go to /mnt/data/input/raw and then click Add → Object.
    5. Upload the samples.

Prepare files for the Docker image

  1. To connect to the VM, get its public IP address:
    1. In the web console, go to ComputeVirtual machines.
    2. On the Standalone VMs tab, open the VM page.
    3. In Network → Public IPv4, copy the address.
  2. Connect to the VM by using SSH:
    Specify the username that you set when creating the VM.
  3. On the VM, create a working directory:
  4. In this directory, create the following files for building the Docker image:
    To verify that all files are present, run ls or tree.

Build and push the Docker image

On the VM:
  1. Install Docker.
  2. Install additional packages and prepare Docker for building the image:
  3. Check that the Docker daemon is running:
    If Docker is running, this command returns a table of containers (can be empty). If you don’t see the table and the daemon isn’t running, launch it.
  4. Create an account in Docker Hub. Use it for authentication when you push your image to a repository.
  5. Create a public repository in Docker Hub. You will push your Docker image there.
  6. In the ~/piper-nebius directory, build the image:
    In the command, specify your public repository. For example, myrepository/tts:piper-nebius-ui-tutorial. This operation can take several minutes to complete.
  7. Authenticate in Docker Hub:
    Specify your username at Docker Hub and enter your password when prompted.
  8. Push the image to the repository:
    This operation can take several minutes to complete.

Create and deploy the ONNX model by using a Serverless AI job and endpoint

  1. Create a fine-tuning job that generates the ONNX model:
    1. In the web console, go to  Serverless AI → Jobs.
    2. Click  Create job.
    3. On the page that opens, specify the following job parameters:
      • Image path: <repository>/<image>:piper-nebius-ui-tutorial. Set the image that you’ve pushed to the Docker repository.
      • Entrypoint command:
        • --raw-dir /mnt/data/input/raw: Matches the uploaded files.
        • --work-dir /tmp/work: Properly saves files to Object Storage.
        • --output-dir /mnt/data/output: Saves the exported ONNX model to the mounted volume.
        • --no-base-ckpt: Helps avoid checkpoint compatibility problems in the dataset path.
        • --batch-size 4 --num-workers 0: Make standard settings for a small dataset.
      • Computing resources: Keep the predefined settings.
      • Mount volumes: Bucket.
      • Mount path: /mnt/data. After that, click  Attach bucket and then select the bucket created earlier.
    4. Click Create.
    After the job reaches the Complete status, the files output/model.onnx and output/model.onnx.json are created in the bucket. These files contain the produced model.
  2. Deploy the model on a Serverless AI endpoint:
    1. In the web console, go to  Serverless AI → Endpoints.
    2. Click  Create endpoint.
    3. On the page that opens, specify the following endpoint parameters:
      • Image path: <repository>/<image>:piper-nebius-ui-tutorial. Set the image that you’ve pushed to the Docker repository.
      • Ports: 8000.
      • Entrypoint command:
      • Computing resources: Keep the predefined settings.
      • Mount volumes: Bucket.
      • Mount path: /mnt/data. After that, click  Attach bucket and then select the bucket created earlier.
      • IP address: Public static IP.
    4. Click Create.
    Wait until the endpoint reaches the Running status.

Synthesize speech

  1. Get the endpoint’s managed HTTPS URL:
    1. In the web console, go to  Serverless AI → Endpoints.
    2. Open the page of the deployed endpoint.
    3. Copy the managed HTTPS URL (https://...) from the Network → Public endpoints field.
  2. To verify the endpoint health, run a health check:
    Expected output:
    The "ok":true message shows that the endpoint is healthy.
  3. To synthesize speech, call the endpoint:
    The method generates the speech.wav file with the recorded Hello world phrase. The audio quality can be low because only five samples from a dataset were used to train the model. That is expected because the tutorial’s purpose is only to showcase the process of the speech synthesis. To improve the audio quality, use a bigger dataset and more samples for the model training.

How to delete the created resources

Some of the created resources are chargeable. If you don’t need them, delete these resources, so Nebius AI Cloud doesn’t charge for them:
  • CPU-only VM.
  • Boot disk attached to the VM.
  • Bucket.
  • Endpoint. When you delete an endpoint, Serverless AI automatically deletes the endpoint VM and container (boot) disk.