From c6e3c33979ab6ed1aa6a834f39c85356320c0f93 Mon Sep 17 00:00:00 2001
From: gerson <1405270578@qq.com>
Date: 星期五, 19 七月 2024 23:02:11 +0800
Subject: [PATCH] 语音对话

---
 src/components/chat/components/playBar/PlayBar.vue |   67 +++++++++++++--------------------
 1 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/src/components/chat/components/playBar/PlayBar.vue b/src/components/chat/components/playBar/PlayBar.vue
index 1175fa8..fa6337d 100644
--- a/src/components/chat/components/playBar/PlayBar.vue
+++ b/src/components/chat/components/playBar/PlayBar.vue
@@ -20,9 +20,9 @@
 		<div class="h100 flex items-center">
 			<div class="upload_img space-y">
 				<div class="imgbox cursor-pointer flex items-center">
-					<el-button title="AI鐪嬪浘" class="cursor-pointer" link style="margin-left: unset">
+					<!-- <el-button title="AI鐪嬪浘" class="cursor-pointer" link style="margin-left: unset">
 						<img src="/static/images/wave/LookImg.png" class="set-img-icon box-border" />
-					</el-button>
+					</el-button> -->
 					<el-button title="AI璇煶瀵硅瘽" class="cursor-pointer" link style="margin-left: unset" @click="audioChangeWord">
 						<img src="/static/images/wave/HeadImg.png" class="set-img-icon box-border" />
 					</el-button>
@@ -35,22 +35,35 @@
 				</div>
 			</div>
 		</div>
+		<VoicePage
+			v-model:isShow="voicePageIsShow"
+			v-show="voicePageIsShow"
+			@submit="(cb) => emits('sendClick', cb)"
+			@updateInputValue="updateInputValue"
+			:isHome = "isHome"
+		/>
 	</div>
 </template>
 
 <script setup lang="ts">
 import { ElMessage } from 'element-plus';
 import { ref } from 'vue';
-
+import VoicePage from './voicePage/VoicePage.vue';
 const emits = defineEmits(['sendClick']);
 
-const props = defineProps(['isTalking']);
+const props = defineProps(['isTalking','isHome']);
 
+const voicePageIsShow = defineModel('voicePageIsShow', {
+	type: Boolean,
+	default: false,
+});
 const inputValue = defineModel({
 	type: String,
 });
 
-const isListening = ref(false);
+const updateInputValue = (val) => {
+	inputValue.value = val;
+};
 
 const enterInput = (e) => {
 	if (props.isTalking) return;
@@ -63,41 +76,15 @@
 	}
 };
 const audioChangeWord = () => {
-	inputValue.value = '';
-	// 鍒涘缓SpeechRecognition瀵硅薄
-	// eslint-disable-next-line no-undef
-	var recognition = new webkitSpeechRecognition();
-	if (!recognition) {
-		// eslint-disable-next-line no-undef
-		recognition = new SpeechRecognition();
-	}
-	console.log('recognition2', recognition);
-	console.log(11);
-	// 璁剧疆璇█
-	recognition.lang = 'zh-CN';
-	console.log(22);
-	// 寮�濮嬭闊宠瘑鍒�
-	recognition.start();
-	isListening.value = true;
-	console.log(33);
-	// 鐩戝惉璇嗗埆缁撴灉
-	recognition.onresult = function (event) {
-		var result = event.results[0][0].transcript;
-		console.log('鐩戝惉缁撴灉:', result);
-		inputValue.value = result;
-	};
-
-	// 鐩戝惉閿欒浜嬩欢
-	recognition.onerror = function (event) {
-		isListening.value = false;
-		ElMessage.error('鐩戝惉璇煶澶辫触');
-		console.error(event.error);
-	};
-	// 鐩戝惉缁撴潫浜嬩欢锛堝寘鎷瘑鍒垚鍔熴�佽瘑鍒敊璇拰鐢ㄦ埛鍋滄锛�
-	recognition.onend = function () {
-		isListening.value = false;
-		console.log('璇煶璇嗗埆鍋滄');
-	};
+	navigator.getUserMedia(
+		{ audio: true },
+		function onSuccess(stream) {
+			voicePageIsShow.value = true;
+		},
+		function onError(error) {
+			ElMessage.warning('璇锋墦寮�楹﹀厠椋庢潈闄�');
+		}
+	);
 };
 </script>
 <style scoped lang="scss">

--
Gitblit v1.9.3