|
|
@@ -12,14 +12,16 @@
|
|
|
<!-- 收音状态显示区域 - 添加这段代码 -->
|
|
|
<div v-if="isRecording" class="recording-status-container">
|
|
|
<div class="recording-text">正在收音...</div>
|
|
|
- <div class="equalizer">
|
|
|
- <div class="bar bar-1"></div>
|
|
|
- <div class="bar bar-2"></div>
|
|
|
- <div class="bar bar-3"></div>
|
|
|
- <div class="bar bar-4"></div>
|
|
|
- <div class="bar bar-5"></div>
|
|
|
- <div class="bar bar-6"></div>
|
|
|
- <div class="bar bar-7"></div>
|
|
|
+ <div class="waveform-container">
|
|
|
+ <LiveWaveform
|
|
|
+ :active="isRecording"
|
|
|
+ :processing="false"
|
|
|
+ :height="50"
|
|
|
+ :barWidth="3"
|
|
|
+ :barGap="1"
|
|
|
+ :barRadius="1"
|
|
|
+ :sensitivity="1.2"
|
|
|
+ />
|
|
|
</div>
|
|
|
<div v-if="recordingCountdown <= 5" class="recording-countdown">{{ recordingCountdown }}秒</div>
|
|
|
</div>
|
|
|
@@ -215,6 +217,8 @@ import { globalState } from "@/utils/globalState.js";
|
|
|
//音乐
|
|
|
import { playMusic, stopMusic, onMusicEnded } from "@/api/blockly/music.js";
|
|
|
import {ElButton} from "element-plus";
|
|
|
+import LiveWaveform from '../../components/ai/voice/LiveWaveform.vue';
|
|
|
+
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
@@ -231,19 +235,20 @@ const showLampPreview = ref(true);
|
|
|
const isRecording = ref(false);
|
|
|
const recordingCountdown = ref(10);
|
|
|
let countdownInterval = null;
|
|
|
+let recognition = null;
|
|
|
|
|
|
// 返回虚拟实验室
|
|
|
const goLabShow = () => {
|
|
|
showLampPreview.value = true;
|
|
|
};
|
|
|
const goBack = () => {
|
|
|
- window.location.href = "/virtual-laboratory";
|
|
|
+ router.push("/virtual-laboratory");
|
|
|
};
|
|
|
// 切换灯光状态
|
|
|
const toggleLight = () => {
|
|
|
state.lamp.isLightOn = true;
|
|
|
- generateCode('javascript');
|
|
|
- runCode();
|
|
|
+ generateCode('javascript');
|
|
|
+ runCode();
|
|
|
};
|
|
|
|
|
|
// 添加开始录音状态函数
|
|
|
@@ -449,6 +454,8 @@ const aiService = {
|
|
|
console.log("语音识别开始");
|
|
|
// 前端语音采集
|
|
|
const recognitionResult = await this.captureVoice(language, promptText);
|
|
|
+ console.log("-============-1-",recognitionResult);
|
|
|
+
|
|
|
return recognitionResult || "";
|
|
|
}, '语音识别失败'),
|
|
|
|
|
|
@@ -465,7 +472,7 @@ const aiService = {
|
|
|
}
|
|
|
|
|
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
|
- const recognition = new SpeechRecognition();
|
|
|
+ recognition = new SpeechRecognition();
|
|
|
|
|
|
recognition.lang = language;
|
|
|
recognition.interimResults = false;
|
|
|
@@ -906,9 +913,13 @@ onMounted(() => {
|
|
|
// 从全局状态初始化年级ID
|
|
|
state.gradeId = globalState.initGradeId();
|
|
|
|
|
|
- device.value.name = router.currentRoute.value.query.name || "";
|
|
|
- device.value.image = router.currentRoute.value.query.image || "";
|
|
|
- device.value.jsonData = JSON.parse(router.currentRoute.value.query.jsonData || {});
|
|
|
+ // 从 window.history.state 接收参数
|
|
|
+ const routeState = window.history.state || {};
|
|
|
+ device.value.name = routeState.name || "";
|
|
|
+ device.value.image = routeState.image || "";
|
|
|
+ device.value.jsonData = JSON.parse(routeState.jsonData || {});
|
|
|
+ console.log("----------",device.value);
|
|
|
+
|
|
|
|
|
|
// 注册AI语音识别积木
|
|
|
Blockly.Blocks["ai_voice_input"] = {
|
|
|
@@ -1314,6 +1325,7 @@ const loadWorkspaceFromJson = () => {
|
|
|
const json = device.value.jsonData;
|
|
|
console.log(typeof json);
|
|
|
Blockly.serialization.workspaces.load(json, workspace);
|
|
|
+ console.log("------------22jiazai:",typeof json, json);
|
|
|
showStatus('工作区已成功从JSON加载!');
|
|
|
} catch (error) {
|
|
|
showStatus('JSON解析错误: ' + error.message, 'error');
|
|
|
@@ -2027,6 +2039,14 @@ textarea {
|
|
|
font-weight: bold;
|
|
|
}
|
|
|
|
|
|
+.waveform-container {
|
|
|
+ margin: 10px 0;
|
|
|
+ width: 100%;
|
|
|
+ max-width: 200px;
|
|
|
+ margin-left: auto;
|
|
|
+ margin-right: auto;
|
|
|
+}
|
|
|
+
|
|
|
.equalizer {
|
|
|
display: flex;
|
|
|
justify-content: center;
|