Zhenghanjv 8 месяцев назад
Родитель
Сommit
787e01c8e0

+ 1 - 0
.hbuilderx/launch.json

@@ -18,6 +18,7 @@
         },
         {
             "openVueDevtools" : false,
+            "playground" : "custom",
             "type" : "uni-app:app-android"
         }
     ]

+ 5 - 1
App.vue

@@ -1,10 +1,14 @@
 <script>
+	import system_util from './until/system_util'
+	import ttsUtils from './until/tts/ttsUtils'
 	export default {
 		onLaunch: function() {
 			console.log('App Launch')
 		},
-		onShow: function() {
+		onShow: async function() {
 			console.log('App Show')
+			await system_util.getCurrentPlatform()
+			ttsUtils.init()
 			var screenWidth = 0
 			var screenHeight = 0
 			uni.getSystemInfo({

+ 18 - 1
manifest.json

@@ -52,7 +52,8 @@
                     "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
                     "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
                     "<uses-feature android:name=\"android.hardware.camera\"/>",
-                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
+                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
+                    "<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>"
                 ],
                 "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
             },
@@ -96,6 +97,22 @@
                     }
                 }
             }
+        },
+        "nativePlugins" : {
+            "tts" : {
+                "__plugin_info__" : {
+                    "name" : "tts",
+                    "description" : "调用原生tts",
+                    "platforms" : "Android",
+                    "url" : "",
+                    "android_package_name" : "",
+                    "ios_bundle_id" : "",
+                    "isCloud" : false,
+                    "bought" : -1,
+                    "pid" : "",
+                    "parameters" : {}
+                }
+            }
         }
     },
     /* 快应用特有相关 */

BIN
nativeplugins/tts/android/tts_lib1.0.1.aar


+ 17 - 0
nativeplugins/tts/package.json

@@ -0,0 +1,17 @@
+{
+	"name": "tts",
+	"id": "tts",
+	"version": "1.0.1",
+	"description": "调用原生tts",
+	"_dp_type": "nativeplugin",
+	"_dp_nativeplugin": {
+		"android": {
+			"plugins": [{
+				"type": "module",
+				"name": "tts",
+				"class": "com.example.tts_lib.Speech"
+			}],
+			"integrateType": "aar"
+		}
+	}
+}

BIN
unpackage/res/icons/1024x1024.png


BIN
unpackage/res/icons/120x120.png


BIN
unpackage/res/icons/144x144.png


BIN
unpackage/res/icons/152x152.png


BIN
unpackage/res/icons/167x167.png


BIN
unpackage/res/icons/180x180.png


BIN
unpackage/res/icons/192x192.png


BIN
unpackage/res/icons/20x20.png


BIN
unpackage/res/icons/29x29.png


BIN
unpackage/res/icons/40x40.png


BIN
unpackage/res/icons/58x58.png


BIN
unpackage/res/icons/60x60.png


BIN
unpackage/res/icons/72x72.png


BIN
unpackage/res/icons/76x76.png


BIN
unpackage/res/icons/80x80.png


BIN
unpackage/res/icons/87x87.png


BIN
unpackage/res/icons/96x96.png


+ 114 - 110
until/fun.js

@@ -1,122 +1,126 @@
-/** 将15寸和32寸共同用到的 函数内容,封装成一个js文件 */ 
-	
-	
-	import {
-		nextTick,
-		reactive,
-		watch
-	} from 'vue';
-	import { getDataList } from '../api/ChatApp';
-	
-	
-	// 发送消息
-	const handleSend = async (msgList) => {
-		msgList.isClick = !msgList.isClick
-		const data = {
-			AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
-			AId: 'TK1234',
-			content: ''
-		}
-		if (msgList.chatMsg != '') {
-			msgList.isloading[msgList.len] = true
-			msgList.len++
-			let obj = {
-				otherContent: '',
-				userContent: '',
-				image: ""
-			}
-			data.content = msgList.chatMsg
-			obj.userContent = msgList.chatMsg
-			msgList.chatList.push(obj)
+/** 将15寸和32寸共同用到的 函数内容,封装成一个js文件 */
 
-			obj.otherContent = await GetNewsList(msgList,data)
 
-			// await sleep(16000);
-			getChatContent(msgList,obj.otherContent, msgList.len)
+import {
+	nextTick,
+	reactive,
+	watch
+} from 'vue';
+import {
+	getDataList
+} from '../api/ChatApp';
+import ttsUtils from './tts/ttsUtils';
 
 
+// 发送消息
+const handleSend = async (msgList) => {
+	msgList.isClick = !msgList.isClick
+	const data = {
+		AppId: '0c8ff06b-91d9-43f7-b61e-ca5da1db15d4',
+		AId: 'TK1234',
+		content: ''
+	}
+	if (msgList.chatMsg != '') {
+		msgList.isloading[msgList.len] = true
+		msgList.len++
+		let obj = {
+			otherContent: '',
+			userContent: '',
+			image: ""
 		}
+		data.content = msgList.chatMsg
+		obj.userContent = msgList.chatMsg
+		msgList.chatList.push(obj)
+
+		obj.otherContent = await GetNewsList(msgList, data)
+		console.log(obj.otherContent)
+		// await sleep(16000);
+		getChatContent(msgList, obj.otherContent, msgList.len)
+		ttsUtils.toSpeak(obj.otherContent)
 
-		msgList.otherContent = ''
-	}
-	
-	// 调用数据接口
-	const GetNewsList = async (msgList,data) => {
-		msgList.chatMsg = ''
-		var res = await getDataList(data)
-		console.log(res)
-		return res
 	}
-	
-	// 逐字显示内容
-	const getChatContent = ((msgList,text, index) => {
-		msgList.timer = setInterval(() => {
-			msgList.textCount++;
-			if (msgList.textCount == text.length + 1) {
-				msgList.otherChatList[index - 1] = text;
-				clearInterval(msgList.timer);
-			} else {
-				// 取字符串子串
-				let nowStr = text.substring(0, msgList.textCount);
-				msgList.otherChatList[index - 1] = nowStr;
+
+	msgList.otherContent = ''
+}
+
+// 调用数据接口
+const GetNewsList = async (msgList, data) => {
+	msgList.chatMsg = ''
+	var res = await getDataList(data)
+	console.log(res)
+	return res
+}
+
+// 逐字显示内容
+const getChatContent = ((msgList, text, index) => {
+	if (text == undefined) return
+	msgList.timer = setInterval(() => {
+		msgList.textCount++;
+		if (msgList.textCount == text.length + 1) {
+			msgList.otherChatList[index - 1] = text;
+			clearInterval(msgList.timer);
+		} else {
+			// 取字符串子串
+			let nowStr = text.substring(0, msgList.textCount);
+			msgList.otherChatList[index - 1] = nowStr;
+		}
+
+	}, 50);
+	console.log(msgList.timer)
+	msgList.textCount = 0
+	msgList.isloading[index - 1] = false
+	msgList.isClick = !msgList.isClick
+})
+
+// 滚动条回到最底部
+const scrollToBottom = ((msgList) => {
+	nextTick(() => {
+		const query = uni.createSelectorQuery();
+		query.select("#content-box").boundingClientRect()
+		query.select("#content-overflow").boundingClientRect()
+		query.exec(res => {
+			const scrollViewHeight = res[0].height
+			const scrollContentHeight = res[1].height
+			if (scrollViewHeight < scrollContentHeight) {
+				const scrollTop = scrollContentHeight - scrollViewHeight
+				msgList.scrollTop = scrollTop
 			}
-	
-		}, 50);
-		console.log(msgList.timer)
-		msgList.textCount = 0
-		msgList.isloading[index - 1] = false
-		msgList.isClick = !msgList.isClick
-	})
-	
-	// 滚动条回到最底部
-	const scrollToBottom = ((msgList) => {
-		nextTick(() => {
-			const query = uni.createSelectorQuery();
-			query.select("#content-box").boundingClientRect()
-			query.select("#content-overflow").boundingClientRect()
-			query.exec(res => {
-				const scrollViewHeight = res[0].height
-				const scrollContentHeight = res[1].height
-				if (scrollViewHeight < scrollContentHeight) {
-					const scrollTop = scrollContentHeight - scrollViewHeight
-					msgList.scrollTop = scrollTop
-				}
-			})
 		})
 	})
+})
 
 
-	// 背景颜色变换
-	const styleChange = ((styleData)=>{
-		styleData.value = !styleData.value
-		if(styleData.value == true){
-			styleData.color = "rgba(0,0,0,0.8)"
-			styleData.fontColor = "#fff"
-			styleData.btnColor = "#ccc"
-			styleData.contentColor = "rgba(0,0,0,0.5)"
-			styleData.labelColor = "rgb(105,105,105)"
-			styleData.borderColor = "rgb(105,105,105)"
-			
-		}else{
-			styleData.color = "#f5f5f5"
-			styleData.fontColor = "black"
-			styleData.btnColor = "rgb(30,144,255)"
-			styleData.contentColor = "#fff"
-			styleData.labelColor = "#fff"
-			styleData.borderColor = "rgb(30,144,255)"
-		}	
-		
-	})
-	
-	//快捷键输入
-	const shortcuts = ((msgList,item)=>{
-		msgList.chatMsg = item
-		handleSend(msgList)
-	})
-	
-	export {
-		handleSend,
-		styleChange,
-		scrollToBottom,
-		shortcuts
-	}
+// 背景颜色变换
+const styleChange = ((styleData) => {
+	styleData.value = !styleData.value
+	if (styleData.value == true) {
+		styleData.color = "rgba(0,0,0,0.8)"
+		styleData.fontColor = "#fff"
+		styleData.btnColor = "#ccc"
+		styleData.contentColor = "rgba(0,0,0,0.5)"
+		styleData.labelColor = "rgb(105,105,105)"
+		styleData.borderColor = "rgb(105,105,105)"
+
+	} else {
+		styleData.color = "#f5f5f5"
+		styleData.fontColor = "black"
+		styleData.btnColor = "rgb(30,144,255)"
+		styleData.contentColor = "#fff"
+		styleData.labelColor = "#fff"
+		styleData.borderColor = "rgb(30,144,255)"
+	}
+
+})
+
+//快捷键输入
+const shortcuts = ((msgList, item) => {
+	msgList.chatMsg = item
+	handleSend(msgList)
+})
+
+export {
+	handleSend,
+	styleChange,
+	scrollToBottom,
+	shortcuts
+}

+ 11 - 11
until/request.js

@@ -7,23 +7,23 @@ const axios = Axios.create({
 		'Content-Type': 'application/json'
 	},
 	timeout: 600000, // 超时
-	baseURL: 'http://192.168.1.101:5000' ,
+	baseURL: 'http://192.168.1.104:5000',
 	// baseURL: 'http://192.168.1.105:5000' ,
 	adapter: axiosAdapterUniapp
 })
 
 // 请求拦截
 axios.interceptors.request.use(req => {
-  if (req.method === 'get') {
-    const url = req.url
-    const t = new Date().getTime()
-    if (url.indexOf('?') >= 0) {
-      req.url = `${url}&t=${t}`
-    } else {
-      req.url = `${url}?t=${t}`
-    }
-  }
-  return req
+	if (req.method === 'get') {
+		const url = req.url
+		const t = new Date().getTime()
+		if (url.indexOf('?') >= 0) {
+			req.url = `${url}&t=${t}`
+		} else {
+			req.url = `${url}?t=${t}`
+		}
+	}
+	return req
 })
 
 // 响应拦截

+ 23 - 0
until/system_util.ts

@@ -0,0 +1,23 @@
+//系统信息
+var systemInfo : UniApp.GetSystemInfoResult
+function getCurrentPlatform() {
+	uni.getSystemInfo().then(res => {
+		systemInfo = res;
+	});
+
+}
+
+//获取系统信息
+function getInfo() {
+	return systemInfo;
+}
+
+function getAppInfo() {
+	return uni.getAppBaseInfo()
+}
+
+export default {
+	getCurrentPlatform,
+	getAppInfo,
+	getInfo
+}

+ 31 - 0
until/tts/androidTTs/androidTTS.js

@@ -0,0 +1,31 @@
+const AndroidTTS = {
+	TextToSpeech: plus.android.importClass("android.speech.tts.TextToSpeech"),
+	tts: null,
+	toSpeak: function(content) {
+		console.log(content)
+		this.tts.speak(content, 0, null)
+	},
+	init: function() {
+		var main = plus.android.runtimeMainActivity();
+		var listner = new plus.android.implements("android.speech.tts.TextToSpeech.OnInitListener", {
+			onInit: function(status) {
+				console.log(`初始化结果${status}`)
+				if (status == 0) {
+					uni.showToast({
+						title: 'tts初始化成功'
+					})
+				} else {
+					uni.showToast({
+						title: 'tts初始化失败'
+					})
+				}
+			}
+		});
+		this.tts = new this.TextToSpeech(main, listner)
+		console.log(this.tts)
+	}
+}
+
+export default {
+	AndroidTTS
+}

+ 26 - 0
until/tts/ttsUtils.ts

@@ -0,0 +1,26 @@
+import system_util from "../system_util"
+// import AndroidTTS from "./androidTTs/androidTTS.js"
+
+const tts = uni.requireNativePlugin("tts")
+const init = () => {
+	var info = system_util.getInfo()
+	if (info.osName == "android") {
+		tts.init(res => {
+			console.log(res)
+		})
+	}
+}
+
+const toSpeak = (content : string) => {
+	var info = system_util.getInfo()
+	if (info.osName == "android") {
+		tts.speech(content, res => {
+			console.log(res)
+		})
+	}
+}
+
+export default {
+	init,
+	toSpeak
+}