androidTTS.js 729 B

12345678910111213141516171819202122232425262728293031
  1. const AndroidTTS = {
  2. TextToSpeech: plus.android.importClass("android.speech.tts.TextToSpeech"),
  3. tts: null,
  4. toSpeak: function(content) {
  5. console.log(content)
  6. this.tts.speak(content, 0, null)
  7. },
  8. init: function() {
  9. var main = plus.android.runtimeMainActivity();
  10. var listner = new plus.android.implements("android.speech.tts.TextToSpeech.OnInitListener", {
  11. onInit: function(status) {
  12. console.log(`初始化结果${status}`)
  13. if (status == 0) {
  14. uni.showToast({
  15. title: 'tts初始化成功'
  16. })
  17. } else {
  18. uni.showToast({
  19. title: 'tts初始化失败'
  20. })
  21. }
  22. }
  23. });
  24. this.tts = new this.TextToSpeech(main, listner)
  25. console.log(this.tts)
  26. }
  27. }
  28. export default {
  29. AndroidTTS
  30. }