perf: 完善语音转文本
This commit is contained in:
parent
8145a54233
commit
2ea9e02b66
@ -168,7 +168,13 @@
|
|||||||
<el-input
|
<el-input
|
||||||
ref="quickInputRef"
|
ref="quickInputRef"
|
||||||
v-model="inputValue"
|
v-model="inputValue"
|
||||||
placeholder="请输入问题,Ctrl+Enter 换行,Enter发送"
|
:placeholder="
|
||||||
|
startRecorderTime
|
||||||
|
? '说话中...'
|
||||||
|
: recorderLoading
|
||||||
|
? '转文字中...'
|
||||||
|
: '请输入问题,Ctrl+Enter 换行,Enter发送'
|
||||||
|
"
|
||||||
:autosize="{ minRows: 1, maxRows: isMobile ? 4 : 10 }"
|
:autosize="{ minRows: 1, maxRows: isMobile ? 4 : 10 }"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:maxlength="100000"
|
:maxlength="100000"
|
||||||
@ -182,15 +188,21 @@
|
|||||||
<Microphone />
|
<Microphone />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button text v-else @click="stopRecording">
|
<div v-else class="operate flex align-center">
|
||||||
<el-icon>
|
<el-text type="info"
|
||||||
<VideoPause />
|
>00:{{ recorderTime < 10 ? `0${recorderTime}` : recorderTime }}</el-text
|
||||||
</el-icon>
|
>
|
||||||
</el-button>
|
<el-button text type="primary" @click="stopRecording" :loading="recorderLoading">
|
||||||
<el-divider direction="vertical" />
|
<el-icon>
|
||||||
|
<VideoPause />
|
||||||
|
</el-icon>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<el-divider v-if="!startRecorderTime && !recorderLoading" direction="vertical" />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<el-button
|
<el-button
|
||||||
|
v-if="!startRecorderTime && !recorderLoading"
|
||||||
text
|
text
|
||||||
class="sent-button"
|
class="sent-button"
|
||||||
:disabled="isDisabledChart || loading"
|
:disabled="isDisabledChart || loading"
|
||||||
@ -270,7 +282,7 @@ const quickInputRef = ref()
|
|||||||
const scrollDiv = ref()
|
const scrollDiv = ref()
|
||||||
const dialogScrollbar = ref()
|
const dialogScrollbar = ref()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const inputValue = ref('')
|
const inputValue = ref<string>('')
|
||||||
const chartOpenId = ref('')
|
const chartOpenId = ref('')
|
||||||
const chatList = ref<any[]>([])
|
const chatList = ref<any[]>([])
|
||||||
const inputFieldList = ref<FormField[]>([])
|
const inputFieldList = ref<FormField[]>([])
|
||||||
@ -279,6 +291,9 @@ const form_data = ref<any>({})
|
|||||||
const api_form_data = ref<any>({})
|
const api_form_data = ref<any>({})
|
||||||
|
|
||||||
const showUserInput = ref(true)
|
const showUserInput = ref(true)
|
||||||
|
const recorderTime = ref(0)
|
||||||
|
const startRecorderTime = ref(false)
|
||||||
|
const recorderLoading = ref(false)
|
||||||
|
|
||||||
const isDisabledChart = computed(
|
const isDisabledChart = computed(
|
||||||
() => !(inputValue.value.trim() && (props.appId || props.data?.name))
|
() => !(inputValue.value.trim() && (props.appId || props.data?.name))
|
||||||
@ -793,6 +808,7 @@ const mediaRecorderStatus = ref(true)
|
|||||||
const startRecording = async () => {
|
const startRecording = async () => {
|
||||||
try {
|
try {
|
||||||
mediaRecorderStatus.value = false
|
mediaRecorderStatus.value = false
|
||||||
|
handleTimeChange()
|
||||||
mediaRecorder.value = new Recorder({
|
mediaRecorder.value = new Recorder({
|
||||||
type: 'mp3',
|
type: 'mp3',
|
||||||
bitRate: 128,
|
bitRate: 128,
|
||||||
@ -814,6 +830,8 @@ const startRecording = async () => {
|
|||||||
|
|
||||||
// 停止录音
|
// 停止录音
|
||||||
const stopRecording = () => {
|
const stopRecording = () => {
|
||||||
|
startRecorderTime.value = false
|
||||||
|
recorderTime.value = 0
|
||||||
if (mediaRecorder.value) {
|
if (mediaRecorder.value) {
|
||||||
mediaRecorderStatus.value = true
|
mediaRecorderStatus.value = true
|
||||||
mediaRecorder.value.stop(
|
mediaRecorder.value.stop(
|
||||||
@ -823,7 +841,6 @@ const stopRecording = () => {
|
|||||||
// link.href = window.URL.createObjectURL(blob)
|
// link.href = window.URL.createObjectURL(blob)
|
||||||
// link.download = 'abc.mp3'
|
// link.download = 'abc.mp3'
|
||||||
// link.click()
|
// link.click()
|
||||||
|
|
||||||
uploadRecording(blob) // 上传录音文件
|
uploadRecording(blob) // 上传录音文件
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
@ -836,18 +853,39 @@ const stopRecording = () => {
|
|||||||
// 上传录音文件
|
// 上传录音文件
|
||||||
const uploadRecording = async (audioBlob: Blob) => {
|
const uploadRecording = async (audioBlob: Blob) => {
|
||||||
try {
|
try {
|
||||||
|
recorderLoading.value = true
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', audioBlob, 'recording.mp3')
|
formData.append('file', audioBlob, 'recording.mp3')
|
||||||
applicationApi.postSpeechToText(props.data.id as string, formData, loading).then((response) => {
|
applicationApi.postSpeechToText(props.data.id as string, formData, loading).then((response) => {
|
||||||
console.log('上传成功:', response.data)
|
console.log('上传成功:', response.data)
|
||||||
inputValue.value = response.data
|
recorderLoading.value = false
|
||||||
|
mediaRecorder.value.close()
|
||||||
|
inputValue.value = typeof response.data === 'string' ? response.data : ''
|
||||||
// chatMessage(null, res.data)
|
// chatMessage(null, res.data)
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
recorderLoading.value = false
|
||||||
console.error('上传失败:', error)
|
console.error('上传失败:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleTimeChange = () => {
|
||||||
|
startRecorderTime.value = true
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (recorderTime.value === 60) {
|
||||||
|
recorderTime.value = 0
|
||||||
|
stopRecording()
|
||||||
|
startRecorderTime.value = false
|
||||||
|
}
|
||||||
|
if (!startRecorderTime.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recorderTime.value++
|
||||||
|
handleTimeChange()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
handleInputFieldList()
|
handleInputFieldList()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -409,7 +409,7 @@ onBeforeUnmount(() => {
|
|||||||
bottom: 16px;
|
bottom: 16px;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
width: 420px;
|
width: 450px;
|
||||||
height: 600px;
|
height: 600px;
|
||||||
.workflow-debug-header {
|
.workflow-debug-header {
|
||||||
background: var(--app-header-bg-color);
|
background: var(--app-header-bg-color);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user