Skip to content

Commit 6b248cd

Browse files
committed
feat: Support stt mode auto send message
--story=1017616 --user=刘瑞斌 【应用】语音输入支持自动发送 https://www.tapd.cn/57709429/s/1641715
1 parent 301c60e commit 6b248cd

File tree

7 files changed

+65
-44
lines changed

7 files changed

+65
-44
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.15 on 2025-01-06 10:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('application', '0022_application_tts_autoplay'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='application',
15+
name='stt_autosend',
16+
field=models.BooleanField(default=False, verbose_name='自动发送'),
17+
),
18+
]

apps/application/models/application.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Application(AppModelMixin):
6666
stt_model_enable = models.BooleanField(verbose_name="语音识别模型是否启用", default=False)
6767
tts_type = models.CharField(verbose_name="语音播放类型", max_length=20, default="BROWSER")
6868
tts_autoplay = models.BooleanField(verbose_name="自动播放", default=False)
69+
stt_autosend = models.BooleanField(verbose_name="自动发送", default=False)
6970
clean_time = models.IntegerField(verbose_name="清理时间", default=180)
7071
file_upload_enable = models.BooleanField(verbose_name="文件上传是否启用", default=False)
7172
file_upload_setting = models.JSONField(verbose_name="文件上传相关设置", default=dict)

apps/application/serializers/application_serializers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ def edit(self, instance: Dict, with_valid=True):
10091009
update_keys = ['name', 'desc', 'model_id', 'multiple_rounds_dialogue', 'prologue', 'status',
10101010
'dataset_setting', 'model_setting', 'problem_optimization', 'dialogue_number',
10111011
'stt_model_id', 'tts_model_id', 'tts_model_enable', 'stt_model_enable', 'tts_type',
1012-
'tts_autoplay', 'file_upload_enable', 'file_upload_setting',
1012+
'tts_autoplay', 'stt_autosend', 'file_upload_enable', 'file_upload_setting',
10131013
'api_key_is_active', 'icon', 'work_flow', 'model_params_setting', 'tts_model_params_setting',
10141014
'problem_optimization_prompt', 'clean_time']
10151015
for update_key in update_keys:
@@ -1075,6 +1075,8 @@ def get_work_flow_model(instance):
10751075
instance['tts_type'] = node_data['tts_type']
10761076
if 'tts_autoplay' in node_data:
10771077
instance['tts_autoplay'] = node_data['tts_autoplay']
1078+
if 'stt_autosend' in node_data:
1079+
instance['stt_autosend'] = node_data['stt_autosend']
10781080
if 'tts_model_params_setting' in node_data:
10791081
instance['tts_model_params_setting'] = node_data['tts_model_params_setting']
10801082
if 'file_upload_enable' in node_data:

ui/src/api/type/application.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface ApplicationFormType {
2222
tts_model_enable?: boolean
2323
tts_type?: string
2424
tts_autoplay?: boolean
25+
stt_autosend?: boolean
2526
}
2627
interface Chunk {
2728
real_node_id: string

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
</div>
176176
</template>
177177
<script setup lang="ts">
178-
import { ref, computed, onMounted } from 'vue'
178+
import { ref, computed, onMounted, nextTick } from 'vue'
179179
import Recorder from 'recorder-core'
180180
import applicationApi from '@/api/application'
181181
import { MsgAlert } from '@/utils/message'
@@ -254,7 +254,7 @@ const getAcceptList = () => {
254254
if (video) {
255255
accepts = [...accepts, ...videoExtensions]
256256
}
257-
// console.log(accepts)
257+
258258
if (accepts.length === 0) {
259259
return '.请在文件上传配置中选择文件类型'
260260
}
@@ -462,7 +462,12 @@ const uploadRecording = async (audioBlob: Blob) => {
462462
recorderLoading.value = false
463463
mediaRecorder.value.close()
464464
inputValue.value = typeof response.data === 'string' ? response.data : ''
465-
// chatMessage(null, res.data)
465+
// 自动发送
466+
if (props.applicationDetails.stt_autosend) {
467+
nextTick(() => {
468+
autoSendMessage()
469+
})
470+
}
466471
})
467472
} catch (error) {
468473
recorderLoading.value = false
@@ -486,24 +491,28 @@ const handleTimeChange = () => {
486491
}, 1000)
487492
}
488493
494+
function autoSendMessage() {
495+
props.sendMessage(inputValue.value, {
496+
image_list: uploadImageList.value,
497+
document_list: uploadDocumentList.value,
498+
audio_list: uploadAudioList.value,
499+
video_list: uploadVideoList.value
500+
})
501+
inputValue.value = ''
502+
uploadImageList.value = []
503+
uploadDocumentList.value = []
504+
uploadAudioList.value = []
505+
uploadVideoList.value = []
506+
quickInputRef.value.textareaStyle.height = '45px'
507+
}
508+
489509
function sendChatHandle(event?: any) {
490510
if (!event?.ctrlKey) {
491511
// 如果没有按下组合键ctrl,则会阻止默认事件
492512
event?.preventDefault()
493513
if (!isDisabledChart.value && !props.loading && !event?.isComposing) {
494514
if (inputValue.value.trim()) {
495-
props.sendMessage(inputValue.value, {
496-
image_list: uploadImageList.value,
497-
document_list: uploadDocumentList.value,
498-
audio_list: uploadAudioList.value,
499-
video_list: uploadVideoList.value
500-
})
501-
inputValue.value = ''
502-
uploadImageList.value = []
503-
uploadDocumentList.value = []
504-
uploadAudioList.value = []
505-
uploadVideoList.value = []
506-
quickInputRef.value.textareaStyle.height = '45px'
515+
autoSendMessage()
507516
}
508517
}
509518
} else {

ui/src/views/application/ApplicationSetting.vue

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,16 @@
319319
<el-form-item>
320320
<template #label>
321321
<div class="flex-between">
322-
<div class="flex align-center">
323-
<span class="mr-4">语音输入</span>
324-
<!-- <el-tooltip
325-
effect="dark"
326-
content="开启后,需要设定语音转文本模型,语音输入完成后会转化为文字直接发送提问"
327-
placement="right"
328-
>
329-
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
330-
</el-tooltip> -->
322+
<span class="mr-4">语音输入</span>
323+
<div class="flex">
324+
<el-checkbox v-model="applicationForm.stt_autosend">自动发送</el-checkbox>
325+
<el-switch
326+
class="ml-8"
327+
size="small"
328+
v-model="applicationForm.stt_model_enable"
329+
@change="sttModelEnableChange"
330+
/>
331331
</div>
332-
<el-switch
333-
size="small"
334-
v-model="applicationForm.stt_model_enable"
335-
@change="sttModelEnableChange"
336-
/>
337332
</div>
338333
</template>
339334
<el-select

ui/src/workflow/nodes/base-node/index.vue

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,16 @@
8484
<el-form-item>
8585
<template #label>
8686
<div class="flex-between">
87-
<div class="flex align-center">
88-
<span class="mr-4">语音输入</span>
89-
<!-- <el-tooltip
90-
effect="dark"
91-
content="开启后,需要设定语音转文本模型,语音输入完成后会转化为文字直接发送提问"
92-
placement="right"
93-
>
94-
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
95-
</el-tooltip> -->
87+
<span class="mr-4">语音输入</span>
88+
<div class="flex">
89+
<el-checkbox v-model="form_data.stt_autosend">自动发送</el-checkbox>
90+
<el-switch
91+
class="ml-8"
92+
size="small"
93+
v-model="form_data.stt_model_enable"
94+
@change="sttModelEnableChange"
95+
/>
9696
</div>
97-
<el-switch
98-
size="small"
99-
v-model="form_data.stt_model_enable"
100-
@change="sttModelEnableChange"
101-
/>
10297
</div>
10398
</template>
10499

0 commit comments

Comments
 (0)