admin管理员组文章数量:1335552
I'm new to React native. In the application, the pronunciation of the words is heard with the TTS package. When I use this package, I get an warning as follows. This warning only happens on android. There is no problem on iOS. This warning ing as the app is opened. How can I fix this?
Warning:
TTS package settings:
import { Platform } from "react-native"
import Tts from "react-native-tts"
export class VocalizationUtil {
constructor() {
Tts.setDefaultLanguage("en-IE").catch(error => { })
}
iosConfig = {
iosVoiceId: ".apple.ttsbundle.Moira-pact", //which voice to use
rate: 0.5, //speech rate
}
androidConfig = {
KEY_PARAM_PAN: 0,
KEY_PARAM_VOLUME: 0.5, // 0 means silence
KEY_PARAM_STREAM: "STREAM_MUSIC"
}
// Subscribe to TTS events
createListeners() {
Tts.addEventListener("tts-start", event => { })
Tts.addEventListener("tts-finish", event => { })
Tts.addEventListener("tts-cancel", event => { })
}
async voiceTheText(text) {
this.createListeners()
Tts.stop() //Stop speaking and flush the TTS queue.
// if text-to-speech engine is not installed, request the installation
Tts.getInitStatus()
.then(() => {
Tts.speak(`${text}`, Platform.OS === "android" ? this.androidConfig : this.iosConfig)
})
.catch(error => { })
}
}
I'm new to React native. In the application, the pronunciation of the words is heard with the TTS package. When I use this package, I get an warning as follows. This warning only happens on android. There is no problem on iOS. This warning ing as the app is opened. How can I fix this?
Warning:
TTS package settings:
import { Platform } from "react-native"
import Tts from "react-native-tts"
export class VocalizationUtil {
constructor() {
Tts.setDefaultLanguage("en-IE").catch(error => { })
}
iosConfig = {
iosVoiceId: ".apple.ttsbundle.Moira-pact", //which voice to use
rate: 0.5, //speech rate
}
androidConfig = {
KEY_PARAM_PAN: 0,
KEY_PARAM_VOLUME: 0.5, // 0 means silence
KEY_PARAM_STREAM: "STREAM_MUSIC"
}
// Subscribe to TTS events
createListeners() {
Tts.addEventListener("tts-start", event => { })
Tts.addEventListener("tts-finish", event => { })
Tts.addEventListener("tts-cancel", event => { })
}
async voiceTheText(text) {
this.createListeners()
Tts.stop() //Stop speaking and flush the TTS queue.
// if text-to-speech engine is not installed, request the installation
Tts.getInitStatus()
.then(() => {
Tts.speak(`${text}`, Platform.OS === "android" ? this.androidConfig : this.iosConfig)
})
.catch(error => { })
}
}
Share
Improve this question
asked Nov 14, 2021 at 21:34
SoFSoF
7871 gold badge14 silver badges33 bronze badges
2 Answers
Reset to default 2Thanks to @Langarus for the reply. I added the short solution here for those who encounter this problem.
For all packages where you get this warning, add the following code to the package's ..Module.java file. For example, for the TTS package, add the following code to node_modules/react-native-tts/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java
@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}
@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
In case you are using
removeEventListener
, that was deprecated https://reactnative.dev/docs/appstate#removeeventlistener You have a codeSnippet on the top of the page on how to use.remove()
instead ofremoveEventLister
In case you are using react-native-reanimated or drawer it seems that the problem es from the libraries not being updated. https://github./react-navigation/react-navigation/issues/9882
If you want to silence it new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method
本文标签:
版权声明:本文标题:javascript - "new NativeEventEmitter()` was called with a non-null argument.." warning TTS package - RN - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742395411a2466820.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论