Expo

Get Started
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

Installation

expo install expo-speech

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

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

export default class App extends React.Component {
  speak() {
    var thingToSay = '0';
    Speech.speak(thingToSay);
  }

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

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});

import * as Speech from 'expo-speech';

Constants

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

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

  • text (string) -- The text to be spoken. Cannot be longer than Speech.maxSpeechInputLength.
  • options (object) --
    A map of options:
    • voice (string) -- Voice identifier
    • language (string) -- The code of a language that should be used to read the text, check out IETF BCP 47 to see valid codes.
    • pitch (number) -- Pitch of the voice to speak text. 1.0 is the normal pitch.
    • rate (number) -- Rate of the voice to speak text. 1.0 is the normal rate.
    • onStart (function) -- A callback that is invoked when speaking starts.
    • onDone (function) -- A callback that is invoked when speaking finishes.
    • onStopped (function) -- A callback that is invoked when speaking is stopped by calling Speech.stop().
    • onError (function) -- (Android only). A callback that is invoked when an error occurred while speaking.

Interrupts current speech and deletes all in queue.

Pauses current speech.

Resumes speaking previously paused speech or does nothing if there's none.

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

Returns a Promise that resolves to a boolean, true if speaking, false if not.

Returns list of all available voices.

List of Voice objects.
Voice
FieldType
identifierstring
namestring
qualityenum Speech.VoiceQuality
languagestring

  • VoiceQuality.Default
  • VoiceQuality.Enhanced

An error occurred when length of text parameter provided to Speech.speak() exceeds its limit. To see the limit, use Speech.maxSpeechInputLength.