flat: 添加语音播放提示

This commit is contained in:
Apcallover
2025-12-20 15:10:44 +08:00
parent 02fef1700b
commit 1bacbe4936
5 changed files with 97 additions and 29 deletions

View File

@@ -6,6 +6,7 @@ import useUserStore from './stores/useUserStore';
import usePageAnimation from './hook/usePageAnimation'; import usePageAnimation from './hook/usePageAnimation';
import useDictStore from './stores/useDictStore'; import useDictStore from './stores/useDictStore';
import { GlobalInactivityManager } from '@/utils/GlobalInactivityManager'; import { GlobalInactivityManager } from '@/utils/GlobalInactivityManager';
import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one';
const { const {
$api, $api,
navTo, navTo,
@@ -98,6 +99,7 @@ function handleInactivity() {
if (useUserStore().hasLogin) { if (useUserStore().hasLogin) {
// 1. 正常弹出确认框 // 1. 正常弹出确认框
playTextDirectly('长时间无操作,是否继续使用?');
$confirm({ $confirm({
title: '会话即将过期', title: '会话即将过期',
content: '长时间无操作,是否继续使用?', content: '长时间无操作,是否继续使用?',

View File

@@ -4,6 +4,9 @@ import {
} from "./globalFunction"; } from "./globalFunction";
import baseDB from '@/utils/db.js'; import baseDB from '@/utils/db.js';
import useUserStore from '@/stores/useUserStore'; import useUserStore from '@/stores/useUserStore';
import {
playTextDirectly
} from '@/hook/useTTSPlayer-all-in-one'
export class IncreaseRevie { export class IncreaseRevie {
constructor(arg) { constructor(arg) {
@@ -52,6 +55,7 @@ export class IncreaseRevie {
useUserStore() useUserStore()
.loginSetToken(resData.token) .loginSetToken(resData.token)
.then((resume) => { .then((resume) => {
playTextDirectly('登录成功')
if (resume.data.jobTitleId) { if (resume.data.jobTitleId) {
useUserStore().initSeesionId(); useUserStore().initSeesionId();
safeReLaunch('/pages/index/index'); safeReLaunch('/pages/index/index');
@@ -63,6 +67,7 @@ export class IncreaseRevie {
} }
} else { } else {
$api.msg('识别失败') $api.msg('识别失败')
playTextDirectly('识别失败')
} }
} }
} }

View File

@@ -6,6 +6,69 @@ import {
onHide, onHide,
onUnload onUnload
} from '@dcloudio/uni-app' } from '@dcloudio/uni-app'
import {
isY9MachineType
} from '../common/globalFunction';
/**
* 封装 hh.call 通用调用
*/
const callBridge = (params) => {
return new Promise((resolve) => {
if (typeof window !== 'undefined' && window.hh && window.hh.call) {
// 打印日志方便调试
console.log('[TTS Bridge Send]:', params)
window.hh.call("ampeHHCommunication", params, (res) => {
console.log('[TTS Bridge Res]:', res)
resolve(res)
})
} else {
console.warn('当前环境不支持 hh.call模拟成功')
resolve({
success: true
})
}
})
}
/**
* 生成随机 TaskId
*/
const generateTaskId = () => {
return 'task_' + Date.now() + '_' + Math.floor(Math.random() * 1000)
}
/**
* 直接播放文本 (静态方法,无需实例化 Hook)
* @param {string} text - 需要朗读的文本
*/
export async function playTextDirectly(text) {
if (!text) return
if (!isY9MachineType()) return
const processedText = extractSpeechText(text)
if (!processedText) return
try {
// 构造播放参数
const params = {
"action": "speech",
"event": "open",
"taskId": generateTaskId(),
"params": {
"text": processedText,
"pitch": 1.0,
"rate": 1.0,
"speechQueue": 1 // 1表示打断当前播放立即播放新的
}
}
// 直接调用
await callBridge(params)
} catch (e) {
console.error('Direct Play Error:', e)
}
}
/** /**
* 一体机 TTS 播放器 Hook (修复版) * 一体机 TTS 播放器 Hook (修复版)
@@ -19,34 +82,6 @@ export function useTTSPlayer() {
// 记录最后一次播放的文本 // 记录最后一次播放的文本
const lastText = ref('') const lastText = ref('')
/**
* 封装 hh.call 通用调用
*/
const callBridge = (params) => {
return new Promise((resolve) => {
if (typeof window !== 'undefined' && window.hh && window.hh.call) {
// 打印日志方便调试
console.log('[TTS Bridge Send]:', params)
window.hh.call("ampeHHCommunication", params, (res) => {
console.log('[TTS Bridge Res]:', res)
resolve(res)
})
} else {
console.warn('当前环境不支持 hh.call模拟成功')
resolve({
success: true
})
}
})
}
/**
* 生成随机 TaskId
*/
const generateTaskId = () => {
return 'task_' + Date.now() + '_' + Math.floor(Math.random() * 1000)
}
/** /**
* 停止 (中断) - 内部使用 * 停止 (中断) - 内部使用
*/ */
@@ -222,3 +257,18 @@ function extractSpeechText(markdown) {
if (endingText) finalTextParts.push(endingText); if (endingText) finalTextParts.push(endingText);
return finalTextParts.join('\n'); return finalTextParts.join('\n');
} }
// 使用方法 1
// import { useTTSPlayer } from '@/hook/useTTSPlayer-all-in-one'
// const { speak, stop, isSpeaking } = useTTSPlayer()
// // 调用
// speak('你好,这是一段测试文本')
// 使用方法 2
// import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one'
// // 直接调用即可,无需实例化
// playTextDirectly('直接朗读这段话不需要处理暂停和UI状态')

View File

@@ -185,6 +185,7 @@ import dictLabel from '@/components/dict-Label/dict-Label.vue';
import RadarMap from './component/radarMap.vue'; import RadarMap from './component/radarMap.vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import useUserStore from '@/stores/useUserStore'; import useUserStore from '@/stores/useUserStore';
import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one';
const { isMiniProgram, hasLogin } = storeToRefs(useUserStore()); const { isMiniProgram, hasLogin } = storeToRefs(useUserStore());
const { $api, navTo, getLenPx, parseQueryParams, navBack, isEmptyObject } = inject('globalFunction'); const { $api, navTo, getLenPx, parseQueryParams, navBack, isEmptyObject } = inject('globalFunction');
@@ -331,10 +332,12 @@ function jobApply() {
}; };
if (jobInfo.value.isApply) { if (jobInfo.value.isApply) {
$api.msg('已经投递过该岗位了~'); $api.msg('已经投递过该岗位了~');
playTextDirectly('已经投递过该岗位了');
return; return;
} else { } else {
$api.createRequest(`/app/internal/sendResume`, params, 'POST').then((resData) => { $api.createRequest(`/app/internal/sendResume`, params, 'POST').then((resData) => {
$api.msg('投递成功'); $api.msg('投递成功');
playTextDirectly('投递成功');
getDetail(jobIdRef.value); getDetail(jobIdRef.value);
}); });
} }
@@ -348,6 +351,7 @@ function jobApply() {
$api.createRequest(`/app/job/apply/${jobId}`, {}, 'GET').then((resData) => { $api.createRequest(`/app/job/apply/${jobId}`, {}, 'GET').then((resData) => {
getDetail(jobId); getDetail(jobId);
$api.msg('申请成功'); $api.msg('申请成功');
playTextDirectly('申请成功');
const jobUrl = jobInfo.value.jobUrl; const jobUrl = jobInfo.value.jobUrl;
return window.open(jobUrl); return window.open(jobUrl);
}); });
@@ -364,11 +368,13 @@ function jobCollection() {
$api.createRequest(`/app/job/collection/${id}/2`, {}, 'DELETE').then((resData) => { $api.createRequest(`/app/job/collection/${id}/2`, {}, 'DELETE').then((resData) => {
getDetail(jobIdRef.value); getDetail(jobIdRef.value);
$api.msg('取消收藏成功'); $api.msg('取消收藏成功');
playTextDirectly('取消收藏成功');
}); });
} else { } else {
$api.createRequest(`/app/job/collection/${id}/2`, {}, 'POST').then((resData) => { $api.createRequest(`/app/job/collection/${id}/2`, {}, 'POST').then((resData) => {
getDetail(jobIdRef.value); getDetail(jobIdRef.value);
$api.msg('收藏成功'); $api.msg('收藏成功');
playTextDirectly('收藏成功');
}); });
} }
} else { } else {
@@ -378,11 +384,13 @@ function jobCollection() {
$api.createRequest(`/app/job/collection/${jobId}/1`, {}, 'DELETE').then((resData) => { $api.createRequest(`/app/job/collection/${jobId}/1`, {}, 'DELETE').then((resData) => {
getDetail(jobId); getDetail(jobId);
$api.msg('取消收藏成功'); $api.msg('取消收藏成功');
playTextDirectly('取消收藏成功');
}); });
} else { } else {
$api.createRequest(`/app/job/collection/${jobId}/1`, {}, 'POST').then((resData) => { $api.createRequest(`/app/job/collection/${jobId}/1`, {}, 'POST').then((resData) => {
getDetail(jobId); getDetail(jobId);
$api.msg('收藏成功'); $api.msg('收藏成功');
playTextDirectly('收藏成功');
}); });
} }
} }

View File

@@ -196,11 +196,13 @@ import { reactive, inject, watch, ref, onMounted, onUnmounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app'; import { onLoad, onShow } from '@dcloudio/uni-app';
import useUserStore from '@/stores/useUserStore'; import useUserStore from '@/stores/useUserStore';
import useDictStore from '@/stores/useDictStore'; import useDictStore from '@/stores/useDictStore';
import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one';
const { $api, navTo } = inject('globalFunction'); const { $api, navTo } = inject('globalFunction');
const { loginSetToken, getUserResume } = useUserStore(); const { loginSetToken, getUserResume } = useUserStore();
const { isMachineEnv } = storeToRefs(useUserStore()); const { isMachineEnv } = storeToRefs(useUserStore());
const { getDictSelectOption, oneDictData } = useDictStore(); const { getDictSelectOption, oneDictData } = useDictStore();
const openSelectPopup = inject('openSelectPopup'); const openSelectPopup = inject('openSelectPopup');
// status // status
const selectJobsModel = ref(); const selectJobsModel = ref();
const tabCurrent = ref(1); const tabCurrent = ref(1);
@@ -242,6 +244,7 @@ onMounted(() => {
if (isMachineEnv) { if (isMachineEnv) {
startCountdown(); startCountdown();
startScanAnimation(); startScanAnimation();
playTextDirectly('请进行用户登录');
} }
}); });
onUnmounted(() => { onUnmounted(() => {