puter.ai.txt2speech()
Converts text into speech using AI. Supports multiple languages and voices.
puter.ai.txt2speech(text)
puter.ai.txt2speech(text, language = 'en-US')
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
. The following languages are supported:
ar-AE
)ca-ES
)yue-CN
)cmn-CN
)da-DK
)nl-BE
)nl-NL
)en-AU
)en-GB
)en-IN
)en-NZ
)en-ZA
)en-US
)en-GB-WLS
)fi-FI
)fr-FR
)fr-BE
)fr-CA
)de-DE
)de-AT
)hi-IN
)is-IS
)it-IT
)ja-JP
)ko-KR
)nb-NO
)pl-PL
)pt-BR
)pt-PT
)ro-RO
)ru-RU
)es-ES
)es-MX
)es-US
)sv-SE
)tr-TR
)cy-GB
)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.
A Promise
that will resolve to an MP3 stream when the speech has been synthesized.
Convert text to speech
<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>