feat: 语音识别的兼容调整
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
@touchend="handleVoiceTouchEndFromContainer"
|
||||
@touchcancel="handleVoiceTouchEndFromContainer"
|
||||
>
|
||||
<view class="area-input">
|
||||
<view v-if="!visibleWaveBtn || speechProvider !== 'wechat'" class="area-input">
|
||||
<!-- 语音/键盘切换 -->
|
||||
<view
|
||||
v-if="isSpeechRecognitionSupported"
|
||||
@@ -52,6 +52,19 @@
|
||||
@touchend="handleTouchEnd"
|
||||
/>
|
||||
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<view
|
||||
v-if="isVoiceMode"
|
||||
class="hold-to-talk-button"
|
||||
@longpress="handleVoiceTouchStart"
|
||||
@touchend="handleVoiceTouchEnd"
|
||||
@touchcancel="handleVoiceTouchEnd"
|
||||
>
|
||||
按住 说话
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifdef APP-PLUS -->
|
||||
<view
|
||||
v-if="isVoiceMode"
|
||||
class="hold-to-talk-button"
|
||||
@@ -66,6 +79,7 @@
|
||||
/>
|
||||
<text v-else>按住 说话</text>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
|
||||
<view class="input-container-send">
|
||||
@@ -80,6 +94,11 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<!-- 录音按钮 -->
|
||||
<RecordingWaveBtn v-if="visibleWaveBtn" ref="recordingWaveBtnRef" />
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifdef APP-PLUS -->
|
||||
<yao-asdRealSpeech
|
||||
v-if="isSpeechRecognitionSupported && appSpeechVisible"
|
||||
@@ -101,13 +120,20 @@
|
||||
import { ref, computed, watch, nextTick, onMounted, defineExpose, onUnmounted } from "vue";
|
||||
import RecordingWaveBtn from "@/components/Speech/RecordingWaveBtn.vue";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
// #ifdef APP-PLUS
|
||||
import { appSpeechRecognitionOptions } from "@/constant/speech";
|
||||
// #endif
|
||||
|
||||
let manager = null;
|
||||
let speechProvider = "";
|
||||
const isSpeechRecognitionEnabled = ref(true);
|
||||
const isSpeechRecognitionSupported = ref(false);
|
||||
// #ifdef APP-PLUS
|
||||
const appSpeechOptions = appSpeechRecognitionOptions;
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
const appSpeechOptions = {};
|
||||
// #endif
|
||||
|
||||
// WechatSI 是微信小程序插件,App 原生基座没有 requirePlugin。
|
||||
// #ifdef MP-WEIXIN
|
||||
@@ -182,7 +208,7 @@ const startWatchDog = (timeout = 10000) => {
|
||||
watchDogTimer = setTimeout(() => {
|
||||
watchDogTimer = null;
|
||||
console.warn("recording watchdog triggered, forcing UI reset");
|
||||
if (hasActiveVoiceRecognition()) {
|
||||
if (speechProvider === "app" && hasActiveVoiceRecognition()) {
|
||||
stopActiveVoiceRecognition({ shouldSend: true });
|
||||
return;
|
||||
}
|
||||
@@ -258,7 +284,7 @@ watch(inputMessage, (val) => {
|
||||
// 切换语音/文本模式
|
||||
const toggleVoiceMode = () => {
|
||||
if (!isSpeechRecognitionSupported.value) return;
|
||||
if (isVoiceMode.value) {
|
||||
if (speechProvider === "app" && isVoiceMode.value) {
|
||||
stopActiveVoiceRecognition({ shouldSend: false });
|
||||
}
|
||||
isVoiceMode.value = !isVoiceMode.value;
|
||||
@@ -395,6 +421,7 @@ const handleVoiceTouchEnd = () => {
|
||||
};
|
||||
|
||||
const handleVoiceTouchEndFromContainer = () => {
|
||||
if (speechProvider !== "app") return;
|
||||
if (!hasActiveVoiceRecognition()) return;
|
||||
stopActiveVoiceRecognition({ shouldSend: true });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user