Skip to content

Commit 28b792a

Browse files
committed
feat: support autoplay answer for tts model
1 parent f9b1f2d commit 28b792a

File tree

8 files changed

+57
-25
lines changed

8 files changed

+57
-25
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-03 14:07
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('application', '0021_applicationpublicaccessclient_client_id_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='application',
15+
name='tts_autoplay',
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
@@ -65,6 +65,7 @@ class Application(AppModelMixin):
6565
tts_model_enable = models.BooleanField(verbose_name="语音合成模型是否启用", default=False)
6666
stt_model_enable = models.BooleanField(verbose_name="语音识别模型是否启用", default=False)
6767
tts_type = models.CharField(verbose_name="语音播放类型", max_length=20, default="BROWSER")
68+
tts_autoplay = models.BooleanField(verbose_name="自动播放", default=False)
6869
clean_time = models.IntegerField(verbose_name="清理时间", default=180)
6970
file_upload_enable = models.BooleanField(verbose_name="文件上传是否启用", default=False)
7071
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-
'file_upload_enable', 'file_upload_setting',
1012+
'tts_autoplay', '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:
@@ -1073,6 +1073,8 @@ def get_work_flow_model(instance):
10731073
instance['tts_model_enable'] = node_data['tts_model_enable']
10741074
if 'tts_type' in node_data:
10751075
instance['tts_type'] = node_data['tts_type']
1076+
if 'tts_autoplay' in node_data:
1077+
instance['tts_autoplay'] = node_data['tts_autoplay']
10761078
if 'tts_model_params_setting' in node_data:
10771079
instance['tts_model_params_setting'] = node_data['tts_model_params_setting']
10781080
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
@@ -21,6 +21,7 @@ interface ApplicationFormType {
2121
stt_model_enable?: boolean
2222
tts_model_enable?: boolean
2323
tts_type?: string
24+
tts_autoplay?: boolean
2425
}
2526
interface Chunk {
2627
real_node_id: string

ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<audio ref="audioPlayer" controls hidden="hidden"></audio>
8080
</template>
8181
<script setup lang="ts">
82-
import { ref } from 'vue'
82+
import { onMounted, ref } from 'vue'
8383
import { useRoute } from 'vue-router'
8484
import { copyClick } from '@/utils/clipboard'
8585
import applicationApi from '@/api/application'
@@ -100,6 +100,7 @@ const props = withDefaults(
100100
applicationId: string
101101
tts: boolean
102102
tts_type: string
103+
tts_autoplay: boolean
103104
}>(),
104105
{
105106
data: () => ({}),
@@ -243,5 +244,12 @@ const pausePlayAnswerText = () => {
243244
window.speechSynthesis.pause()
244245
}
245246
}
247+
248+
onMounted(() => {
249+
// 第一次回答后自动播放, 打开历史记录不自动播放
250+
if (props.tts_autoplay && buttonData.value.write_ed && !buttonData.value.update_time) {
251+
playAnswerText(buttonData.value.answer_text)
252+
}
253+
})
246254
</script>
247255
<style lang="scss" scoped></style>

ui/src/components/ai-chat/component/operation-button/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<ChatOperationButton
3333
:tts="application.tts_model_enable"
3434
:tts_type="application.tts_type"
35+
:tts_autoplay="application.tts_autoplay"
3536
:data="chatRecord"
3637
:type="type"
3738
:applicationId="application.id"

ui/src/views/application/ApplicationSetting.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,7 @@
403403
<div class="flex-between">
404404
<span class="mr-4">语音播放</span>
405405
<div>
406-
<el-button
407-
v-if="applicationForm.tts_type === 'TTS'"
408-
type="primary"
409-
link
410-
@click="openTTSParamSettingDialog"
411-
:disabled="!applicationForm.tts_model_id"
412-
class="mr-8"
413-
>
414-
<el-icon class="mr-4"><Setting /></el-icon>
415-
设置
416-
</el-button>
406+
<el-checkbox v-model="applicationForm.tts_autoplay">自动播放</el-checkbox>
417407
<el-switch
418408
size="small"
419409
v-model="applicationForm.tts_model_enable"
@@ -492,6 +482,16 @@
492482
</el-option>
493483
</el-option-group>
494484
</el-select>
485+
<el-button
486+
v-if="applicationForm.tts_type === 'TTS'"
487+
type="primary"
488+
link
489+
@click="openTTSParamSettingDialog"
490+
:disabled="!applicationForm.tts_model_id"
491+
class="mr-8"
492+
>
493+
<el-icon class="mr-4"><Setting /></el-icon>
494+
</el-button>
495495
</el-form-item>
496496
</el-form>
497497
</el-scrollbar>

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,7 @@
167167
<div class="flex-between">
168168
<span class="mr-4">语音播放</span>
169169
<div>
170-
<el-button
171-
v-if="form_data.tts_type === 'TTS' && form_data.tts_model_enable"
172-
type="primary"
173-
link
174-
@click="openTTSParamSettingDialog"
175-
:disabled="!form_data.tts_model_id"
176-
class="mr-4"
177-
>
178-
<el-icon class="mr-4">
179-
<Setting />
180-
</el-icon>
181-
</el-button>
170+
<el-checkbox v-model="form_data.tts_autoplay">自动播放</el-checkbox>
182171
<el-switch
183172
size="small"
184173
v-model="form_data.tts_model_enable"
@@ -252,6 +241,18 @@
252241
</el-option>
253242
</el-option-group>
254243
</el-select>
244+
<el-button
245+
v-if="form_data.tts_type === 'TTS' && form_data.tts_model_enable"
246+
type="primary"
247+
link
248+
@click="openTTSParamSettingDialog"
249+
:disabled="!form_data.tts_model_id"
250+
class="mr-4"
251+
>
252+
<el-icon class="mr-4">
253+
<Setting />
254+
</el-icon>
255+
</el-button>
255256
</el-form-item>
256257
</el-form>
257258
<TTSModeParamSettingDialog ref="TTSModeParamSettingDialogRef" @refresh="refreshTTSForm" />

0 commit comments

Comments
 (0)