Text-To-Speech

FREEMIUM
By kynesys | Updated un mese fa | Text Analysis
Popularity

5.7 / 10

Latency

1,952ms

Service Level

100%

Health Check

N/A

Back to All Tutorials (1)

How to Consume API in Web App

This example shows how to set the use the generated Text-to-speech response as the source for an HTML video element

HTML:

When the OutputType is set to stream, the response is a buffer array which can be converted into a URL as below

JS:
var dataArr = new Uint8Array(bstream) // bstream is API response where OutputType is stream
var blob = new Blob([dataArr.buffer]);
var url = URL.createObjectURL(blob);
var audio = document.getElementById(โ€˜myplayerโ€™);
audio.src = url

When the Output type is file, a url is returned so we can simply set it
JS:
var audio = document.getElementById(โ€˜myplayerโ€™);
audio.src = url //url is API response where OutputType is file