Skip to main content
POST
/
v1
/
realtime
/
tts-stream
fetch('https://api.tryhamsa.com/v1/realtime/tts-stream', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Token YOUR_API_KEY'
  },
  body: JSON.stringify({ speaker: 'Ali', dialect: 'pls', text: 'Hello, world!', mulaw: false })
})
.then(response => {
  const reader = response.body.getReader();
  const chunks = [];

  function read() {
    reader.read().then(({ done, value }) => {
      if (done) {
        // Concatenate chunks and play entire stream
        const blob = new Blob(chunks, { type: 'audio/wav' });
        const url = URL.createObjectURL(blob);
        const audio = new Audio(url);
        audio.play();
        return;
      }

      chunks.push(value);
      read();
    });
  }

  read();
})
.catch(console.error);
"00000000: 52 49 46 46 FF FF FF FF 57 41 56 45 66 6D 74 20 "

Authorizations

Authorization
string
header
required

Pass the API key in the Authorization header, You need to put Token keyword before the API key. e.g. 'Authorization: Token '

Body

application/json
text
string
required

The text to be generated as an aduio file.

Example:

"مرحباً بكم في جميعاً في همسة!"

speaker
string
required

The speaker (voice) name. Pick a voice that matches the chosen dialect — see the dialect field for voice examples per dialect. You can also pass the UUID of a custom cloned voice, but you must first preload it via the Preload Cloned Voice endpoint.

Example:

"Amjad"

dialect
enum<string>

The dialect to synthesize, identified by its country/region code. Voice examples per dialect:

  • pls (Palestinian) — Amjad, Layan
  • egy (Egyptian) — Mariam, Samir
  • syr (Syrian) — Dalal, Mais
  • irq (Iraqi) — Lyali, Fatma
  • jor (Jordanian) — Lana, Jasem
  • leb (Lebanese) — Carla, Majd
  • ksa (Saudi) — Hiba, Fahd
  • uae (Emirati) — Salma, Dima
  • bah (Bahraini) — Mazen, Ruba
  • qat (Qatari) — Deema, Faisal
  • kuw (Kuwaiti) — Mai, Hatem
  • oma (Omani) — Aisha, Jaber
  • msa (Modern Standard Arabic / Fusha) — Salem, Tamim
  • ar-sa (Arabic – Gulf) — Khalid, Rahma
  • en (English) — Emma, James
Available options:
pls,
egy,
syr,
irq,
jor,
leb,
ksa,
uae,
bah,
qat,
kuw,
oma,
msa,
ar-sa,
en
Example:

"pls"

mulaw
boolean
default:false

Whether to use 'Mu-Law' algorithm in voice signal processing or not.

Example:

false

Response

Streamed Successful Response - Chunked

The response is of type file.