更新记录

1.0(2026-02-09) 下载此版本

init


平台兼容性

uni-app

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - - - - - - × ×
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

参考 https://cloud.baidu.com/article/3896533

initTTS 初始化

SpeakTTS 播报

全部代码:

let TextToSpeech
let tts
export default class TTS {
    static initTTS() {
        const main = plus.android.runtimeMainActivity();
        TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech');
        const Context = plus.android.importClass('android.content.Context');
        tts = new TextToSpeech(
            main,
            new TextToSpeech.OnInitListener({
                onInit: function(status) {
                    if (status === TextToSpeech.SUCCESS) {
                        const result = tts.setLanguage(plus.android.invoke('java.util.Locale', 'US'));
                        if (result === TextToSpeech.LANG_MISSING_DATA || result === TextToSpeech.LANG_NOT_SUPPORTED) {
                            console.log('语言包未安装');
                        }
                    }
                }
            }),
            null
        );
    }

    static SpeakTTS(text, pitch = 1.0, rate = 1.0) {
        if (!tts) {
      this.initTTS();
    }
    tts.setPitch(pitch);
    tts.setSpeechRate(rate);
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, (e) => {
      console.log(e);
    }, (e) => {
      console.log(e);
    });
    }
}

兼容性什么的都没试,需要自行测试

需要配合中文tts引擎 低版本安卓需要安装 讯飞语记 或其他中文引擎 且需要在设置中修改为中文引擎 自带中文引擎的实测一加ace(安卓15)不需要

小白 尝试一下发布插件 设置的价格是无意义的

隐私、权限声明

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

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

插件不采集任何数据

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

暂无用户评论。