From 56bc142d33106db9f226abe39f60d0059d702338 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 10 四月 2026 20:04:38 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
app/pages/index/index.vue | 79 +++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/app/pages/index/index.vue b/app/pages/index/index.vue
new file mode 100644
index 0000000..75bb71a
--- /dev/null
+++ b/app/pages/index/index.vue
@@ -0,0 +1,79 @@
+<template>
+ <view style="padding: 40rpx;">
+ <button @click="speak('璁㈠崟宸叉敹鍒帮紝寮�濮嬫挱鎶�')">寮�濮嬫挱鎶�</button>
+ </view>
+</template>
+
+<script>
+ export default {
+ data() {
+ return {
+ tts: null // 鍘熺敓TTS瀵硅薄
+ }
+ },
+
+ onReady() {
+ this.initTTS() // 椤甸潰娓叉煋瀹屾垚鍒濆鍖栬闊�
+ },
+
+ methods: {
+ // ========== 鍒濆鍖栧畨鍗撳師鐢熻闊� ==========
+ initTTS() {
+ if (uni.getSystemInfoSync().platform !== 'android') {
+ console.log('浠呮敮鎸佸畨鍗�')
+ return
+ }
+
+ try {
+ // 瀵煎叆瀹夊崜鍘熺敓绫�
+ const TextToSpeech = plus.android.importClass('android.speech.tts.TextToSpeech')
+ const Locale = plus.android.importClass('java.util.Locale')
+
+ // 鍒涘缓TTS
+ this.tts = new TextToSpeech(plus.android.runtimeMainActivity(), {
+ onInit: (status) => {
+ if (status == 0) {
+ // 璁剧疆涓枃
+ this.tts.setLanguage(Locale.CHINA)
+ console.log('璇煶鍒濆鍖栨垚鍔�')
+ }
+ }
+ })
+ } catch (e) {
+ console.log('鍒濆鍖栧け璐�', e)
+ }
+ },
+
+ // ========== 璇煶鎾姤锛堟牳蹇冩柟娉曪級 ==========
+ speak(text) {
+ if (!this.tts) {
+ uni.showToast({
+ title: '璇煶鏈噯澶囧ソ',
+ icon: 'none'
+ })
+ return
+ }
+
+ try {
+ // 瀹夊崜鍘熺敓鎾姤锛圦UEUE_FLUSH = 绔嬪嵆鎾姤锛屾墦鏂笂涓�鏉★級
+ this.tts.speak(text, 0, null)
+ } catch (err) {
+ console.log('鎾姤澶辫触', err)
+ }
+ },
+
+ // 鍋滄鎾姤
+ stopSpeak() {
+ if (this.tts) this.tts.stop()
+ }
+ },
+
+ // 椤甸潰閿�姣佹椂鍏抽棴璇煶
+ onUnload() {
+ if (this.tts) {
+ this.tts.stop()
+ this.tts.shutdown()
+ }
+ }
+ }
+</script>
\ No newline at end of file
--
Gitblit v1.9.3