Guides
Plan-enterprise-icon
Expo Application Services
API Reference

Speech

expo-speech provides an API that allows you to utilize Text-to-speech functionality in your app.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb
Status-success-iconStatus-success-iconStatus-success-iconStatus-success-iconStatus-success-icon

Installation

Terminal
→ npx expo install expo-speech

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

Usage

Speech
import * as React from 'react';
import { View, StyleSheet, Button } from 'react-native';
import * as Speech from 'expo-speech';

export default function App() {
  const speak = () => {
    const thingToSay = '1';
    Speech.speak(thingToSay);
  };

  return (
    <View style={styles.container}>
      <Button title="Press to hear some words" onPress={speak} />
    </View>
  );
}

%%placeholder-start%%const styles = StyleSheet.create({ ... }); %%placeholder-end%%const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
});

API

import * as Speech from 'expo-speech';

Constants

Speech.maxSpeechInputLength

Type: number

Maximum possible text length acceptable by Speech.speak() method. It is platform-dependent. On iOS, this returns Number.MAX_VALUE.

Methods

Speech.getAvailableVoicesAsync()

Returns list of all available voices.

Returns

  • Undo-iconPromise<Voice[]>

List of Voice objects.

Speech.isSpeakingAsync()

Determine whether the Text-to-speech utility is currently speaking. Will return true if speaker is paused.

Returns a Promise that fulfils with a boolean, true if speaking, false if not.

Speech.pause()

Pauses current speech. This method is not available on Android.

Speech.resume()

Resumes speaking previously paused speech or does nothing if there's none. This method is not available on Android.

Speech.speak(text, options)

NameTypeDescription
textstring

The text to be spoken. Cannot be longer than Speech.maxSpeechInputLength.

options
(optional)
SpeechOptions

A SpeechOptions object.

Default: {}

Speak out loud the text given options. Calling this when another text is being spoken adds an utterance to queue.

  • Undo-iconvoid

Speech.stop()

Interrupts current speech and deletes all in queue.

Types

SpeechOptions

NameTypeDescription
_voiceIndex
(optional)
number-
language
(optional)
stringThe code of a language that should be used to read the text, refer to IETF BCP 47 to see valid codes.
onBoundary
(optional)
SpeechEventCallback | null-
onMark
(optional)
SpeechEventCallback | null-
onPause
(optional)
SpeechEventCallback | null-
onResume
(optional)
SpeechEventCallback | null-
pitch
(optional)
numberPitch of the voice to speak text. 1.0 is the normal pitch.
rate
(optional)
numberRate of the voice to speak text. 1.0 is the normal rate.
voice
(optional)
stringVoice identifier.
volume
(optional)
numberOnly for:
At-sign-iconWeb

Volume of the voice to speak text. A number between 0.0 (muted) and 1.0 (max volume)
Default: 1.0
onDone
(optional)
() => voidA callback that is invoked when speaking finishes.
onError
(optional)
(error: Error) => voidOnly for:
Android-iconAndroid

A callback that is invoked when an error occurred while speaking.
onStart
(optional)
() => voidA callback that is invoked when speaking starts.
onStopped
(optional)
() => voidA callback that is invoked when speaking is stopped by calling Speech.stop().

Voice

Object describing the available voices on the device.

NameTypeDescription
identifierstringVoice unique identifier.
languagestringVoice language.
namestringVoice name.
qualityVoiceQualityVoice quality.

WebVoice

Voice extended by:

NameTypeDescription
isDefaultboolean-
localServiceboolean-
namestring-
voiceURIstring-

Enums

VoiceQuality

Enum representing the voice quality.

VoiceQuality.Default = "Default"
VoiceQuality.Enhanced = "Enhanced"
  • Message-iconAsk a question on the forums about Speech
  • Github-iconView open bug reports for Speech
  • Code-iconView source code for Speech
  • Build-iconView package in npm Registry
  • Edit-iconEdit this page

Was this doc helpful?