react-native-android-speech icon indicating copy to clipboard operation
react-native-android-speech copied to clipboard

the text-to-speech is not working after built

Open sumanbogati opened this issue 9 years ago • 8 comments

I can successfully built your project, however the text-to-speech is not working, I can't hear the audio after clicked on "button" text, the apk file is installed in android phone. Here is my index.android.js

` import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Platform, TouchableHighlight, TouchableNativeFeedback } from 'react-native';

var tts = require('react-native-android-speech')

function buttonClicked () {
    tts.speak({
        text:'Please provide some text to speak.', // Mandatory
        pitch:1.5, // Optional Parameter to set the pitch of Speech,
        forceStop : false , //  Optional Parameter if true , it will stop TTS if it is already in process
        language : 'en' // Optional Paramenter Default is en you can provide any supported lang by TTS
    }).then(isSpeaking=>{
        //Success Callback
        console.log(isSpeaking);
    }).catch(error=>{
        //Errror Callback
        console.log(error)
    });

     setTimeout(function(){ alert("finished here"); }, 3000);

}
class mysound extends Component {

  render() {
    var TouchableElement = TouchableHighlight;
    if (Platform.OS === 'android') {
        TouchableElement = TouchableNativeFeedback;
    }
    return (
      <View style={styles.container}>
          <Text style={styles.welcome}>
            Tap me as fast as you can!
          </Text>

          <TouchableElement
            onPress={buttonClicked}>
            <View>
              <Text>Button!</Text>
            </View>
          </TouchableElement>
  </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
AppRegistry.registerComponent('mysound', () => mysound);

` Can you please tell me why this is not working ? I have downloaded your code before one month and since then I have been working on this.

sumanbogati avatar Aug 07 '16 06:08 sumanbogati

@sumanbogati Could you please show me the error logs so that I can look at errors ?

mihirsoni avatar Aug 07 '16 12:08 mihirsoni

When I am alerting the error, it would come something like below

sumanbogati avatar Aug 07 '16 13:08 sumanbogati

Hi Mihir,

Have you found something related to this error ?

I would really appreciate if you give me the working example of text-to-speech.

Thank you.

sumanbogati avatar Aug 25 '16 04:08 sumanbogati

I am also trying to get this to work but having no luck.

What's odd is that if I output tts to the console, it says it's an object with five functions (speak, stop, shutDown, etc.). But if I try to use tts.speak() I get Cannot read property 'speak' of undefined. The console says tts is defined but it suddenly becomes undefined if I try to use it.

function buttonClicked () {
    var tts = require('react-native-android-speech')
    console.log("tts = ", tts);
    tts.speak({text:'Please provide some text to speak.'});
}

bergonom avatar Sep 29 '16 21:09 bergonom

I think I am running into the same Problem. However it looks as if the tts import from the package works, but the AndroidTTS object is not able to send the speak message.

ReactNativeJS: { [TypeError: undefined is not an object (evaluating 'AndroidTTS.speak')] ReactNativeJS: line: 82144, ReactNativeJS: column: 11, ReactNativeJS: sourceURL: 'http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false' }

dennissivia avatar Nov 03 '16 10:11 dennissivia

@scepticulous Do you have sample repo where I can reproduce this ?

mihirsoni avatar Nov 03 '16 14:11 mihirsoni

Hi @mihirsoni, here is an minimal example app that causes the error.

dennissivia avatar Nov 03 '16 15:11 dennissivia

I get same issue too. Whatever function I use (isSpeaking, isSpeak, getLocales), I got error "Cannot read property 'isSpeaking' of undefined", "Cannot read property 'isSpeak' of undefined", "Cannot read property 'getLocale' of undefined". Still figure out the solution

pewh avatar Jan 27 '17 03:01 pewh