ak1394 / react-native-tts Goto Github PK
View Code? Open in Web Editor NEWReact Native Text-To-Speech library for Android and iOS
React Native Text-To-Speech library for Android and iOS
I'm having a strange error after installing react-native-tts. The run-android command builds up completely. However when I try to run the app (on physical android device) it crashes without any warning/errors. Neither errors on the debugger-ui. Any idea what it could be?
This package has a minSdkVersion=15 build.gradle, however React Native 0.41.2 won't work with less than 16, and the gradle will not sync, giving an AndroidManifest merge error. I tried to override the requirement but that did not work (RN possibly has GradleOverrides set).
If I change the minSdkVersion in this package to 16, gradle syncs
就是安卓播放的为什么没有声音 Tts.speak('Hello,world');
Hi @ak1394 thanks for the great job with this library, I'am testing it and I can automatically stop the audio if the user leave the current View with componentWillUnmount as you can check here:
componentWillUnmount(){
Tts.stop();
}
However, if the user switch to another app or force to close the app, the sounds continue until the entire text is completely readed. Is there any option to avoid this behavior?
Hi, I was wondering what your thoughts are on this. I need background audio to be ducked when text-to-speech is played, and unducked when the utterance is finished. Currently on iOS any background audio is paused and never resumed when usibng react-native-tts. I've already got ducking and audio resume working for iOS, but before I start working on the Android I was thinking what your thoughts are on this.
Should ducking be part of this library, or something that should be build externally using the events that are emitted by this library? A penny for your thoughts.
cheers,
Hein
In IOS when permission is granted to the microphone, the device's audio goes to the upper speaker and the sound becomes low because that speaker serves for the purpose of call. Please, anybody can help me?
Is there any way to add a delay in a string you send to the TTS engine?
e.g.
This is some content. [PAUSE for 3 seconds] This is more content.
Somewhere I thought I saw iOS supported inlining a command [[sinc 3000]]
Hi @ak1394 i'm tried config 'vi', 'vn' but no one of them work in my case
Hi, the installation when Ok but when I run the app I get the red screen with the following error:
Native module TextToSpeechModule tried to override TextToSpeechModule for module name TextToSpeech. If this was your intention, return true from TextToSpeechModule#canOverrideExistingModule()
Thanks, Railton.
After adding this, I got the error 'Node module cannot be null'. Stack trace mentions Tts.NativeEventEmitter as the error source. I don't get the error if I'm not importing/using Tts anywhere. I'm on React-Native 44.2.
Thanks for this great library, works great in my app.
Is there a way to get this library to work while app is in background, so speech continues without app interactivity, when multiple paragraphs have already been queued in the TTS library? I see other audio libraries that can play in background, but those are not for TTS, only audio streaming from remote sources.
Any direction is appreciated for having queued TTS playing in background.
Its useful us but I need to also highlight text when speak, how should I do.
Any solution.
Hi.awesome lib. I use this with Android 5.1 platform and found that when I try to invoke:
TTS.voices().then(voices=>console.log(voices));
it gives me an error that collection == null ;
How to solve this ? and BTW, is this lib support Chinese Simplified language ?
RN Version: 0.46.4
I don't know why I just install lib, even don't use lib in code, then now I can't run project anymore! It turns to this error red screens: "... make sure you have packaged.. "
import React from 'react';
import { StyleSheet, View, TouchableHighlight, Image } from 'react-native';
import Tts from 'react-native-tts';
export default class App extends React.Component {
constructor(props) {
super(props);
this._pressConfig = this._pressConfig.bind(this);
this._pressPlay = this._pressPlay.bind(this);
}
_pressConfig() {
console.log("pressed");
}
_pressPlay() {
Tts.speak("Hello world");
}
render() {
return (
<View style={styles.container}>
<View style={styles.navigation}>
<TouchableHighlight onPress={this._pressConfig}>
<Image source={require('./App/img/img_hamburger.png')}
style={{ width: 30, height: 30 }} />
</TouchableHighlight>
</View>
<View style={styles.content}>
<TouchableHighlight onPress={this._pressPlay}>
<Image source={require('./App/img/img_play.png')}
style={{ width: 100, height: 100 }} />
</TouchableHighlight>
</View>
</View>
);
}
}
this is my App.js file, I tried react-native link
after installing 'react-native-tts' but it seems not to work.
my package.json file:
"all": "0.0.0",
"expo": "^20.0.0",
"lottie-react-native": "~1.1.1",
"module": "^1.2.5",
"react": "16.0.0-alpha.12",
"react-native": "^0.47.2",
"react-native-side-menu": "^1.0.2",
"react-native-tts": "^1.4.0"
anyone has any ideas?
This support library should not use a different version (24) than the compileSdkVersion (23)
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.facebook.react:react-native:+'
}
Hey man, awesome library. Everything was going awesome till I upgraded to RN 0.50, then suddenly my app crashes whenever I call the voices()
method. I checked my logs and found the following:
Exception '-[AVSpeechSynthesisVoice identifier]: unrecognized selector sent to instance 0x7ffc1d4c3ff0' was thrown while invoking voices on target TextToSpeech with params (
6746,
6747
)
callstack: (
0 CoreFoundation 0x000000010d676f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c7d2bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010d67e04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010d5d627c ___forwarding___ + 988
4 CoreFoundation 0x000000010d5d5e18 _CF_forwarding_prep_0 + 120
5 Linguistic 0x000000010be3d61c -[TextToSpeech voices:reject:] + 476
6 CoreFoundation 0x000000010d56ec8c __invoking___ + 140
7 CoreFoundation 0x000000010d56eae2 -[NSInvocation invoke] + 290
8 CoreFoundation 0x000000010d5fded6 -[NSInvocation invokeWithTarget:] + 54
9 Linguistic 0x000000010bca4c0c -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2796
10 Linguistic 0x000000010bd3b582 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 786
11 Linguistic 0x000000010bd3b0af _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127
12 Linguistic 0x000000010bd3b029 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
13 libdispatch.dylib 0x000000011045aaf6 _dispatch_call_block_and_release + 12
14 libdispatch.dylib 0x0000000110474af4 _dispatch_client_callout + 8
15 libdispatch.dylib 0x000000011045f8cf _dispatch_queue_drain + 733
16 libdispatch.dylib 0x000000011045f494 _dispatch_queue_invoke + 217
17 libdispatch.dylib 0x00000001104613fa _dispatch_root_queue_drain + 479
18 libdispatch.dylib 0x00000001104622c9 _dispatch_worker_thread3 + 98
19 libsystem_pthread.dylib 0x00000001107e71ca _pthread_wqthread + 1387
20 libsystem_pthread.dylib 0x00000001107e6c4d start_wqthread + 13
)
which, from the looks of things, is coming from this line:
[voices addObject:@{@"id": voice.identifier, @"name": voice.name, @"language": voice.language}];
It seems like it can't find identifier
as a property of the voice
object, despite it being listed in the official docs. I'd try to fix it myself, but seeing it deals with native code I'm not even sure where I'd begin debugging it. Any idea what might be responsible for it?
Due to this : https://github.com/facebook/react-native/releases
After e1577df, Native code on iOS must refer to headers out of the react namespace. Previously the following would work:
#import "RCTUtils.h"
But now all headers have been moved:
#import <React/RCTUtils.h>
Solution here : in TextToSpeech.m
, line 9, replace #import "RCTBridge.h"
by #import <React/RCTBridge.h>
And the rest too :
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTLog.h>
#import <TextToSpeech/TextToSpeech.h>
I don’t PR because it would break builds on RN < 0.40.
When I navigate to a screen where Tts.setDefaultLanguage('nl-NL');
is used, it takes a few seconds to really navigate to that screen... So Tts.setDefaultLanguage('nl-NL');
makes my app really really really slow...
I have seen this on Android 7.0 and Android 7.1 (lower not seen, higher not tested). Not on Android 4.5
I'm currently running into an issue where I need to remove the TTS event listeners I am creating. Unfortunately, it seems to be ignoring removeEventListeners, and adding additional instances of the event listeners, when I call "setup" again, which ultimately crashes the app.
setup() {
Tts.addEventListener('tts-start', this.onTTSStart.bind(this));
Tts.addEventListener('tts-finish', this.onTTSFinish.bind(this));
Tts.addEventListener('tts-cancel', this.onTTSCancel.bind(this));
}
destroy() {
Tts.removeEventListener('tts-start', this.onTTSStart.bind(this));
Tts.removeEventListener('tts-finish', this.onTTSFinish.bind(this));
Tts.removeEventListener('tts-cancel', this.onTTSCancel.bind(this));
}
Using AVD which is emulating android 6.0, API 32, Intel Atom (x86_64)
"react": "15.4.2",
"react-native": "^0.38.0",
"react-native-tts": "0.4.0"
Steps to reproduce
Tts.setDefaultLanguage('en-US')
Tts.speak('text')
Tts.setDefaultLanguage('es-ES)
I get the alert: Unfortunately, Pico TTS has stopped. After the initial alert, the spanish version will play. However, if I switch back and forth a couple of times, it stops working and causes this error in the debugger:
Possible Unhandled Promise Rejection (id: 0):unable to play
Error: unable to play
at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22591:11)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22554:35
at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22940:10)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22792:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22711:1)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:22791:1)
at http://localhost:8081/debuggerWorker.js:71:58
I am using react-native-tts and it is working perfectly fine in my iOS project, however I get the following error while my Android app launches in emulator
"undefined is not an object (evaluating 'NativeSpeechSynthesizer.stopSpeakingAtBoundary')
Any help on this is much appreciated.
Hi,
When I use your TTS library and then use a different library with SFSpeechRecognizer
that uses audioSession setCategory:AVAudioSessionCategoryRecord
... and then I try to use your TTS library again... it doesn't seem to work.
It seems as though the audioSession's Category is still set to AVAudioSessionCategoryRecord
.
Do you know if there is a way to reset the audioSession's category to AVAudioSessionCategoryPlayback
before running your Tts.speak
method or any other way to get your library to work after/before using SFSpeechRecognizer
Thanks.
Hello!
I was trying to use the component and managed to set it up.
It does talk, but when I try to subscribe to events the call back is not being called, for example:
Tts.addEventListener('tts-start', (event) => { console.log("tts-start", event); dispatch({type: 'SPEECH_STARTED', payload: event}); });
Do you have any clue why this could happen?
I didn't see any list of supported language, can you please provide one?
Thanks in advance
The speed of tts is very important for us.
That's why we made some investigation on this. And here are our results:
As you can see, the max rate for Android is ~5. The max rate that we can currently set with help of this library is 3. It's almost twice less...
Moreover, the max rate may differ between different voices.
That's why I would ask you to remove this smart transformation from iOS to Android rate.
Or, maybe, it would be better to add the third parameter to the setDefaultRate
method. Something like dontTransform
or whatever...
Hi, great package !
Would it be possible to change te the speed at will ?
In TextToSpeech.m
, after that :
if ( voice ) {
utterance.voice = [ AVSpeechSynthesisVoice voiceWithIdentifier: voice ];
} else if ( _defaultVoice ) {
utterance.voice = _defaultVoice;
}
You can add
if ( rate ) {
utterance.rate = [ rate doubleValue ];
}
And for android it’s going to be tts.setPitch(rate);
as far as I understand.
componentWillMount () {
Tts.addEventListener('tts-start', (event) => console.log("start"))
}
componentWillUnmount () {
Tts.removeEventListener('tts-start');
}
the event listener does not remove properly~
cc: @sunjae1294
OS:
Platform:
Module TextToSpeech requires main queue setup since it overrides constantsToExport
but doesn't implement requiresMainQueueSetup
. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
react-native info
:
Environment:
OS: macOS Sierra 10.12.6
Node: 8.6.0
Yarn: 1.2.0
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: Not Found
Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.3 => 0.49.3
https://github.com/wix/react-native-navigation/pull/1983/files#diff-b8c48202d12fa78c4c377e5a3225c298
Hello Folks,
I have a production ready App and using react-native-tts, Text to speech works well in Android (both real device and simulator) and in iOS it works perfectly fine in simulator but not in the real device. Any suggestions to mitigate this?
Works on IOS emulator but get the "Error: TTS not ready" on Android (tried both simulator as well as device with same result).
I have verified that TTS works when tested under settings on emulator as well as device.
Android emulator version: 8.0.0
Device version: 7.1.2
the error in console log:
blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:sourcemap:53509 Possible Unhandled Promise Rejection (id: 0):
Error: TTS is not ready
Error: TTS is not ready
at createErrorFromErrorData (blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:2023:17)
at blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:1975:27
at MessageQueue.__invokeCallback (blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:2417:18)
at blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:2162:18
at MessageQueue.__guardSafe (blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:2330:11)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/463ce249-4719-4e5f-ad7d-a2f63dc584b8:2161:14)
at http://localhost:8081/debugger-ui/debuggerWorker.js:72:58
Tts.addEventListener('tts-finish', (arg) => {
console.log(arg);
// arg's type is ``number`` for iOS, ``{utteranceId: string}`` for Android
});
https://docs.gradle.org/current/userguide/gradle_wrapper.html
https://stackoverflow.com/questions/25769536/how-when-to-generate-gradle-wrapper-files
and don't forget to commit generated gradle wrapper .jar Because the whole point of the gradle wrapper is to be able, without having ever installed gradle.
I get the following error while I am running "react-native run-android"
:react-native-tts:compileReleaseJavaWithJavac
:react-native-tts:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
注: D:\ENtest\node_modules\react-native-tts\android\src\main\java\net\no_mad\tts\TextToSpeechModule.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: D:\ENtest\node_modules\react-native-tts\android\src\main\java\net\no_mad\tts\TextToSpeechModule.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
Hey @ak1394 nice work with this library! I'm wondering if there is any option to choose a female voice, if not, it will be a nice feature.
After linking the library to my xcode project, it fails to build with error:
React/RCTBridge.h file not found from TextToSpeech.m library.
and simulator shows error "Native module can't be null".
React Native version: 0.39.2
Default it don't use loudspeaker so I must use headphone to listening.
New iOS 11 came out with much more natural sounding Siri voice. However, even if the voice is installed in Settings app > General > Accessibility > Voices, for 'en-IE' only Samantha shows up from Tts.voices()
. Is there any way to access the new Siri voice, if it is exposed natively?
For reference, from README:
Tts.voices().then(voices => console.log(voices));
// Prints:
//
// [ { id: 'com.apple.ttsbundle.Moira-compact', name: 'Moira', language: 'en-IE' },
// ...
// { id: 'com.apple.ttsbundle.Samantha-compact', name: 'Samantha', language: 'en-US' } ]
Hello,
First of all, thank you very much for all that work.
On react-native 0.49.5, I'm trying to make my bot speak using your library. I first call Tts.speak("some sentence")
once my components are mounted and I call it again a few times later. The first call of the function returns the promise immediately, but it doesn't fire the tts-start
event and the voice only plays after 20-30 seconds. Whereas after those 30 seconds, calling Tts.speak()
fires the tts-start event right away and the bot speaks just after the function call.
I'm running the react-native app on Android 7.0.
Am I missing something ?
Hi,
Running the build with react-native v0.35.0 and the TTS library seems to fails for iOS:
$ react-native run-ios
...
The following build commands failed:
CompileC /Users/Me/Projects/MyProject/ios/build/Build/Intermediates/TextToSpeech.build/Release-iphonesimulator/TextToSpeech.build/Objects-normal/i386/TextToSpeech.o TextToSpeech/TextToSpeech.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/Me/Projects/MyProject/ios/build/Build/Intermediates/TextToSpeech.build/Release-iphonesimulator/TextToSpeech.build/Objects-normal/x86_64/TextToSpeech.o TextToSpeech/TextToSpeech.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(2 failures)
X-Code
// React/RCTBridge.h file not found in TextToSpeech.m
#import <React/RCTBridge.h>
What are the requirements for running the TTS library for iOS?
Hi,
I really love your package, and it works great. My problem is that Dutch is available on iOS but not on Android, is there a way to add a new language to the android languages?
If not, any suggestions what I could do?
I added an event listener for tts-finish event and i am removing it in componentwillunmount method but still its subscribed to the event.Is there something i need to do extra?
I have this error only on IOS:
TextToSpeech. was called with 1 arguments but expects 2 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript are out of sync. Updating both should make this error go.
Otherwise in Android is working fine.
Thanks.
First, thanks for you library ! very usefull
I just ask, if it's possible to know if the voice currently talking or not?
or at least remaining tim of the phrase? I think #31 is same question
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.