更新记录

1.0.2(2021-09-28)

iOS版增加stop方法,支持停止播放。

1.0.1(2021-06-23)

修复Android可能播报失败的问题

1.0.0(2021-02-05)

新鲜出炉

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:6.0 - 11.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 适用版本区间:10 - 14

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


原生TTS

调用方式

const tts = uni.requireNativePlugin("nrb-tts-plugin")

tts && tts.init({ "lang":"ZH", "country":"CN" }, res => {
    if(res.success == 0){
        console.log('初始化TTS成功')
    }
})

tts && tts.speak('测试语音播报', {}, e => {
    console.log(e)

})

//停止播放
tts && tts.stop()

init参数及回调

Android:

如果使用默认参数,传{}

参数格式:{"lang":"zh","country":"CN"} 详见Local定义: /**

 * Construct a locale from language and country.
      * This constructor normalizes the language value to lowercase and
      * the country value to uppercase.
           * <p>
           * <b>Note:</b>
           * <ul>
           * <li>ISO 639 is not a stable standard; some of the language codes it defines
           * (specifically "iw", "ji", and "in") have changed.  This constructor accepts both the
           * old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other
           * API on Locale will return only the OLD codes.
           * <li>For backward compatibility reasons, this constructor does not make
           * any syntactic checks on the input.
           * </ul>
           *
           * @param language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag
           * up to 8 characters in length.  See the <code>Locale</code> class description about
           * valid language values.
           * @param country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code.
           * See the <code>Locale</code> class description about valid country values.
           * @exception NullPointerException thrown if either argument is null.
           */

lang:language,默认:zh country:country,默认CN

回调结果:{"success":0,"errmsg":"出错"} success:0:成功;其他:失败,参考TextToSpeech错误码

iOS:

参数:无,传{}

回调结果:{"success":0,"errmsg":""} success:0:成功;iOS只会回调成功

errmsg:错误信息

speak参数及回调

Android:

播放参数:{"pitch":1.0,"speechRate":1.0,"queueMode":1,"utteranceId":""}参考TextToSpeech参数,使用默认播放参数,传{} pitch:默认1.0f speechRate:默认1.0f queueMode:默认TextToSpeech.QUEUE_ADD utteranceId:默认长度为10的随机字符串

回调结果:{"utteranceId":"","type":"","params":{}} 播放进度,参考UtteranceProgressListener,一次播报会回调多次 utteranceId:speak传入的id type:UtteranceProgressListener回调的方法名,如:,onStop,onDone等 params:UtteranceProgressListener回调的参数集,如:onStop时,为{"interrupted":true}。onError时,为{"errorCode":-1}

iOS:

播放参数:{"rate":0.5,"lang":"zh-CN","volume":1},参考AVSpeechUtterance里的参数说明,使用默认播放参数,传{} rate:播放速度,默认0.5 lang:播放声音来源,默认zh-CN volume:音量,默认1

回调结果:{"msg":msg,"type":type,"params":params}播放进度,参考AVSpeechSynthesizerDelegate,一次播报会回调多次 msg:speak传入的播放字符串 type:AVSpeechSynthesizerDelegate的方法名 params:AVSpeechSynthesizerDelegate回调的其他参数集

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问