Skip to main content
Convert a chat message to speech and stream the audio. Audio is generated via our TTS provider on first request and cached automatically — subsequent requests are served from cache with no added latency.
The response is raw PCM audio: 32-bit float, little-endian, mono, 44100 Hz. You will need to decode it before playback. See the Playback section below for browser and mobile examples.

Request

Authorization
string
required
Bearer token obtained from the authenticate endpoint.
message_id
string
required
ID of the chat message to synthesize. The message must belong to your organization.

Response

Returns a streaming application/octet-stream body of raw PCM audio.
PropertyValue
EncodingPCM float32, little-endian
Sample rate44100 Hz
ChannelsMono

Playback

Browser (Web Audio API)

async function playMessageAudio(messageId, token) {
  const response = await fetch(
    `https://api.trellis.sh/v1/tts/messages/${messageId}/audio`,
    { headers: { Authorization: `Bearer ${token}` } }
  );

  const pcmBuffer = await response.arrayBuffer();
  const audioCtx = new AudioContext({ sampleRate: 44100 });

  // Decode raw float32 PCM
  const float32 = new Float32Array(pcmBuffer);
  const audioBuffer = audioCtx.createBuffer(1, float32.length, 44100);
  audioBuffer.copyToChannel(float32, 0);

  const source = audioCtx.createBufferSource();
  source.buffer = audioBuffer;
  source.connect(audioCtx.destination);
  source.start();
}

React Native (Expo AV)

import { Audio } from "expo-av";
import * as FileSystem from "expo-file-system";

async function playMessageAudio(messageId, token) {
  const localPath = FileSystem.cacheDirectory + `${messageId}.pcm`;

  await FileSystem.downloadAsync(
    `https://api.trellis.sh/v1/tts/messages/${messageId}/audio`,
    localPath,
    { headers: { Authorization: `Bearer ${token}` } }
  );

  const { sound } = await Audio.Sound.createAsync({ uri: localPath });
  await sound.playAsync();
}
curl -X GET "https://api.trellis.sh/v1/tts/messages/8f14e45f-ceea-467f-a83c-0a06b8901a45/audio" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  --output message_audio.pcm
<binary PCM audio stream>