Get started with voca CDN

MIT licensed

Voca is a library for text-to-speech conversion using the Web Speech API.

Tags:
  • string
  • sprintf
  • trim
  • truncate
  • pad
  • slugify
  • latinise
  • escape
  • word
  • wrap
  • case
  • strip

Stable version

Copied!

How to start using voca CDN


<!DOCTYPE html>
<html>
<head>
    <title>Get started with voca CDN - cdnhub.io</title>
    <script src="https://cdn.cdnhub.io/voca/1.4.0/voca.min.js"></script>
</head>
<body>
    <button id="speak">Speak "Hello World"</button>
    <script>
        const speakButton = document.getElementById('speak');
        const TextToSpeech = window.SpeechSynthesisUtterance;
        const synth = window.speechSynthesis;

        speakButton.addEventListener('click', () => {
            const utterance = new TextToSpeech();
            utterance.lang = 'en-US';
            utterance.text = 'Hello World';

            synth.speak(utterance);

            // Use Voca to convert text to speech in Data URL
            const text = 'Hello World';
            const voice = 'Google US English'; // or any other supported voice
            const dataURL = voca.toDataURL(text, voice);

            const audio = new Audio(dataURL);
            audio.play();
        });
    </script>
</body>
</html>
Copied!
Copied!
Copied!

All versions