Converts text into speech using AI. Supports multiple languages and voices.


Code copied
puter.ai.txt2speech(text, language = 'en-US', testMode = false)


text (String) (required)

A string containing the text you want to convert to speech. The text must be less than 3000 characters long.

language (String) (optional)

The language to use for speech synthesis. Defaults to en-US.

testMode (Boolean) (Optional)

A boolean indicating whether you want to use the test API. Defaults to false. This is useful for testing your code without using up API credits.

Return value

A Promise that will resolve to an MP3 stream when the speech has been synthesized.


Convert text to speech

Code copied
    <script src="https://js.puter.com/v2/"></script>
    <button id="play">Speak!</button>
        document.getElementById('play').addEventListener('click', ()=>{
            puter.ai.txt2speech(`Hello world! Puter is pretty amazing, don't you agree?`).then((audio)=>{