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
string
required

The speaker name, Suggestions: Amjad, Lyali, Salma, Mariam, Dalal, Lana, Jasem, Samir, Carla, Nada, or you can provide another values from the voice agents dashboard. You can also provide your own cloned voice's id here in the speaker field, but you need to preload that voice into the system first from here

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.