我是新来的本地人。在应用程序中,使用TTS包可以听到单词的发音。当我使用这个包时,我会收到如下警告。这个警告只发生在android上。iOS没有问题。这个警告是在应用程序打开时发出的。我怎么才能解决这个问题?
警告:

TTS包设置:
import { Platform } from "react-native"
import Tts from "react-native-tts"
export class VocalizationUtil {
constructor() {
Tts.setDefaultLanguage("en-IE").catch(error => { })
}
iosConfig = {
iosVoiceId: "com.apple.ttsbundle.Moira-compact", //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 => { })
}
}
发布于 2021-11-15 13:16:28
如果您使用的是removeEventLister,则在页的顶部有一个codeSnippet,说明如何使用.remove()而不是removeEventListener
如果你想让它安静,new NativeEventEmitter()was called with a non-null argument without the requiredaddListener` method
发布于 2022-06-06 10:31:08
谢谢@Langarus的回复。我在这里为那些遇到这个问题的人添加了简短的解决方案。
对于收到此警告的所有包,请将以下代码添加到包的..Module.java文件中。例如,对于TTS包,将以下代码添加到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.
}
https://stackoverflow.com/questions/69967372
复制相似问题