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