txt2speech()


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

Syntax

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

Parameters

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.

Examples

Convert text to speech

Run

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