npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-android-text-to-speech

v1.2.3

Published

React Native Text-To-Speech wrapper module for android

Downloads

10

Readme

react-native-android-text-to-speech

Getting started

npm install --save react-native-android-text-to-speech

Mostly automatic installation

react-native link react-native-android-text-to-speech

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.echo.reactandroidtts.RNAndroidTextToSpeechPackage; to the imports at the top of the file
  • Add new RNAndroidTextToSpeechPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-android-text-to-speech'
    project(':react-native-android-text-to-speech').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-android-text-to-speech/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-android-text-to-speech')

Usage

This wrapper library's function uses Promises instead of callbacks. The ".then()" or es2016's async await(recommended) keywords should be used.

Imports

import AndroidTextToSpeech from 'react-native-tts';

Speaking

  1. Use the function AndroidTextToSpeech.speak(utterance, queueMode) to use the default TTS engine to speak. Where 'utterance' is of type string. 'queueMode' can have values - 1. "ADD" - to add to the TTS play queue. 2. "FLUSH" - to interrupt the TTS play queue with the utterance and then flush it. Returns a promise with utteranceId.

Example -

AndroidTextToSpeech.speak('Hello, world!', 'ADD');
  1. Use the function AndroidTextToSpeech.stop() to stop speaking and flush the TTS play queue. Return a promise with "success".
AndroidTextToSpeech.stop();

Ducking

Ducking is meant to lower other applications output sound level while speaking. It can be enabled by using function AndroidTextToSpeech.setDucking(enable). Where 'enable' is a boolean value. Return a promise with success.

Example-

AndroidTextToSpeech.setDucking(true)

List Attribute Information

Various lists can be retrieved regarding the TTS Engine.

  1. Installed Engines Info: Use function
AndroidTextToSpeech.getEnginesInfo();

to list all the available TTS Engines on the android device. Returns a promise with list containing strings of package names of the installed engines.

  1. Current Engine Info: Use function
AndroidTextToSpeech.getCurrentEngineInfo();

to get the name of current TTS Engine being used. Returns a promise with string of the package name of currently in use TTS engine.

  1. All Available Locales: Use function
AndroidTextToSpeech.getAvailableLocales();

to get details of all the available languages of the engine. Returns a promise with an object of the form -

{
	languageName: string;	//Language display name as given by android 
	languageCode: string;	//Language code according to ISO 639-2 standards
	coutryName: string;		//Country display name as given by android
	countryCode: string;	//Country code according to ISO 3166-1 alpha-3 standards
}
  1. Default Locale: Use Function
AndroidTextToSpeech.getDefaultLocale();

to get details of the default locale being used by the engine. Returns a promise with an object of the form -

{
	languageName: string;	//Language display name as given by android 
	languageCode: string;	//Language code according to ISO 639-2 standards
	coutryName: string;		//Country display name as given by android
	countryCode: string;	//Country code according to ISO 3166-1 alpha-3 standards
}
  1. Current Locale: Use Function
AndroidTextToSpeech.getCurrentLocale();

to get details of the current locale being used by the engine. Returns a promise with an object of the form -

{
	languageName: string;	//Language display name as given by android 
	languageCode: string;	//Language code according to ISO 639-2 standards
	coutryName: string;		//Country display name as given by android
	countryCode: string;	//Country code according to ISO 3166-1 alpha-3 standards
}
  1. All Available Voices: Use function
AndroidTextToSpeech.getAvailableVoices();

to get details of all the available voices in the engine. Returns a promise with an object of the form -

{
	voiceName: string;		//Name of the voice.
	languageName: string;	//Language display name as given by android 
	languageCode: string;	//Language code according to ISO 639-2 standards
	coutryName: string;		//Country display name as given by android
	countryCode: string;	//Country code according to ISO 3166-1 alpha-3 standards
}
  1. Current Voice: Use function
AndroidTextToSpeech.getAvailableVoices();

to get details of the current voice being used by the engine. Returns a promise with an object of the form -

{
	voiceName: string;		//Name of the voice.
	languageName: string;	//Language display name as given by android 
	languageCode: string;	//Language code according to ISO 639-2 standards
	coutryName: string;		//Country display name as given by android
	countryCode: string;	//Country code according to ISO 3166-1 alpha-3 standards
}

Set Speech Attributes

Various speech attributes can be set

  1. Language: Use function
AndroidTextToSpeech.setDefaultLangauge(languageCode);

to set the language/locale to be used by the engine. Where 'languageCode' is in the format of ISO 639-2 standards. Returns a promise with either "success" or with error depending on the language being found.

  1. Pitch: Use function
AndroidTextToSpeech.setDefaultPitch(pitch);

to set the voice pitch to be used by the engine. Where 'pitch' is speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it. Returns a promise with "success".

  1. Speech Rate: Use function
AndroidTextToSpeech.setDefaultSpeechRate(speechRate);

to set the playback speed to be used by the engine. Where 'speechRate' is speech rate. 1.0 is the normal speech rate, lower values slow down the speech (0.5 is half the normal speech rate), greater values accelerate it (2.0 is twice the normal speech rate). Returns a promise with "success".

Events

Subscibe to TTS events.

AndroidTextToSpeech.addEventListener('tts-start', (event) => console.log("start", event));
AndroidTextToSpeech.addEventListener('tts-finish', (event) => console.log("finish", event));
AndroidTextToSpeech.addEventListener('tts-cancel', (event) => console.log("cancel", event));

Example Code

async function sayHello() {
	let result = await AndroidTextToSpeech.speak("Hello World!", "ADD");
	console.log(result);
	return result;
}

async function getLanguageDetails() {
	let list = await AndroidTextToSpeech.getAvailableLocales();
	console.log(list);
	return list;
}

License

    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
                Version 2, December 2004 

Copyright (C) 2004 Sam Hocevar [email protected]

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. You just DO WHAT THE FUCK YOU WANT TO.