Coder Social home page Coder Social logo

react-native-speech's Introduction

React Native Speech

npm version npm downloads Code Climate

React Native Speech is a text-to-speech library for React Native.

Documentation

Install

npm i --save react-native-speech

Usage

Linking the Library

In order to use Speech, you must first link the library your project. There's excellent documentation on how to do this in the React Native Docs.

Speaking an Utterance

Once you've linked the library, you'll want to make it available to your app by requiring it:

var Speech = require('react-native-speech');

Speaking an utterance is as simple as calling:

Speech.speak({
  text: 'React Native Speech is awesome!  I\'m going to use it in my next project.',
  voice: 'en-US'
});

Example

Using Speech in your app will usually look like this:

var Speech = require('react-native-speech');

var YourComponent = React.createClass({
  _startHandler() {
    Speech.speak({
      text: 'Aujourd\'hui, Maman est morte. Ou peut-être hier, je ne sais pas.',
      voice: 'fr-FR'
    })
    .then(started => {
      console.log('Speech started');
    })
    .catch(error => {
      console.log('You\'ve already started a speech instance.');
    });
  },

  _pauseHandler() {
    Speech.pause();
  },

  _resumeHandler() {
    Speech.resume();
  },

  _stopHandler() {
    Speech.stop();
  },

  render() {
    return (
      <View>
        ...
        <Button onPress={this._startHandler}>
          Speak
        </Button>
        <Button onPress={this._pauseHandler}>
          Pause
        </Button>
        <Button onPress={this._resumeHandler}>
          Resume
        </Button>
        <Button onPress={this._stopHandler}>
          Stop
        </Button>
      </View>
    );
  }
});

Methods

speak(utterance)

Initializes the speech instance and speaks the utterance provided.

Arguments

  • utterance - An Object containing the following keys: text, voice and, optionally, rate. rate is a float where lower numbers indicate slower speech.

Examples

Speech.speak({
  text: 'I was runnin\' through the 6 with my woes',
  voice: 'en-US',
  rate: 0.4
})
.then(started => {
  // Success code
})
.catch(error => {
  // Failure code
});
Speech.speak({
  text: 'I was runnin\' through the 6 with my woes',
  voice: 'en-US'
});

pause()

Pauses the speech instance.

Example

Speech.pause();

resume()

Resumes the speech instance.

Example

Speech.resume();

stop()

Stops and destroys the speech instance.

Example

Speech.stop();

isSpeaking()

Indicates whether speech is in progress.

Example

Speech.isSpeaking()
  .then(speaking => {
    console.log(speaking); // true or false
  });

isPaused()

Indicates whether speech is paused.

Example

Speech.isPaused()
  .then(paused => {
    console.log(paused); // true or false
  });

supportedVoices()

Indicates which speech voices are available.

Example

Speech.supportedVoices()
  .then(locales => {
    console.log(locales); // ["ar-SA", "en-ZA", "nl-BE", "en-AU", "th-TH", ...]
  });

License

Copyright (c) 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

react-native-speech's People

Contributors

alekseiko avatar naoufal avatar tannewt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-speech's Issues

Is this repository maintained?

Just curious because I see a lot of unchecked issues and un-answered concerns (especially for android support).

I would be happy to help close some issues or add some features if you are short on time. Thanks for an awesome iOS component! 😄

Not working in device

Good Morning
when I run the code listed (excerpt) in the emulator it plays ok .when I run it in my device (ipad) does not play any sound .My ios for both is IOS 10.2

....
var Speech = require('react-native-speech');
...

rowPressedF(){
//start
Speech.speak({
text: 'Welcome',
voice: 'en-GB'
});
Thanks

Wont Archive - Need to Add Search Header [WITH FIX]

You need to search the node_modules during archive or it will fail. Add this to the pbxproj file in the xcodeproj

 "$(SRCROOT)/../../node_modules/react-native/React/**",

If you don't do this step you will get the error that RCTBridge not Found.

Sounds stupid

Super slow - cant seem to change the utterance rate? Takes like 6 seconds to say a sentence with weird pauses.

Can you add gender option?

Speech.speak({
  text: 'React Native Speech is awesome!  I\'m going to use it in my next project.',
  voice: 'en-US',
  gender: 'female'
});

evaluating NativeSpeechSynthesizer .stopSpeakingAtBoundary

Hey, still new to coding but got this error undefined is not an object('evaluating NativeSpeechSynthesizer .stopSpeakingAtBoundary') . tried updating the require as an other post with kinda the same error sugested.

any ideas ?

cheers

What about android support?

As of now this plugins only supports iOS, Have you a plan for android support ?

If yes, till when you will be publish this ?

Speech.stop() won't allow me to Speech.speak() again.

Hi!

When using your component, I realized that Speech.stop(), which removes the Speech instance, won't allow me to re-launh a Speech.speak() again. When catching the error, Speech.speak tells me : "There is a speech in progress. Use the paused method to know if it's paused." when there is absolutely nothing in progress.
I have no issue pausing / resuming a Speech.speak().

Any idea?

Cheers

Manual linking or automatic linking required

Hi,
I have installed react-native-speech in my current project. But after node module install I could not find any manual or automatic installation guide.

I trigger react-native link react-native-speech.

Still nothing working.

Could you share installation and manual linking guide? And other settings.

Speech on physical ios device

If I install the app on my physical device, I get no errors but there also is no audio. It works in the emulator. Any ideas what I have gotten wrong?

I tried adding inter-app-audio entitlement but that did not seem to resolve my problem...

Unable to resolve module NativeModules

Hello,

I'm simply trying to require this library as a module within my application, and it just doesn't work. I have successfully added your other library react-native-activity-view to my application with no errors at all, I also followed the facebook docs like you suggested.

Unable to resolve module NativeModules from /path/tomy/home/dir/node_modules/react-native-speech/SpeechSynthesizer.ios.js: Invalid 
Unable to resolve module NativeModules

Commenting out your require on NativeModules prompted that *invariant * could not be found as a module.

Unable to resolve module invariant

I'm actively researching these issues, any help would be greatly appreciated.

After installing react-native-speech got error

error: bundling failed: Error: While trying to resolve module react-native-speech from file /Applications/MAMP/htdocs/echoapp/demoPro/App.js, the package /Applications/MAMP/htdocs/echoapp/demoPro/node_modules/react-native-speech/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/react-native-speech/SpeechSynthesizer.ios.js. Indeed, none of these files exist:

  • /Applications/MAMP/htdocs/echoapp/demoPro/node_modules/react-native-speech/SpeechSynthesizer.ios.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
  • /Applications/MAMP/htdocs/echoapp/demoPro/node_modules/react-native-speech/SpeechSynthesizer.ios.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)
    at ResolutionRequest.resolveDependency (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:103:15)
    at DependencyGraph.resolveDependency (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
    at dependencies.map.relativePath (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
    at Array.map ()
    at resolveDependencies (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
    at /Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
    at Generator.next ()
    at step (/Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
    at /Applications/MAMP/htdocs/echoapp/demoPro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473

screen shot 2018-06-05 at 3 22 55 pm

Not working for android. SpeechSynthesizer.android.js SpeechSynthesizer is not implemented

Dear team,
The plugin looks very nice and I have started using for my android project.
But unfortunately it not working after repeated debug of problem, I found in
SpeechSynthesizer.android.js file there is no native code invocation for TTS speech
SpeechSynthesizer

'use strict';

var warning = require('warning');

var SpeechSynthesizer = {
test: function() {
warning("Not yet implemented for Android.");
}
};

module.exports = SpeechSynthesizer;

Please confirm the same.

thanks

supplying numbers to speak causing silent crash

If you supply this module with a number to speak, for example:

Speech.speak({ text: 5 });

it will result in a silent runtime error which crashes the app without any reported errors or stack traces.

I am simply casting all my number values to strings before sending them to react-native-speech to avoid this problem, but you might want to run an internal catch (or cast) to prevent these types of errors, and facilitate some nice error messages for a better debugging experience.

[Bug] require('NativeModules').SpeechSynthesizer is undefined

Hi,

Your plugin looks very promising, and I'd love to use it in my current project, but it seems that - since React core update (see facebook/react-native#1821 ), SpeechSynthesizer is not part of the core anymore.

When trying to install your plugin, I'm prompted with an error screen due tu SpeechSynthesizer not being part of NativeModules.

Any Ideas on how to fix this?

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.