MLOS TTS β€’ Different Language Example Codes

For /api/tts use x-api-key: YOUR_API_KEY. Use Authorization: Bearer <JWT> only for other /api/* endpoints (e.g., /api/login, /api/protected).

Available voices: en_male_01, en_female_01  β€’ set via JSON field voice_id.

πŸ”§ cURL

curl -X POST "https://tts.bryerstone.com/api/tts" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text":"Hello from MLOS TTS!", "voice_id":"en_female_01",
        "prompt_length":1, "sampling_rate":16000,
        "output_format":"wav", "return_base64": true }' \
  -o output.wav
curl -X POST "https://tts.bryerstone.com/api/tts" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text": "Hello from MLOS!", "voice_id": "en_male_01",
        "prompt_length": 1, "sampling_rate": 16000,
        "output_format": "wav", "return_base64": false }' \
  -o audio.wav

🐍 Python (requests)

import requests
API_URL = "https://tts.bryerstone.com/api/tts"
API_KEY = "YOUR_API_KEY"

payload = {
    "text": "Hello world, this is Bryerstone TTS!",
    "voice_id": "en_female_01",  # or "en_male_01"
    "prompt_length": 1,
    "sampling_rate": 16000,
    "output_format": "wav",
    "return_base64": False
}
headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
resp = requests.post(API_URL, json=payload, headers=headers)
open("output.wav","wb").write(resp.content)
curl -X POST "https://tts.bryerstone.com/api/tts" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text":"Hello from MLOS TTS!", "voice_id":"en_female_01",
        "prompt_length":1, "sampling_rate":16000,
        "output_format":"wav", "return_base64": true }' \
  -o output.wav
resp = requests.post(url, json=payload, headers=headers) resp.raise_for_status() with open("audio.wav", "wb") as f: f.write(resp.content)

🌐 JavaScript (Browser Fetch)

fetch("https://tts.bryerstone.com/api/tts", {
  method: "POST",
  headers: {
    "x-api-key": "YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    text: "Hello from MLOS!",
    voice_id: "en_male_01",
    prompt_length: 1,
    sampling_rate: 16000,
    output_format: "wav",
    return_base64: true
  })
})
.then(async res => {
  if (!res.ok) throw new Error("HTTP " + res.status + ": " + (await res.text()));
  if ((res.headers.get("Content-Type") || "").startsWith("audio/")) {
    const blob = await res.blob();
    const url = URL.createObjectURL(blob);
    const a = document.createElement("a"); a.href = url; a.download = "audio.wav"; a.click();
    URL.revokeObjectURL(url);
  } else {
    const data = await res.json();
    const b64 = data.audio_base64 || data.data || data.audio;
    const bin = atob(b64); const bytes = new Uint8Array(bin.length);
    for (let i=0;i<bin.length;i++) bytes[i] = bin.charCodeAt(i);
    const url = URL.createObjectURL(new Blob([bytes], {type:"audio/wav"}));
    const a = document.createElement("a"); a.href = url; a.download = "audio.wav"; a.click();
    URL.revokeObjectURL(url);
  }
})
.catch(console.error);

πŸ–₯️ Node.js (Axios)

const axios = require("axios");
const fs = require("fs");

axios.post("https://tts.bryerstone.com/api/tts", {
  text: "Hello from MLOS!", voice_id: "en_male_01",
  prompt_length: 1, sampling_rate: 16000,
  output_format: "wav", return_base64: false
}, {
  headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
  responseType: "arraybuffer"
}).then(res => fs.writeFileSync("audio.wav", res.data))
  .catch(err => console.error(err.response?.status, err.response?.data?.toString?.() || err.message));

🐘 PHP (cURL)

<?php
$url = "https://tts.bryerstone.com/api/tts";
$payload = json_encode([
  "text" => "Hello from MLOS!",
  "voice_id" => "en_male_01",
  "prompt_length" => 1,
  "sampling_rate" => 16000,
  "output_format" => "wav",
  "return_base64" => false
]);

$ch = curl_init($url);
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => $payload,
  CURLOPT_HTTPHEADER => [
    "x-api-key: YOUR_API_KEY",
    "Content-Type: application/json"
  ],
]);
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($code === 200) {
  file_put_contents("audio.wav", $result);
  echo "Saved audio.wav\\n";
} else {
  echo "HTTP $code\\n$result\\n";
}

β˜• Java (HttpClient)

import java.io.FileOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class MlosTtsJavaExample {
  public static void main(String[] args) throws Exception {
    String json  = "{ \\"text\\": \\"Hello from MLOS (Java)!\\", \\"voice_id\\": \\"en_male_01\\", \\"prompt_length\\":1, \\"sampling_rate\\":16000, \\"output_format\\":\\"wav\\", \\"return_base64\\": false }";
    HttpClient client = HttpClient.newHttpClient();
    HttpRequest req = HttpRequest.newBuilder()
        .uri(URI.create("https://tts.bryerstone.com/api/tts"))
        .header("x-api-key", "YOUR_API_KEY")
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(json))
        .build();

    HttpResponse<byte[]> res = client.send(req, HttpResponse.BodyHandlers.ofByteArray());
    if (res.statusCode() == 200) {
      try (FileOutputStream fos = new FileOutputStream("audio.wav")) { fos.write(res.body()); }
      System.out.println("Saved audio.wav");
    } else {
      System.err.println("HTTP " + res.statusCode());
      System.err.println(new String(res.body()));
    }
  }
}

🐹 Go (net/http)

package main

import (
  "bytes"
  "encoding/json"
  "io"
  "log"
  "net/http"
  "os"
)

func main() {
  body := map[string]any{
    "text": "Hello from MLOS (Go)!",
    "voice_id": "en_male_01",
    "prompt_length": 1,
    "sampling_rate": 16000,
    "output_format": "wav",
    "return_base64": false,
  }
  b, _ := json.Marshal(body)

  req, _ := http.NewRequest("POST", "https://tts.bryerstone.com/api/tts", bytes.NewBuffer(b))
  req.Header.Set("x-api-key", "YOUR_API_KEY")
  req.Header.Set("Content-Type", "application/json")

  resp, err := http.DefaultClient.Do(req)
  if err != nil { log.Fatal(err) }
  defer resp.Body.Close()
  if resp.StatusCode != http.StatusOK {
    data, _ := io.ReadAll(resp.Body)
    log.Fatalf("HTTP %d: %s", resp.StatusCode, string(data))
  }

  out, _ := os.Create("audio.wav")
  defer out.Close()
  io.Copy(out, resp.Body)
  log.Println("Saved audio.wav")
}

🟣 Kotlin (OkHttp)

import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import java.nio.file.Files
import java.nio.file.Paths

fun main() {
  val client = OkHttpClient()
  val json = """
    { "text": "Hello from MLOS (Kotlin)!", "voice_id": "en_male_01",
      "prompt_length":1, "sampling_rate":16000, "output_format":"wav", "return_base64": false }
  """.trimIndent()

  val body = RequestBody.create("application/json".toMediaType(), json)
  val req = Request.Builder()
    .url("https://tts.bryerstone.com/api/tts")
    .addHeader("x-api-key", "YOUR_API_KEY")
    .addHeader("Content-Type", "application/json")
    .post(body).build()

  client.newCall(req).execute().use { res ->
    if (!res.isSuccessful) error("HTTP ${res.code}")
    Files.write(Paths.get("audio.wav"), res.body!!.bytes())
    println("Saved audio.wav")
  }
}

πŸ‡¨ C (libcurl)

Build: gcc tts.c -o tts -lcurl

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>

size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
  return fwrite(ptr, size, nmemb, (FILE*)stream);
}

int main(void) {
  const char *url   = "https://tts.bryerstone.com/api/tts";
  const char *json  = "{ \\"text\\": \\"Hello from MLOS (C)!\\", \\"voice_id\\": \\"en_male_01\\", \\"prompt_length\\":1, \\"sampling_rate\\":16000, \\"output_format\\":\\"wav\\", \\"return_base64\\": false }";
  CURL *curl = curl_easy_init(); if (!curl) { fprintf(stderr, "curl init failed\\n"); return 1; }

  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "x-api-key: YOUR_API_KEY");
  headers = curl_slist_append(headers, "Content-Type: application/json");

  FILE *out = fopen("audio.wav", "wb");
  if (!out) { fprintf(stderr, "open audio.wav failed\\n"); return 1; }

  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, out);

  CURLcode res = curl_easy_perform(curl);
  long code = 0; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);

  fclose(out); curl_slist_free_all(headers); curl_easy_cleanup(curl);
  if (res != CURLE_OK || code != 200) { fprintf(stderr, "HTTP %ld, curl: %s\\n", code, curl_easy_strerror(res)); return 1; }
  printf("Saved audio.wav\\n"); return 0;
}

πŸ‡¨++ C++ (libcurl)

#include <iostream>
#include <fstream>
#include <string>
#include <curl/curl.h>

static size_t write_data(void *ptr, size_t size, size_t nmemb, void *userdata) {
  std::ofstream *ofs = static_cast<std::ofstream*>(userdata);
  ofs->write(static_cast<char*>(ptr), size * nmemb);
  return size * nmemb;
}

int main() {
  std::string url   = "https://tts.bryerstone.com/api/tts";
  std::string json  = R"({ "text": "Hello from MLOS (C++)!", "voice_id": "en_male_01",
    "prompt_length":1, "sampling_rate":16000, "output_format":"wav", "return_base64": false })";

  CURL *curl = curl_easy_init(); if (!curl) { std::cerr << "curl init failed\\n"; return 1; }
  struct curl_slist *headers = nullptr;
  headers = curl_slist_append(headers, "x-api-key: YOUR_API_KEY");
  headers = curl_slist_append(headers, "Content-Type: application/json");

  std::ofstream ofs("audio.wav", std::ios::binary);
  if (!ofs) { std::cerr << "open audio.wav failed\\n"; return 1; }

  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ofs);

  CURLcode res = curl_easy_perform(curl);
  long code = 0; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);

  ofs.close(); curl_slist_free_all(headers); curl_easy_cleanup(curl);
  if (res != CURLE_OK || code != 200) { std::cerr << "HTTP " << code << ", curl: " << curl_easy_strerror(res) << "\\n"; return 1; }
  std::cout << "Saved audio.wav\\n"; return 0;
}

🟦 C# (.NET 6+)

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program {
  static async Task Main() {
    var url  = "https://tts.bryerstone.com/api/tts";
    var json = "{ \\"text\\": \\"Hello from MLOS (C#)!\\", \\"voice_id\\": \\"en_male_01\\", \\"prompt_length\\":1, \\"sampling_rate\\":16000, \\"output_format\\":\\"wav\\", \\"return_base64\\": false }";

    using var client = new HttpClient();
    client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
    using var content = new StringContent(json, Encoding.UTF8, "application/json");
    using var res = await client.PostAsync(url, content);

    if (!res.IsSuccessStatusCode) {
      var err = await res.Content.ReadAsStringAsync();
      Console.Error.WriteLine($"HTTP {(int)res.StatusCode}: {err}");
      return;
    }
    var bytes = await res.Content.ReadAsByteArrayAsync();
    await File.WriteAllBytesAsync("audio.wav", bytes);
    Console.WriteLine("Saved audio.wav");
  }
}

🟨 TypeScript (Node + Axios)

Install: npm i axios β€’ Node 18+ recommended

import axios from "axios";
import { writeFileSync } from "fs";

const URL = "https://tts.bryerstone.com/api/tts";

async function main() {
  try {
    const res = await axios.post(URL,
      { text: "Hello from MLOS (TypeScript)!", voice_id: "en_male_01",
        prompt_length: 1, sampling_rate: 16000, output_format: "wav", return_base64: false },
      {
        headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
        responseType: "arraybuffer",
      }
    );
    writeFileSync("audio.wav", res.data);
    console.log("Saved audio.wav");
  } catch (e: any) {
    console.error("Error:", e.response?.status, e.response?.data?.toString?.() || e.message);
  }
}
main();

🟦 Flutter (Dart)

import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart';

Future<void> synthesizeFlutter() async {
  final uri = Uri.parse("https://tts.bryerstone.com/api/tts");
  final body = '{"text":"Hello from Flutter!","voice_id":"en_male_01","prompt_length":1,"sampling_rate":16000,"output_format":"wav","return_base64":false}';

  final res = await http.post(
    uri,
    headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
    body: body,
  );

  if (res.statusCode != 200) { print("HTTP ${res.statusCode}: ${res.body}"); throw Exception("TTS failed"); }

  final dir = await getTemporaryDirectory();
  final file = File("${dir.path}/audio.wav");
  await file.writeAsBytes(res.bodyBytes);
  print("Saved: ${file.path}");
}

πŸ“± React Native

import RNFS from "react-native-fs";

function arrayBufferToBase64(buffer) {
  let binary = ""; const bytes = new Uint8Array(buffer);
  for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
  return global.btoa(binary);
}

export async function synthesizeReactNative() {
  const res = await fetch("https://tts.bryerstone.com/api/tts", {
    method: "POST",
    headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
    body: JSON.stringify({ text: "Hello from React Native!", voice_id: "en_male_01", prompt_length:1, sampling_rate:16000, output_format:"wav", return_base64:false }),
  });
  if (!res.ok) { const txt = await res.text(); throw new Error(`HTTP ${res.status}: ${txt}`); }
  const buf = await res.arrayBuffer();
  const b64 = arrayBufferToBase64(buf);
  const path = `${RNFS.DocumentDirectoryPath}/audio.wav`;
  await RNFS.writeFile(path, b64, "base64");
  console.log("Saved:", path);
}

βš›οΈ React (Web)

import React, { useState } from "react";

export default function TtsButton() {
  const [loading, setLoading] = useState(false);
  async function handleClick() {
    setLoading(true);
    try {
      const res = await fetch("https://tts.bryerstone.com/api/tts", {
        method: "POST",
        headers: { "x-api-key": "YOUR_API_KEY", "Content-Type": "application/json" },
        body: JSON.stringify({ text: "Hello from React!", voice_id: "en_male_01", prompt_length:1, sampling_rate:16000, output_format:"wav", return_base64:false }),
      });
      if (!res.ok) throw new Error(`HTTP ${res.status}`);
      const blob = await res.blob();
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a"); a.href = url; a.download = "audio.wav"; a.click();
      URL.revokeObjectURL(url);
    } finally { setLoading(false); }
  }
  return <button onClick={handleClick} disabled={loading}>{loading ? "Synthesizing..." : "Synthesize (React)"}</button>;
}

πŸ›οΈ MUMPS – InterSystems IRIS / CachΓ©

Uses $ZF(-1) to shell to curl. Uses API key header.

TTS    ; IRIS/CachΓ© M routine to call MLOS TTS via curl
        NEW url,out,payload,cmd,sc
        SET url="https://tts.bryerstone.com/api/tts"
        SET out="/tmp/audio.wav"
        SET payload="{""text"":""Hello from MUMPS (IRIS)!"",""voice_id"":""en_male_01"",""prompt_length"":1,""sampling_rate"":16000,""output_format"":""wav"",""return_base64"":false}"
        SET cmd="curl -sS -X POST """_url_""" "_
     "-H ""x-api-key: YOUR_API_KEY"" "_
     "-H ""Content-Type: application/json"" "_
     "-d '"_payload_"' -o "_out
        SET sc=$ZF(-1,cmd)
        WRITE "curl exit status: ",sc,!
        WRITE "Saved to: ",out,!
        QUIT

πŸ›οΈ MUMPS – GT.M / YottaDB

TTSGTM  ; GT.M/YottaDB routine to call MLOS TTS via curl
        NEW cmd
        SET cmd="curl -sS -X POST 'https://tts.bryerstone.com/api/tts' "_
     "-H 'x-api-key: YOUR_API_KEY' "_
     "-H 'Content-Type: application/json' "_
     "-d '{""text"":""Hello from MUMPS (GT.M)!"",""voice_id"":""en_male_01"",""prompt_length"":1,""sampling_rate"":16000,""output_format"":""wav"",""return_base64"":false}' "_
     "-o /tmp/audio.wav"
        ZSY cmd
        WRITE "Requested synthesis. Check /tmp/audio.wav",!
        QUIT

🏦 COBOL (GnuCOBOL – via curl)

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TTSAPI.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-CMD    PIC X(1024).
       PROCEDURE DIVISION.
           MOVE "curl -sS -X POST 'https://tts.bryerstone.com/api/tts' "  TO WS-CMD
           STRING WS-CMD DELIMITED BY SIZE
                  "-H 'x-api-key: YOUR_API_KEY' "
                  "-H 'Content-Type: application/json' "
                  "-d '{""text"":""Hello from COBOL!"",""voice_id"":""en_male_01"",""prompt_length"":1,""sampling_rate"":16000,""output_format"":""wav"",""return_base64"":false}' "
                  "-o audio.wav"
                  INTO WS-CMD
           END-STRING
           CALL "SYSTEM" USING BY REFERENCE WS-CMD
           DISPLAY "Saved audio.wav"
           STOP RUN.

βš™οΈ Assembly (NASM, Linux x86-64)

Demo stub β€” ensure you send header x-api-key: YOUR_API_KEY in your HTTP request.

; Demo outline only. For production use HTTPS (OpenSSL) and proper TCP connect/send/recv.
; Ensure request includes:
;   Content-Type: application/json
;   x-api-key: YOUR_API_KEY
; and a JSON body with the TTSRequest fields shown above.