update voice
This commit is contained in:
1 parent
d91f5ed5cb
commit
34a12e85bc
3 files changed
+87
-1
No files matched your search
@@ -8,6 +8,7 @@
|
||||
@keyup.enter="$emit('send')"
|
||||
>
|
||||
<template #suffix>
|
||||
<voice-recognition v-if="false" class="mr-1" @finished="value = $event" />
|
||||
<font-awesome-icon icon="fa-regular fa-paper-plane" class="icon-send" @click="$emit('send')" />
|
||||
</template>
|
||||
</el-input>
|
||||
@@ -42,6 +43,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { IApi, IApplication } from '@/operators';
|
||||
import { IApplicationType } from '@/operators';
|
||||
import ApplicationConfirm from '@/components/application/Confirm.vue';
|
||||
import VoiceRecognition from './VoiceRecognition.vue';
|
||||
|
||||
interface IData {
|
||||
applicationType: typeof IApplicationType;
|
||||
@@ -55,7 +57,8 @@ export default defineComponent({
|
||||
ElInput,
|
||||
ElButton,
|
||||
FontAwesomeIcon,
|
||||
ApplicationConfirm
|
||||
ApplicationConfirm,
|
||||
VoiceRecognition
|
||||
},
|
||||
props: {
|
||||
initializing: {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<template>
|
||||
<font-awesome-icon icon="fa-solid fa-microphone" class="icon-edit" @click="onToggleRecognition" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'VoiceRecognition',
|
||||
components: {
|
||||
FontAwesomeIcon
|
||||
},
|
||||
emits: ['finished'],
|
||||
data() {
|
||||
return {
|
||||
supported: false,
|
||||
recognition: undefined,
|
||||
started: false,
|
||||
result: ''
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
|
||||
this.supported = true;
|
||||
// @ts-ignore
|
||||
this.recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
||||
if (this.recognition) {
|
||||
// @ts-ignore
|
||||
this.recognition.lang = 'zh-CN';
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
this.recognition?.addEventListener('result', (event) => {
|
||||
const transcript = event.results[0][0].transcript;
|
||||
this.result = transcript;
|
||||
console.log('result', this.result);
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
this.recognition?.addEventListener('error', (event) => {
|
||||
console.log('Recognition error:', event.error);
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
this.recognition?.addEventListener('end', () => {
|
||||
console.log('Recognition ended');
|
||||
console.log('result', this.result);
|
||||
this.$emit('finished', this.result);
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
startRecognition() {
|
||||
// @ts-ignore
|
||||
this.recognition?.start();
|
||||
this.started = true;
|
||||
},
|
||||
stopRecognition() {
|
||||
// @ts-ignore
|
||||
this.recognition?.stop();
|
||||
this.started = true;
|
||||
},
|
||||
onToggleRecognition() {
|
||||
if (!this.started) {
|
||||
this.startRecognition();
|
||||
} else {
|
||||
this.stopRecognition();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.introduction-item {
|
||||
font-size: 14px;
|
||||
background-color: #eee;
|
||||
color: #333;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
faSun as faRegularSun
|
||||
} from '@fortawesome/free-regular-svg-icons';
|
||||
import {
|
||||
faMicrophone as faSolidMicrophone,
|
||||
faRotateRight as faSolidRotateRight,
|
||||
faCheck as faSolidCheck,
|
||||
faPlus as faSolidPlus,
|
||||
@@ -28,6 +29,7 @@ library.add(faSolidCheck);
|
||||
library.add(faRegularUser);
|
||||
library.add(faRegularSun);
|
||||
library.add(faSolidBolt);
|
||||
library.add(faSolidMicrophone);
|
||||
library.add(faSolidPlus);
|
||||
library.add(faSolidQuestion);
|
||||
library.add(faSolidTriangleExclamation);
|
||||
|
||||
Reference in new issue
Block a user