Where to Find Supertonic Examples: Complete Guide for All Languages

Supertonic examples are located in language-specific directories within the supertone-inc/supertonic repository, covering Python, Node.js, Java, Go, C++, C#, Swift, Rust, Flutter, and WebGPU implementations.

The supertone-inc/supertonic repository houses comprehensive Text-to-Speech (TTS) implementation examples across eleven programming languages and platforms. These Supertonic examples demonstrate how to perform on-device inference using the ONNX Runtime, with each language directory containing a complete runnable project. The top-level README includes a "Programming Language Support" table that maps each language to its corresponding directory and build requirements.

Repository Structure and Language Directories

According to the source code, examples are organized under the repository root with the following structure:

Each directory contains a dedicated README.md with step-by-step build instructions and prerequisites specific to that platform.

Python Example Implementation

The Python example in py/example_onnx.py demonstrates the minimal setup required to generate speech. The script uses the TTS class with automatic model downloading:

from supertonic import TTS

# Download model on first run

tts = TTS(auto_download=True)

style = tts.get_voice_style(voice_name="M1")
wav, duration = tts.synthesize(
    text="Supertonic is a lightning‑fast, on‑device TTS system.",
    lang="en",
    voice_style=style,
    total_steps=8,
    speed=1.05,
)
tts.save_audio(wav, "output.wav")
print(f"Generated {duration[0]:.2f}s of audio")

JavaScript and Web Browser Examples

Node.js Example

The Node.js implementation in nodejs/example.js uses the @supertone/supertonic package:

import { TTS } from '@supertone/supertonic';
const tts = new TTS({ autoDownload: true });

(async () => {
  const voice = await tts.getVoiceStyle('M1');
  const { wav, duration } = await tts.synthesize({
    text: 'Supertonic runs locally with zero network.',
    lang: 'en',
    voiceStyle: voice,
    totalSteps: 8,
    speed: 1.0,
  });
  await tts.saveAudio(wav, 'output.wav');
  console.log(`Created ${duration}s of audio`);
})();

WebGPU Browser Example

For browser-based inference, the web/src/main.ts example leverages WebGPU through onnxruntime-web:

import { TTS } from '@supertone/supertonic-web';
const tts = new TTS({ autoDownload: true });

async function synthesize() {
  const voice = await tts.getVoiceStyle('M1');
  const { wav } = await tts.synthesize({
    text: 'Supertonic in the browser!',
    lang: 'en',
    voiceStyle: voice,
  });
  // Play the resulting Float32Array in the browser
  const audioCtx = new AudioContext({ sampleRate: 44100 });
  const buffer = audioCtx.createBuffer(1, wav.length, 44100);
  buffer.copyToChannel(wav, 0);
  const source = audioCtx.createBufferSource();
  source.buffer = buffer;
  source.connect(audioCtx.destination);
  source.start();
}
synthesize();

Java and Go Examples

Java Implementation

The Java example in java/src/main/java/Example.java uses the Maven build system and Java ONNX Runtime bindings:

import com.supertone.supertonic.TTS;
import com.supertone.supertonic.VoiceStyle;

public class Example {
  public static void main(String[] args) throws Exception {
    TTS tts = new TTS(true); // autoDownload = true
    VoiceStyle style = tts.getVoiceStyle("M1");
    float[] wav = tts.synthesize(
        "Supertonic on Java.", "en", style, 8, 1.0f);
    tts.saveAudio(wav, "output.wav");
    System.out.println("Audio saved.");
  }
}

Go Implementation

The Go example in go/example_onnx.go demonstrates native module usage:

package main

import (
    "log"
    "supertone/supertonic"
)

func main() {
    tts, err := supertonic.NewTTS(true) // auto download
    if err != nil { log.Fatal(err) }
    style, _ := tts.GetVoiceStyle("M1")
    wav, dur, err := tts.Synthesize("Supertonic in Go.", "en", style, 8, 1.0)
    if err != nil { log.Fatal(err) }
    tts.SaveAudio(wav, "output.wav")
    log.Printf("Generated %.2f seconds", dur)
}

Additional Language Support

Beyond the examples above, the repository includes working implementations for:

Model Assets and Prerequisites

All examples require the ONNX model files and voice presets stored in the assets/ directory. According to the repository's Prerequisites section (lines 109-121 of the top-level README), you must clone these assets from Hugging Face separately using Git LFS. Each language-specific README.md details the exact version requirements, such as Java JDK 17 for the Maven project or .NET 9 for the C# implementation.

Summary

  • Supertonic examples are located in language-specific directories under the repository root, including py/, nodejs/, web/, java/, go/, and seven others.
  • Each example follows the same inference pattern: instantiate the TTS class with auto_download enabled, retrieve a voice style using get_voice_style(), call synthesize(), and save the output with save_audio().
  • The assets/ directory contains required model files that must be downloaded separately from Hugging Face.
  • All examples support zero-network, on-device inference using ONNX Runtime across Python, JavaScript, Java, Go, C++, C#, Swift, Rust, and mobile platforms.

Frequently Asked Questions

Where are the Supertonic Python examples located?

The Python examples are located in the py/ directory at the repository root. The main file py/example_onnx.py contains a complete inference script using ONNX Runtime, and the directory includes a pyproject.toml managed by UV for dependency resolution.

Do the Supertonic examples require an internet connection?

No. While the examples support automatic model downloading via the auto_download parameter (or autoDownload in JavaScript), once the assets are cached locally, all inference runs completely offline. The WebGPU browser example also runs entirely client-side after the initial model fetch.

Which platforms support GPU acceleration in the examples?

The WebGPU example in web/src/main.ts specifically targets browser-based GPU acceleration using onnxruntime-web. Other language examples typically use CPU inference by default, though the underlying ONNX Runtime supports GPU execution providers where configured.

How do I set up the model assets for the examples?

Clone the model assets from Hugging Face using Git LFS into the assets/ directory as described in the top-level README's Prerequisites section (lines 109-121). Each language-specific README contains additional instructions for linking or loading these assets in the respective build system.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →