rn-text-to-speech
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

React Native Text to Speech

Description

This module provides text-to-speech functionality for Android and iOS platforms in React Native applications.

Installation

To install this module, you can use npm or yarn:

npm install rn-text-to-speech

or

yarn add rn-text-to-speech

Usage

Importing the module First, import the module into your React Native component:

import Tts from 'rn-text-to-speech';

Speaking text To speak text, use the speak method:

Tts.speak("Hello, world!");

Pausing and resuming speech You can pause and resume speech using the pause and resume methods:

Tts.pause();
Tts.resume();

Stopping speech To stop speech, use the stop method:

Tts.stop();

Setting voice and parameters You can set voice, rate, pitch, language, and other parameters using the appropriate methods:

Tts.setDefaultVoice(voiceId);
Tts.setDefaultRate(rate);
Tts.setDefaultPitch(pitch);
Tts.setDefaultLanguage(language);

Getting available voices You can retrieve available voices using the voices method:

Tts.voices().then((voices) => {
  console.log(voices);
});

Example

Here's an example of how you might use this module in a React Native component:

import React, { useEffect } from 'react';
import { View, Button } from 'react-native';
import Tts from 'rn-text-to-speech';

const MyComponent = () => {
  useEffect(() => {
    Tts.setDefaultLanguage('en-US');
    Tts.setDefaultRate(0.5);
  }, []);

  const speakHello = () => {
    Tts.speak('Hello, world!');
  };

  return (
    <View>
      <Button title="Speak" onPress={speakHello} />
    </View>
  );
};

export default MyComponent;

License

This module is licensed under the MIT License. See the LICENSE file for details.

Package Sidebar

Install

npm i rn-text-to-speech

Weekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

251 kB

Total Files

49

Last publish

Collaborators

  • djangoamidala