Skip to content
  • Android
  • iOS
  • Web

Text to Speech

Speak a text string with the platform’s speech synthesizer.

Examples

Quick start

Available voices depend on the platform and the installed languages.

nayan-ui/tts
import { speech } from 'nayan-ui/tts';

export async function readAloud(text: string) {
  await speech.speak(text, { language: 'en-US' });
}

Pick a voice by language

nayan-ui/tts
import { speech } from 'nayan-ui/tts';

export async function speakWithVoice(text: string, language: string) {
  const voices = await speech.getAvailableVoicesAsync();
  const voice = voices.find((item) => item.language === language)?.identifier;
  await speech.speak(text, { language, voice, rate: 0.9, pitch: 1, volume: 0.8 });
}

Pause, resume, or stop speech

nayan-ui/tts
import { speech } from 'nayan-ui/tts';

export async function controlSpeech(action: 'pause' | 'resume' | 'stop') {
  if (action === 'pause' && await speech.isSpeakingAsync()) await speech.pause();
  if (action === 'resume') await speech.resume();
  if (action === 'stop') await speech.stop();
}

Tags