Skip to content

npm + Vite Example

@responsivevoice/core installed from npm and bundled for the browser by Vite. Same feature set as the Basic Example, but the library arrives via ESM import instead of a CDN <script> tag — the path modern web apps actually use.

Terminal window
npm install
npm run vite:dev
# open http://localhost:5173/
import { getResponsiveVoice } from '@responsivevoice/core';
const rv = await getResponsiveVoice();
rv.addEventListener('OnReady', () => {
rv.speak('Hello from Vite!');
});
rv.init({
// Get a free API key at https://responsivevoice.org/register
// apiKey: 'YOUR_RESPONSIVEVOICE_API_KEY',
});

getResponsiveVoice() returns the singleton instance — the same object that the CDN IIFE exposes as window.responsiveVoice. Attach listeners first, then call init() so OnReady reliably fires into your handlers.

Terminal window
npm run vite:build
npm run vite:preview