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);
This response does not have an example.

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 <api-key>'

Body

application/json
text
string
required

The text to be generated as an aduio file.

Example:

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

speaker
enum<string>
required

The speaker name, this field's value can be taken from the dashboard voice agents section.

Available options:
Amjad,
Lyali,
Salma,
Mariam,
Dalal,
Lana,
Jasem,
Samir,
Carla,
Nada,
Mais,
Fatma,
Hiba,
Ali,
Layan,
Khadija,
Mazen,
Dima,
Majd,
Talin,
Ahmed,
Rema,
Fahd,
Rami,
Sarah,
Faiza,
Hamdan,
Alia,
Maher,
Noor,
Majid,
Mansour,
Hind,
Hasan,
Safa,
Somaya,
Sayed,
Ruba
Example:

"Majd"

dialect
enum<string>

The dialect of each country by its country code. Recommended voices per dialect are: pls (Palestinian): Amjad, Layan, Talin, Rema, Ali; leb (Lebanese): Carla, Majd; jor (Jordanian): Lana, Jasem, Nada, Sarah; syr (Syrian): Dalal, Mais; ksa (Saudi): Hiba, Khadija, Fahd, Jasem; bah (Bahraini): Mazen, Ruba; uae (Emirati): Salma, Dima; egy (Egyptian): Mariam, Samir, Nada, Ali, Ahmed; irq (Iraqi): Lyali, Fatma.

Available options:
pls,
egy,
syr,
irq,
jor,
leb,
ksa,
uae,
bah,
qat,
msa
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.

I