李朗
李朗
  • 发布:2021-03-29 10:54
  • 更新:2023-12-20 11:26
  • 阅读:861

ios使用Native.JS调用本地tts代理崩溃

分类:uni-app

使用Native.JS
调用ios的tts语音,添加代理后程序崩溃,直接闪退到桌面。
请大神们帮忙

<template>  
  <view class="content">  
    <button @tap="getLIst">获取发音人</button>  
    <image class="logo" src="/static/logo.png"></image>  
    <view class="text-area">  
      <text class="title">{{ title }}</text>  
      <button @tap="say">朗读</button>  
      <button @tap="stop">停止</button>  
    </view>  
  </view>  
</template>  

<script>  
var AVAudioSession = plus.ios.importClass("AVAudioSession");  
var AVSpeechSynthesizer = plus.ios.importClass("AVSpeechSynthesizer");  
//AVSpeechUtterance:这个类就是用来将字符串合成为语音对象提供给AVSpeechSynthesizer来播放,这个类还有一些实例方法用来控制语速,音调等等。。  
var AVSpeechUtterance = plus.ios.importClass("AVSpeechUtterance");  
//AVSpeechSynthesisVoice:用来配置发音,支持的发音非常多.  
var AVSpeechSynthesisVoice = plus.ios.import("AVSpeechSynthesisVoice");  
AVAudioSession.sharedInstance().setCategoryerror(  
  "AVAudioSessionCategoryPlayback",  
  null  
);  
var sppech = new AVSpeechSynthesizer();  
export default {  
  data() {  
    return {  
      title: "Hello",  
    };  
  },  
  onLoad() {},  
  methods: {  
    /*  
获取发音角色  
*/  
    getLIst() {  
      var AVSpeechSynthesisVoice = plus.ios.import("AVSpeechSynthesisVoice");  
      var list = new AVSpeechSynthesisVoice();  
      console.log("发音人", list.speechVoices);  
    },  

    /**  
停止朗读  
**/  

    stop() {  
      //停止  
      sppech.stopSpeakingAtBoundary(0);  
      //暂停  
      //sppech.pauseSpeakingAtBoundary(0);  
      //继续  
      //sppech.continueSpeaking(0);  
      //plus.ios.deleteObject(voice);  
      //plus.ios.deleteObject(utterance);  
      //plus.ios.deleteObject(sppech);  
      //plus.ios.deleteObject(AVAudioSession);  
    },  

    /*  
朗读  
*/  
    say() {  

      var AVdelegate = plus.ios.implements("李朗123", {  
        "speechSynthesizer:didStartSpeechUtterance:": (          synthesizer,          utterance        )=> {  
          console.log("开始说话");  
        }  
});  

      sppech.plusSetAttribute("delegate", AVdelegate);  

      console.log("代理属性", sppech.plusGetAttribute("delegate"));  
//return false;  
      const _this = this;  
      var utterance = AVSpeechUtterance.speechUtteranceWithString("i live you");  
      utterance.plusSetAttribute("rate", 0.8);  
      sppech.speakUtterance(utterance);  
    },  
  },  
};  
</script>  

<style>  
.content {  
  display: flex;  
  flex-direction: column;  
  align-items: center;  
  justify-content: center;  
}  

.logo {  
  height: 200rpx;  
  width: 200rpx;  
  margin-top: 200rpx;  
  margin-left: auto;  
  margin-right: auto;  
  margin-bottom: 50rpx;  
}  

.text-area {  
  display: flex;  
  justify-content: center;  
}  

.title {  
  font-size: 36rpx;  
  color: #8f8f94;  
}  
</style>  
2021-03-29 10:54 负责人:无 分享
已邀请:
2104_DLS

2104_DLS

测试代码没有崩溃,提供一下手机型号、系统等详细信息。

FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

b***@163.com

b***@163.com

能获取到角色列表么,打印是未定义

要回复问题请先登录注册