Migration Guide
This guide helps you migrate from the legacy responsivevoice.js script to the modern @responsivevoice/core package.
Overview
Section titled “Overview”The new package provides:
- TypeScript support with full type definitions
- Modern build formats (ESM, CJS, browser bundle)
- Tree-shakeable exports
- Better error handling
- API-first architecture (voice data fetched at runtime)
- Full backward compatibility with the legacy API
Installation Changes
Section titled “Installation Changes”Before
Section titled “Before”<script src="https://code.responsivevoice.org/responsivevoice.js?key=YOUR_KEY"></script>The closest migration keeps a script tag — load the browser bundle from the CDN and move your key into an init() call. Use npm instead if your app has a bundler.
<script src="https://cdn.responsivevoice.org/sdk/latest/responsivevoice.js"></script><script> responsiveVoice.init({ apiKey: 'YOUR_KEY' });</script>npm install @responsivevoice/coreimport { getResponsiveVoice } from '@responsivevoice/core';
const rv = await getResponsiveVoice({ apiKey: 'YOUR_KEY' });API Mapping
Section titled “API Mapping”The core API remains the same:
| Legacy | Modern | Notes |
|---|---|---|
responsiveVoice.speak() | rv.speak() | Same signature |
responsiveVoice.cancel() | rv.cancel() | Same behavior |
responsiveVoice.pause() | rv.pause() | Same behavior |
responsiveVoice.resume() | rv.resume() | Same behavior |
responsiveVoice.getVoices() | rv.getVoices() | Same behavior |
responsiveVoice.isPlaying() | rv.isPlaying() | Same behavior |
In the browser bundle the global stays responsiveVoice; with npm you call the same methods on the rv instance from getResponsiveVoice(). The signatures are identical either way.
Configuration Changes
Section titled “Configuration Changes”Before
Section titled “Before”// Global configuration via URL parameter<script src="...?key=YOUR_KEY"></script>;
// Or via global variablewindow.responsiveVoice.setDefaultVoice('UK English Female');<script src="https://cdn.responsivevoice.org/sdk/latest/responsivevoice.js"></script><script> responsiveVoice.init({ apiKey: 'YOUR_KEY', defaultVoice: 'UK English Female', });</script>import { getResponsiveVoice } from '@responsivevoice/core';
const rv = await getResponsiveVoice({ apiKey: 'YOUR_KEY', defaultVoice: 'UK English Female',});Event System
Section titled “Event System”Per-call event callbacks are unchanged from the legacy script:
responsiveVoice.speak('Hello', 'UK English Female', { onstart: () => console.log('Started'), onend: () => console.log('Ended'),});rv.speak('Hello', 'UK English Female', { onstart: () => console.log('Started'), onend: () => console.log('Ended'),});Breaking Changes
Section titled “Breaking Changes”1. Voice Data is Fetched at Runtime
Section titled “1. Voice Data is Fetched at Runtime”Voice mappings are no longer bundled in the JavaScript file — init() fetches them from the API and caches them locally.
Impact: First initialization needs a network connection to fetch the voice catalog. There's nothing to pre-fetch — init() already loads voices before it resolves.
2. No Internet Explorer Support
Section titled “2. No Internet Explorer Support”The browser bundle (CDN) ships the polyfills modern browsers need and targets Chrome 66+, Firefox 57+, Safari 12+, Edge 17+, and iOS 12+. Internet Explorer 11 is not supported.
Impact: If you need to support IE11 or similarly old browsers, stay on the legacy responsivevoice.js (v1).
TypeScript Support
Section titled “TypeScript Support”The new package includes full TypeScript definitions:
import { getResponsiveVoice, type ResponsiveVoiceInitOptions,} from '@responsivevoice/core';import type { SpeakParams } from '@responsivevoice/types';
const options: ResponsiveVoiceInitOptions = { apiKey: 'YOUR_KEY',};
const rv = await getResponsiveVoice(options);
const params: SpeakParams = { pitch: 1.0, rate: 1.0, onend: () => console.log('Done'),};
rv.speak('Hello', 'UK English Female', params);Troubleshooting
Section titled “Troubleshooting”"Voice not found" Error
Section titled “"Voice not found" Error”
"Voice not found" Error
Section titled “"Voice not found" Error”Ensure the voice name exactly matches an available voice:
const voices = rv.getVoices();console.log(voices.map((v) => v.name));"API key required" Error
Section titled “"API key required" Error”
"API key required" Error
Section titled “"API key required" Error”Make sure to initialize with an API key:
const rv = await getResponsiveVoice({ apiKey: 'YOUR_KEY' });Audio Not Playing on iOS
Section titled “Audio Not Playing on iOS”
Audio Not Playing on iOS
Section titled “Audio Not Playing on iOS”Mobile browsers (iOS, and Android Chrome) block autoplay, but ResponsiveVoice handles this automatically with a built-in permission prompt that captures the first tap and unlocks audio. If you've disabled the prompt, trigger speech from your own gesture handler instead:
button.addEventListener('click', () => { rv.speak('Hello');});See the FAQ for details.