|
@@ -124,8 +124,19 @@ const _sfc_main = {
|
|
|
countdownTimer: null,
|
|
|
showGif: false,
|
|
|
// 控制是否显示GIF
|
|
|
- gifUrl: ""
|
|
|
+ gifUrl: "",
|
|
|
// GIF图片的URL
|
|
|
+ // 添加AI语音交互相关属性
|
|
|
+ aiVoiceUrl: "",
|
|
|
+ // AI语音URL
|
|
|
+ aiText: "",
|
|
|
+ // AI回复文本
|
|
|
+ transcribedText: "",
|
|
|
+ // 转写文本
|
|
|
+ isPlayingAiVoice: false,
|
|
|
+ // 是否正在播放AI语音
|
|
|
+ aiAudioPlayer: null
|
|
|
+ // AI语音播放器
|
|
|
};
|
|
|
},
|
|
|
onLoad(options) {
|
|
@@ -156,6 +167,10 @@ const _sfc_main = {
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
this.stopUserCamera();
|
|
|
+ if (this.aiAudioPlayer) {
|
|
|
+ this.aiAudioPlayer.destroy();
|
|
|
+ this.aiAudioPlayer = null;
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
// 初始化相机
|
|
@@ -1327,6 +1342,7 @@ const _sfc_main = {
|
|
|
this.showRetryButton = false;
|
|
|
this.lastVideoToRetry = null;
|
|
|
}
|
|
|
+ this.submitToAiVoiceInteraction(videoUrl);
|
|
|
} else {
|
|
|
if (task) {
|
|
|
this.handleSubmitFailure(task, res.data.msg || "提交失败");
|
|
@@ -1409,6 +1425,10 @@ const _sfc_main = {
|
|
|
// 修改 proceedToNextQuestion 方法
|
|
|
proceedToNextQuestion() {
|
|
|
console.log("准备跳转到下一页面");
|
|
|
+ if (this.isPlayingAiVoice) {
|
|
|
+ console.log("AI语音正在播放,等待播放完成后再跳转");
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.navigateToNextPage();
|
|
|
if (this.uploadQueue.length > 0) {
|
|
|
console.log("上传队列将在后台继续处理...");
|
|
@@ -1417,6 +1437,11 @@ const _sfc_main = {
|
|
|
},
|
|
|
// 修改 navigateToNextPage 方法
|
|
|
navigateToNextPage() {
|
|
|
+ console.log("准备导航到下一个页面");
|
|
|
+ if (this.isPlayingAiVoice) {
|
|
|
+ console.log("AI语音正在播放,等待播放完成后再跳转");
|
|
|
+ return;
|
|
|
+ }
|
|
|
console.log("导航到下一个页面");
|
|
|
common_vendor.index.navigateTo({
|
|
|
url: "/pages/interview-result/interview-result?uploading=" + (this.uploadQueue.length > 0 ? "true" : "false"),
|
|
@@ -1446,9 +1471,11 @@ const _sfc_main = {
|
|
|
duration: 500
|
|
|
// 只显示0.5秒
|
|
|
});
|
|
|
- setTimeout(() => {
|
|
|
+ if (this.lastUploadedVideoUrl) {
|
|
|
+ this.submitToAiVoiceInteraction(this.lastUploadedVideoUrl);
|
|
|
+ } else {
|
|
|
this.navigateToNextPage();
|
|
|
- }, 500);
|
|
|
+ }
|
|
|
},
|
|
|
// 处理相机错误
|
|
|
handleCameraError(e) {
|
|
@@ -1814,6 +1841,138 @@ const _sfc_main = {
|
|
|
} catch (e) {
|
|
|
console.error("保存上传状态失败:", e);
|
|
|
}
|
|
|
+ },
|
|
|
+ // 修改 submitToAiVoiceInteraction 方法,使用 FormData 提交
|
|
|
+ submitToAiVoiceInteraction(videoUrl) {
|
|
|
+ console.log("提交视频到AI语音交互接口:", videoUrl);
|
|
|
+ common_vendor.index.showLoading({
|
|
|
+ title: "AI正在思考...",
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
|
|
|
+ const userInfo = common_vendor.index.getStorageSync("userInfo");
|
|
|
+ const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
|
|
|
+ const systemInfo = common_vendor.index.getSystemInfoSync();
|
|
|
+ const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
|
|
|
+ if (isMiniProgram) {
|
|
|
+ common_vendor.index.request({
|
|
|
+ url: `${common_config.apiBaseUrl}/api/voice_ai_interaction`,
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ url: videoUrl,
|
|
|
+ tenant_id,
|
|
|
+ openid,
|
|
|
+ application_id: common_vendor.index.getStorageSync("appId") || ""
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ "content-type": "application/json"
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ this.handleAiInteractionResponse(res.data);
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ this.handleAiInteractionError(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("url", videoUrl);
|
|
|
+ formData.append("tenant_id", tenant_id);
|
|
|
+ formData.append("openid", openid);
|
|
|
+ formData.append("application_id", common_vendor.index.getStorageSync("appId") || "");
|
|
|
+ const xhr = new XMLHttpRequest();
|
|
|
+ xhr.open("POST", `${common_config.apiBaseUrl}/api/voice_ai_interaction`, true);
|
|
|
+ xhr.timeout = 6e4;
|
|
|
+ xhr.onload = () => {
|
|
|
+ if (xhr.status === 200) {
|
|
|
+ try {
|
|
|
+ const response = JSON.parse(xhr.responseText);
|
|
|
+ this.handleAiInteractionResponse(response);
|
|
|
+ } catch (e) {
|
|
|
+ console.error("解析AI响应失败:", e);
|
|
|
+ this.handleAiInteractionError({ errMsg: "解析响应失败" });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.handleAiInteractionError({ errMsg: "HTTP状态: " + xhr.status });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ xhr.onerror = () => {
|
|
|
+ this.handleAiInteractionError({ errMsg: "网络错误" });
|
|
|
+ };
|
|
|
+ xhr.ontimeout = () => {
|
|
|
+ this.handleAiInteractionError({ errMsg: "请求超时" });
|
|
|
+ };
|
|
|
+ xhr.send(formData);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加处理AI交互响应的方法
|
|
|
+ handleAiInteractionResponse(data) {
|
|
|
+ console.log("AI语音交互接口响应:", data);
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ if (data && data.success) {
|
|
|
+ this.aiText = data.ai_text || "";
|
|
|
+ this.transcribedText = data.transcribed_text ? data.transcribed_text.text : "";
|
|
|
+ const aiVoiceUrl = data.ai_voice_url || "";
|
|
|
+ if (aiVoiceUrl) {
|
|
|
+ this.aiVoiceUrl = aiVoiceUrl.startsWith("http") ? aiVoiceUrl : `${common_config.apiBaseUrl}${aiVoiceUrl}`;
|
|
|
+ console.log("AI语音URL:", this.aiVoiceUrl);
|
|
|
+ this.currentSubtitle = this.aiText;
|
|
|
+ this.playAiVoice();
|
|
|
+ } else {
|
|
|
+ console.warn("未获取到AI语音URL");
|
|
|
+ this.navigateToNextPage();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.error("AI语音交互失败:", data);
|
|
|
+ this.navigateToNextPage();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加处理AI交互错误的方法
|
|
|
+ handleAiInteractionError(err) {
|
|
|
+ console.error("AI语音交互请求失败:", err);
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "AI处理失败,请稍后再试",
|
|
|
+ icon: "none",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ this.navigateToNextPage();
|
|
|
+ },
|
|
|
+ // 添加新方法:播放AI语音
|
|
|
+ playAiVoice() {
|
|
|
+ console.log("开始播放AI语音:", this.aiVoiceUrl);
|
|
|
+ this.isPlayingAiVoice = true;
|
|
|
+ this.aiAudioPlayer = common_vendor.index.createInnerAudioContext();
|
|
|
+ this.aiAudioPlayer.src = this.aiVoiceUrl;
|
|
|
+ this.aiAudioPlayer.autoplay = true;
|
|
|
+ this.aiAudioPlayer.onPlay(() => {
|
|
|
+ console.log("AI语音开始播放");
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "正在播放AI回复",
|
|
|
+ icon: "none",
|
|
|
+ duration: 2e3
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.aiAudioPlayer.onEnded(() => {
|
|
|
+ console.log("AI语音播放结束");
|
|
|
+ this.isPlayingAiVoice = false;
|
|
|
+ this.currentSubtitle = "";
|
|
|
+ if (this.aiAudioPlayer) {
|
|
|
+ this.aiAudioPlayer.destroy();
|
|
|
+ this.aiAudioPlayer = null;
|
|
|
+ }
|
|
|
+ this.navigateToNextPage();
|
|
|
+ });
|
|
|
+ this.aiAudioPlayer.onError((err) => {
|
|
|
+ console.error("AI语音播放错误:", err);
|
|
|
+ this.isPlayingAiVoice = false;
|
|
|
+ this.currentSubtitle = "";
|
|
|
+ if (this.aiAudioPlayer) {
|
|
|
+ this.aiAudioPlayer.destroy();
|
|
|
+ this.aiAudioPlayer = null;
|
|
|
+ }
|
|
|
+ this.navigateToNextPage();
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
};
|