mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
update: 增加智能体独立音频设置
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.agent.dto;
|
package xiaozhi.modules.agent.dto;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -44,6 +45,15 @@ public class AgentUpdateDTO implements Serializable {
|
|||||||
@Schema(description = "音色语言", example = "普通话", nullable = true)
|
@Schema(description = "音色语言", example = "普通话", nullable = true)
|
||||||
private String ttsLanguage;
|
private String ttsLanguage;
|
||||||
|
|
||||||
|
@Schema(description = "TTS音量", example = "50", nullable = true)
|
||||||
|
private Integer ttsVolume;
|
||||||
|
|
||||||
|
@Schema(description = "TTS语速", example = "50", nullable = true)
|
||||||
|
private Integer ttsRate;
|
||||||
|
|
||||||
|
@Schema(description = "TTS音调", example = "50", nullable = true)
|
||||||
|
private Integer ttsPitch;
|
||||||
|
|
||||||
@Schema(description = "记忆模型标识", example = "mem_model_02", nullable = true)
|
@Schema(description = "记忆模型标识", example = "mem_model_02", nullable = true)
|
||||||
private String memModelId;
|
private String memModelId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package xiaozhi.modules.agent.entity;
|
package xiaozhi.modules.agent.entity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
@@ -48,6 +49,15 @@ public class AgentEntity {
|
|||||||
@Schema(description = "音色语言")
|
@Schema(description = "音色语言")
|
||||||
private String ttsLanguage;
|
private String ttsLanguage;
|
||||||
|
|
||||||
|
@Schema(description = "TTS音量")
|
||||||
|
private Integer ttsVolume;
|
||||||
|
|
||||||
|
@Schema(description = "TTS语速")
|
||||||
|
private Integer ttsRate;
|
||||||
|
|
||||||
|
@Schema(description = "TTS音调")
|
||||||
|
private Integer ttsPitch;
|
||||||
|
|
||||||
@Schema(description = "记忆模型标识")
|
@Schema(description = "记忆模型标识")
|
||||||
private String memModelId;
|
private String memModelId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.agent.entity;
|
package xiaozhi.modules.agent.entity;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
@@ -69,6 +70,21 @@ public class AgentTemplateEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String ttsLanguage;
|
private String ttsLanguage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTS音量
|
||||||
|
*/
|
||||||
|
private Integer ttsVolume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTS语速
|
||||||
|
*/
|
||||||
|
private Integer ttsRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTS音调
|
||||||
|
*/
|
||||||
|
private Integer ttsPitch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记忆模型标识
|
* 记忆模型标识
|
||||||
*/
|
*/
|
||||||
|
|||||||
+9
@@ -285,6 +285,15 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
if (dto.getTtsLanguage() != null) {
|
if (dto.getTtsLanguage() != null) {
|
||||||
existingEntity.setTtsLanguage(dto.getTtsLanguage());
|
existingEntity.setTtsLanguage(dto.getTtsLanguage());
|
||||||
}
|
}
|
||||||
|
if (dto.getTtsVolume() != null) {
|
||||||
|
existingEntity.setTtsVolume(dto.getTtsVolume());
|
||||||
|
}
|
||||||
|
if (dto.getTtsRate() != null) {
|
||||||
|
existingEntity.setTtsRate(dto.getTtsRate());
|
||||||
|
}
|
||||||
|
if (dto.getTtsPitch() != null) {
|
||||||
|
existingEntity.setTtsPitch(dto.getTtsPitch());
|
||||||
|
}
|
||||||
if (dto.getMemModelId() != null) {
|
if (dto.getMemModelId() != null) {
|
||||||
existingEntity.setMemModelId(dto.getMemModelId());
|
existingEntity.setMemModelId(dto.getMemModelId());
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -88,6 +88,9 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
agent.getVadModelId(),
|
agent.getVadModelId(),
|
||||||
agent.getAsrModelId(),
|
agent.getAsrModelId(),
|
||||||
null,
|
null,
|
||||||
@@ -219,6 +222,9 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
referenceAudio,
|
referenceAudio,
|
||||||
referenceText,
|
referenceText,
|
||||||
language,
|
language,
|
||||||
|
agent.getTtsVolume(),
|
||||||
|
agent.getTtsRate(),
|
||||||
|
agent.getTtsPitch(),
|
||||||
agent.getVadModelId(),
|
agent.getVadModelId(),
|
||||||
agent.getAsrModelId(),
|
agent.getAsrModelId(),
|
||||||
agent.getLlmModelId(),
|
agent.getLlmModelId(),
|
||||||
@@ -397,6 +403,9 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
String referenceAudio,
|
String referenceAudio,
|
||||||
String referenceText,
|
String referenceText,
|
||||||
String language,
|
String language,
|
||||||
|
Integer ttsVolume,
|
||||||
|
Integer ttsRate,
|
||||||
|
Integer ttsPitch,
|
||||||
String vadModelId,
|
String vadModelId,
|
||||||
String asrModelId,
|
String asrModelId,
|
||||||
String llmModelId,
|
String llmModelId,
|
||||||
@@ -437,6 +446,12 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
((Map<String, Object>) model.getConfigJson()).put("ref_text", referenceText);
|
((Map<String, Object>) model.getConfigJson()).put("ref_text", referenceText);
|
||||||
if (language != null)
|
if (language != null)
|
||||||
((Map<String, Object>) model.getConfigJson()).put("language", language);
|
((Map<String, Object>) model.getConfigJson()).put("language", language);
|
||||||
|
if (ttsVolume != null)
|
||||||
|
((Map<String, Object>) model.getConfigJson()).put("ttsVolume", ttsVolume);
|
||||||
|
if (ttsRate != null)
|
||||||
|
((Map<String, Object>) model.getConfigJson()).put("ttsRate", ttsRate);
|
||||||
|
if (ttsPitch != null)
|
||||||
|
((Map<String, Object>) model.getConfigJson()).put("ttsPitch", ttsPitch);
|
||||||
|
|
||||||
// 火山引擎声音克隆需要替换resource_id
|
// 火山引擎声音克隆需要替换resource_id
|
||||||
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
||||||
|
|||||||
@@ -13,8 +13,36 @@ SET languages = CASE
|
|||||||
ELSE languages
|
ELSE languages
|
||||||
END;
|
END;
|
||||||
|
|
||||||
-- 添加音色语言字段到 ai_agent 表
|
-- 添加音色语言、音量、语速、音调字段到 ai_agent 表
|
||||||
ALTER TABLE `ai_agent` ADD COLUMN `tts_language` VARCHAR(50) NULL COMMENT '音色语言' AFTER `tts_voice_id`;
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent' AND COLUMN_NAME = 'tts_language');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent` ADD COLUMN `tts_language` VARCHAR(50) NULL COMMENT ''音色语言'' AFTER `tts_voice_id`', 'SELECT ''Column tts_language already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
-- 添加音色语言字段到 ai_agent_template 表
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent' AND COLUMN_NAME = 'tts_volume');
|
||||||
ALTER TABLE `ai_agent_template` ADD COLUMN `tts_language` VARCHAR(50) NULL COMMENT '音色语言' AFTER `tts_voice_id`;
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent` ADD COLUMN `tts_volume` INT NULL COMMENT ''TTS音量'' AFTER `tts_language`', 'SELECT ''Column tts_volume already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent' AND COLUMN_NAME = 'tts_rate');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent` ADD COLUMN `tts_rate` INT NULL COMMENT ''TTS语速'' AFTER `tts_volume`', 'SELECT ''Column tts_rate already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent' AND COLUMN_NAME = 'tts_pitch');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent` ADD COLUMN `tts_pitch` INT NULL COMMENT ''TTS音调'' AFTER `tts_rate`', 'SELECT ''Column tts_pitch already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
-- 添加音色语言、音量、语速、音调字段到 ai_agent_template 表
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent_template' AND COLUMN_NAME = 'tts_language');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent_template` ADD COLUMN `tts_language` VARCHAR(50) NULL COMMENT ''音色语言'' AFTER `tts_voice_id`', 'SELECT ''Column tts_language already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent_template' AND COLUMN_NAME = 'tts_volume');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent_template` ADD COLUMN `tts_volume` INT NULL COMMENT ''TTS音量'' AFTER `tts_language`', 'SELECT ''Column tts_volume already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent_template' AND COLUMN_NAME = 'tts_rate');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent_template` ADD COLUMN `tts_rate` INT NULL COMMENT ''TTS语速'' AFTER `tts_volume`', 'SELECT ''Column tts_rate already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ai_agent_template' AND COLUMN_NAME = 'tts_pitch');
|
||||||
|
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `ai_agent_template` ADD COLUMN `tts_pitch` INT NULL COMMENT ''TTS音调'' AFTER `tts_rate`', 'SELECT ''Column tts_pitch already exists'' AS msg');
|
||||||
|
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||||
@@ -17,6 +17,9 @@
|
|||||||
<result column="ttsModelId" property="ttsModelId"/>
|
<result column="ttsModelId" property="ttsModelId"/>
|
||||||
<result column="ttsVoiceId" property="ttsVoiceId"/>
|
<result column="ttsVoiceId" property="ttsVoiceId"/>
|
||||||
<result column="ttsLanguage" property="ttsLanguage"/>
|
<result column="ttsLanguage" property="ttsLanguage"/>
|
||||||
|
<result column="ttsVolume" property="ttsVolume"/>
|
||||||
|
<result column="ttsRate" property="ttsRate"/>
|
||||||
|
<result column="ttsPitch" property="ttsPitch"/>
|
||||||
<result column="memModelId" property="memModelId"/>
|
<result column="memModelId" property="memModelId"/>
|
||||||
<result column="intentModelId" property="intentModelId"/>
|
<result column="intentModelId" property="intentModelId"/>
|
||||||
|
|
||||||
@@ -47,6 +50,9 @@
|
|||||||
a.tts_model_id AS ttsModelId,
|
a.tts_model_id AS ttsModelId,
|
||||||
a.tts_voice_id AS ttsVoiceId,
|
a.tts_voice_id AS ttsVoiceId,
|
||||||
a.tts_language AS ttsLanguage,
|
a.tts_language AS ttsLanguage,
|
||||||
|
a.tts_volume AS ttsVolume,
|
||||||
|
a.tts_rate AS ttsRate,
|
||||||
|
a.tts_pitch AS ttsPitch,
|
||||||
a.mem_model_id AS memModelId,
|
a.mem_model_id AS memModelId,
|
||||||
a.intent_model_id AS intentModelId,
|
a.intent_model_id AS intentModelId,
|
||||||
COALESCE(
|
COALESCE(
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
<template>
|
||||||
|
<el-drawer
|
||||||
|
:visible.sync="drawerVisible"
|
||||||
|
:before-close="handleClose"
|
||||||
|
direction="rtl"
|
||||||
|
size="400px"
|
||||||
|
:modal="true"
|
||||||
|
:show-close="false"
|
||||||
|
custom-class="tts-advanced-drawer"
|
||||||
|
>
|
||||||
|
<div class="drawer-header" slot="title">
|
||||||
|
<span class="drawer-title">{{ $t('roleConfig.advancedSettings') }}</span>
|
||||||
|
<button class="drawer-close-btn" @click="handleClose">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="drawer-content">
|
||||||
|
<el-form label-position="top">
|
||||||
|
<!-- 音量 -->
|
||||||
|
<el-form-item :label="$t('roleConfig.ttsVolume')">
|
||||||
|
<div class="slider-container">
|
||||||
|
<el-slider
|
||||||
|
v-model="localSettings.volume"
|
||||||
|
:min="-100"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:format-tooltip="formatTooltip"
|
||||||
|
class="tts-slider"
|
||||||
|
/>
|
||||||
|
<span class="slider-hint">{{ $t('roleConfig.volumeHint') }}</span>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 语速 -->
|
||||||
|
<el-form-item :label="$t('roleConfig.ttsRate')">
|
||||||
|
<div class="slider-container">
|
||||||
|
<el-slider
|
||||||
|
v-model="localSettings.speed"
|
||||||
|
:min="-100"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:format-tooltip="formatTooltip"
|
||||||
|
class="tts-slider"
|
||||||
|
/>
|
||||||
|
<span class="slider-hint">{{ $t('roleConfig.speedHint') }}</span>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 音调 -->
|
||||||
|
<el-form-item :label="$t('roleConfig.ttsPitch')">
|
||||||
|
<div class="slider-container">
|
||||||
|
<el-slider
|
||||||
|
v-model="localSettings.pitch"
|
||||||
|
:min="-100"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:format-tooltip="formatTooltip"
|
||||||
|
class="tts-slider"
|
||||||
|
/>
|
||||||
|
<span class="slider-hint">{{ $t('roleConfig.pitchHint') }}</span>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="drawer-footer">
|
||||||
|
<el-button @click="handleCancel">{{ $t('button.cancel') }}</el-button>
|
||||||
|
<el-button type="primary" @click="handleSave">{{ $t('button.save') }}</el-button>
|
||||||
|
</div>
|
||||||
|
</el-drawer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'TtsAdvancedSettings',
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
volume: 0,
|
||||||
|
speed: 0,
|
||||||
|
pitch: 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
localSettings: {
|
||||||
|
volume: 0,
|
||||||
|
speed: 0,
|
||||||
|
pitch: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
drawerVisible: {
|
||||||
|
get() {
|
||||||
|
return this.visible;
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$emit('update:visible', val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
// 当抽屉打开时,复制当前设置到本地
|
||||||
|
this.localSettings = { ...this.settings };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleClose() {
|
||||||
|
this.$emit('update:visible', false);
|
||||||
|
},
|
||||||
|
handleCancel() {
|
||||||
|
// 取消时不保存,直接关闭
|
||||||
|
this.handleClose();
|
||||||
|
},
|
||||||
|
handleSave() {
|
||||||
|
// 保存设置并关闭
|
||||||
|
this.$emit('save', { ...this.localSettings });
|
||||||
|
this.handleClose();
|
||||||
|
},
|
||||||
|
formatTooltip(val) {
|
||||||
|
return `${val}%`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.drawer-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 20px 24px;
|
||||||
|
border-bottom: 1px solid #e8f0ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-title {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #3d4566;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-close-btn {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid #cfcfcf;
|
||||||
|
background: none;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: lighter;
|
||||||
|
color: #cfcfcf;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0;
|
||||||
|
outline: none;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-close-btn:hover {
|
||||||
|
color: #409eff;
|
||||||
|
border-color: #409eff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-content {
|
||||||
|
padding: 24px;
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-container {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-hint {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
margin-top: 8px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider ::v-deep .el-slider__input {
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider ::v-deep .el-input__inner {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-footer {
|
||||||
|
padding: 16px 24px;
|
||||||
|
border-top: 1px solid #e8f0ff;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drawer-footer .el-button {
|
||||||
|
min-width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep .el-form-item__label {
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: #3d4566 !important;
|
||||||
|
font-weight: 500;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep .el-form-item {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.tts-advanced-drawer .el-drawer__header {
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-advanced-drawer .el-drawer__body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -764,6 +764,14 @@ export default {
|
|||||||
'roleConfig.intent': 'Intent',
|
'roleConfig.intent': 'Intent',
|
||||||
'roleConfig.language': 'Sprache auswählen',
|
'roleConfig.language': 'Sprache auswählen',
|
||||||
'roleConfig.voiceType': 'Stimmtyp',
|
'roleConfig.voiceType': 'Stimmtyp',
|
||||||
|
'roleConfig.ttsVolume': 'Lautstärke',
|
||||||
|
'roleConfig.ttsRate': 'Geschwindigkeit',
|
||||||
|
'roleConfig.ttsPitch': 'Tonhöhe',
|
||||||
|
'roleConfig.ttsAdvanced': 'TTS-Parameter',
|
||||||
|
'roleConfig.advancedSettings': 'Erweiterte Einstellungen',
|
||||||
|
'roleConfig.volumeHint': '-100=Min, 0=Standard, 100=Max',
|
||||||
|
'roleConfig.speedHint': '-100=Langsamste, 0=Standard, 100=Schnellste',
|
||||||
|
'roleConfig.pitchHint': '-100=Niedrigste, 0=Standard, 100=Höchste',
|
||||||
'roleConfig.pleaseEnterContent': 'Bitte Inhalt eingeben',
|
'roleConfig.pleaseEnterContent': 'Bitte Inhalt eingeben',
|
||||||
'roleConfig.pleaseEnterLangCode': 'Bitte Sprachcode eingeben, z.B.: en_US',
|
'roleConfig.pleaseEnterLangCode': 'Bitte Sprachcode eingeben, z.B.: en_US',
|
||||||
'roleConfig.pleaseEnterLangName': 'Bitte Interaktionssprache eingeben, z.B.: Englisch',
|
'roleConfig.pleaseEnterLangName': 'Bitte Interaktionssprache eingeben, z.B.: Englisch',
|
||||||
|
|||||||
@@ -764,6 +764,14 @@ export default {
|
|||||||
'roleConfig.intent': 'Intent Recognition',
|
'roleConfig.intent': 'Intent Recognition',
|
||||||
'roleConfig.language': 'Select Language',
|
'roleConfig.language': 'Select Language',
|
||||||
'roleConfig.voiceType': 'Voice Type',
|
'roleConfig.voiceType': 'Voice Type',
|
||||||
|
'roleConfig.ttsVolume': 'Volume',
|
||||||
|
'roleConfig.ttsRate': 'Speed',
|
||||||
|
'roleConfig.ttsPitch': 'Pitch',
|
||||||
|
'roleConfig.ttsAdvanced': 'TTS Parameters',
|
||||||
|
'roleConfig.advancedSettings': 'Advanced Settings',
|
||||||
|
'roleConfig.volumeHint': '-100=Min, 0=Standard, 100=Max',
|
||||||
|
'roleConfig.speedHint': '-100=Slowest, 0=Standard, 100=Fastest',
|
||||||
|
'roleConfig.pitchHint': '-100=Lowest, 0=Standard, 100=Highest',
|
||||||
'roleConfig.pleaseEnterContent': 'Please enter content',
|
'roleConfig.pleaseEnterContent': 'Please enter content',
|
||||||
'roleConfig.pleaseEnterLangCode': 'Please enter language code, e.g.: en_US',
|
'roleConfig.pleaseEnterLangCode': 'Please enter language code, e.g.: en_US',
|
||||||
'roleConfig.pleaseEnterLangName': 'Please enter interaction language, e.g.: English',
|
'roleConfig.pleaseEnterLangName': 'Please enter interaction language, e.g.: English',
|
||||||
|
|||||||
@@ -764,6 +764,14 @@ export default {
|
|||||||
'roleConfig.intent': 'Nhận dạng ý định',
|
'roleConfig.intent': 'Nhận dạng ý định',
|
||||||
'roleConfig.language': 'Chọn ngôn ngữ',
|
'roleConfig.language': 'Chọn ngôn ngữ',
|
||||||
'roleConfig.voiceType': 'Loại giọng nói',
|
'roleConfig.voiceType': 'Loại giọng nói',
|
||||||
|
'roleConfig.ttsVolume': 'Âm lượng',
|
||||||
|
'roleConfig.ttsRate': 'Tốc độ',
|
||||||
|
'roleConfig.ttsPitch': 'Cao độ',
|
||||||
|
'roleConfig.ttsAdvanced': 'Tham số TTS',
|
||||||
|
'roleConfig.advancedSettings': 'Cài đặt nâng cao',
|
||||||
|
'roleConfig.volumeHint': '-100=Tối thiểu, 0=Tiêu chuẩn, 100=Tối đa',
|
||||||
|
'roleConfig.speedHint': '-100=Chậm nhất, 0=Tiêu chuẩn, 100=Nhanh nhất',
|
||||||
|
'roleConfig.pitchHint': '-100=Thấp nhất, 0=Tiêu chuẩn, 100=Cao nhất',
|
||||||
'roleConfig.pleaseEnterContent': 'Vui lòng nhập nội dung',
|
'roleConfig.pleaseEnterContent': 'Vui lòng nhập nội dung',
|
||||||
'roleConfig.pleaseEnterLangCode': 'Vui lòng nhập mã ngôn ngữ, ví dụ: en_US',
|
'roleConfig.pleaseEnterLangCode': 'Vui lòng nhập mã ngôn ngữ, ví dụ: en_US',
|
||||||
'roleConfig.pleaseEnterLangName': 'Vui lòng nhập ngôn ngữ tương tác, ví dụ: Tiếng Anh',
|
'roleConfig.pleaseEnterLangName': 'Vui lòng nhập ngôn ngữ tương tác, ví dụ: Tiếng Anh',
|
||||||
|
|||||||
@@ -764,6 +764,14 @@ export default {
|
|||||||
'roleConfig.tts': '语音合成(TTS)',
|
'roleConfig.tts': '语音合成(TTS)',
|
||||||
'roleConfig.language': '选择语言',
|
'roleConfig.language': '选择语言',
|
||||||
'roleConfig.voiceType': '声音音色(Voice)',
|
'roleConfig.voiceType': '声音音色(Voice)',
|
||||||
|
'roleConfig.ttsVolume': '音量',
|
||||||
|
'roleConfig.ttsRate': '语速',
|
||||||
|
'roleConfig.ttsPitch': '音调',
|
||||||
|
'roleConfig.ttsAdvanced': 'TTS参数',
|
||||||
|
'roleConfig.advancedSettings': '高级设置',
|
||||||
|
'roleConfig.volumeHint': '-100=最小, 0=标准, 100=最大',
|
||||||
|
'roleConfig.speedHint': '-100=最慢, 0=标准, 100=最快',
|
||||||
|
'roleConfig.pitchHint': '-100=最低, 0=标准, 100=最高',
|
||||||
'roleConfig.pleaseEnterContent': '请输入内容',
|
'roleConfig.pleaseEnterContent': '请输入内容',
|
||||||
'roleConfig.pleaseEnterLangCode': '请输入语言编码,如:zh_CN',
|
'roleConfig.pleaseEnterLangCode': '请输入语言编码,如:zh_CN',
|
||||||
'roleConfig.pleaseEnterLangName': '请输入交互语种,如:中文',
|
'roleConfig.pleaseEnterLangName': '请输入交互语种,如:中文',
|
||||||
|
|||||||
@@ -764,6 +764,14 @@ export default {
|
|||||||
'roleConfig.intent': '意圖識別(Intent)',
|
'roleConfig.intent': '意圖識別(Intent)',
|
||||||
'roleConfig.language': '選擇語言',
|
'roleConfig.language': '選擇語言',
|
||||||
'roleConfig.voiceType': '聲音音色(Voice)',
|
'roleConfig.voiceType': '聲音音色(Voice)',
|
||||||
|
'roleConfig.ttsVolume': '音量',
|
||||||
|
'roleConfig.ttsRate': '語速',
|
||||||
|
'roleConfig.ttsPitch': '音調',
|
||||||
|
'roleConfig.ttsAdvanced': 'TTS參數',
|
||||||
|
'roleConfig.advancedSettings': '高級設置',
|
||||||
|
'roleConfig.volumeHint': '-100=最小, 0=標準, 100=最大',
|
||||||
|
'roleConfig.speedHint': '-100=最慢, 0=標準, 100=最快',
|
||||||
|
'roleConfig.pitchHint': '-100=最低, 0=標準, 100=最高',
|
||||||
'roleConfig.pleaseEnterContent': '請輸入內容',
|
'roleConfig.pleaseEnterContent': '請輸入內容',
|
||||||
'roleConfig.pleaseEnterLangCode': '請輸入語言編碼,如:zh_TW',
|
'roleConfig.pleaseEnterLangCode': '請輸入語言編碼,如:zh_TW',
|
||||||
'roleConfig.pleaseEnterLangName': '請輸入交互語種,如:繁體中文',
|
'roleConfig.pleaseEnterLangName': '請輸入交互語種,如:繁體中文',
|
||||||
|
|||||||
@@ -234,12 +234,12 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div class="model-row">
|
<div class="model-row">
|
||||||
<!-- 语言筛选器 -->
|
<!-- 语言筛选器 -->
|
||||||
<el-form-item :label="$t('roleConfig.language')" class="model-item">
|
<el-form-item :label="$t('roleConfig.language')" class="model-item language-select-item">
|
||||||
<div class="model-select-wrapper">
|
<div class="model-select-wrapper">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="selectedLanguage"
|
v-model="selectedLanguage"
|
||||||
:placeholder="$t('roleConfig.selectLanguage')"
|
:placeholder="$t('roleConfig.selectLanguage')"
|
||||||
class="form-select"
|
class="form-select language-select"
|
||||||
@change="filterVoicesByLanguage"
|
@change="filterVoicesByLanguage"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
@@ -251,7 +251,7 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<!-- 音色选择器 -->
|
<!-- 音色选择器 -->
|
||||||
<el-form-item :label="$t('roleConfig.voiceType')" class="model-item">
|
<el-form-item :label="$t('roleConfig.voiceType')" class="model-item">
|
||||||
<div class="model-select-wrapper">
|
<div class="model-select-wrapper">
|
||||||
@@ -294,6 +294,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
<el-button
|
||||||
|
class="edit-function-btn"
|
||||||
|
style="margin-left: 10px;"
|
||||||
|
@click="openTtsAdvancedSettings"
|
||||||
|
>
|
||||||
|
{{ $t('roleConfig.advancedSettings') }}
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
@@ -318,6 +325,11 @@
|
|||||||
:providers="currentContextProviders"
|
:providers="currentContextProviders"
|
||||||
@confirm="handleUpdateContext"
|
@confirm="handleUpdateContext"
|
||||||
/>
|
/>
|
||||||
|
<tts-advanced-settings
|
||||||
|
:visible.sync="showTtsAdvancedDialog"
|
||||||
|
:settings="ttsSettings"
|
||||||
|
@save="handleTtsSettingsSave"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -327,20 +339,30 @@ import { getServiceUrl } from "@/apis/api";
|
|||||||
import RequestService from "@/apis/httpRequest";
|
import RequestService from "@/apis/httpRequest";
|
||||||
import FunctionDialog from "@/components/FunctionDialog.vue";
|
import FunctionDialog from "@/components/FunctionDialog.vue";
|
||||||
import ContextProviderDialog from "@/components/ContextProviderDialog.vue";
|
import ContextProviderDialog from "@/components/ContextProviderDialog.vue";
|
||||||
|
import TtsAdvancedSettings from "@/components/TtsAdvancedSettings.vue";
|
||||||
import HeaderBar from "@/components/HeaderBar.vue";
|
import HeaderBar from "@/components/HeaderBar.vue";
|
||||||
import i18n from "@/i18n";
|
import i18n from "@/i18n";
|
||||||
import featureManager from "@/utils/featureManager";
|
import featureManager from "@/utils/featureManager";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "RoleConfigPage",
|
name: "RoleConfigPage",
|
||||||
components: { HeaderBar, FunctionDialog, ContextProviderDialog },
|
components: { HeaderBar, FunctionDialog, ContextProviderDialog, TtsAdvancedSettings },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showContextProviderDialog: false,
|
showContextProviderDialog: false,
|
||||||
|
showTtsAdvancedDialog: false,
|
||||||
|
ttsSettings: {
|
||||||
|
volume: 0,
|
||||||
|
speed: 0,
|
||||||
|
pitch: 0
|
||||||
|
},
|
||||||
form: {
|
form: {
|
||||||
agentCode: "",
|
agentCode: "",
|
||||||
agentName: "",
|
agentName: "",
|
||||||
ttsVoiceId: "",
|
ttsVoiceId: "",
|
||||||
|
ttsVolume: null,
|
||||||
|
ttsRate: null,
|
||||||
|
ttsPitch: null,
|
||||||
chatHistoryConf: 0,
|
chatHistoryConf: 0,
|
||||||
systemPrompt: "",
|
systemPrompt: "",
|
||||||
summaryMemory: "",
|
summaryMemory: "",
|
||||||
@@ -422,6 +444,17 @@ export default {
|
|||||||
}),
|
}),
|
||||||
contextProviders: this.currentContextProviders,
|
contextProviders: this.currentContextProviders,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 只在用户设置了TTS参数时才传递(不为null/undefined)
|
||||||
|
if (this.form.ttsVolume !== null && this.form.ttsVolume !== undefined) {
|
||||||
|
configData.ttsVolume = this.form.ttsVolume;
|
||||||
|
}
|
||||||
|
if (this.form.ttsRate !== null && this.form.ttsRate !== undefined) {
|
||||||
|
configData.ttsRate = this.form.ttsRate;
|
||||||
|
}
|
||||||
|
if (this.form.ttsPitch !== null && this.form.ttsPitch !== undefined) {
|
||||||
|
configData.ttsPitch = this.form.ttsPitch;
|
||||||
|
}
|
||||||
Api.agent.updateAgentConfig(this.$route.query.agentId, configData, ({ data }) => {
|
Api.agent.updateAgentConfig(this.$route.query.agentId, configData, ({ data }) => {
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
this.$message.success({
|
this.$message.success({
|
||||||
@@ -535,6 +568,14 @@ export default {
|
|||||||
intentModelId: data.data.intentModelId,
|
intentModelId: data.data.intentModelId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 同步TTS设置到ttsSettings
|
||||||
|
this.ttsSettings = {
|
||||||
|
volume: this.form.ttsVolume || 0,
|
||||||
|
speed: this.form.ttsRate || 0,
|
||||||
|
pitch: this.form.ttsPitch || 0
|
||||||
|
};
|
||||||
|
|
||||||
// 后端只给了最小映射:[{ id, agentId, pluginId }, ...]
|
// 后端只给了最小映射:[{ id, agentId, pluginId }, ...]
|
||||||
const savedMappings = data.data.functions || [];
|
const savedMappings = data.data.functions || [];
|
||||||
|
|
||||||
@@ -696,6 +737,13 @@ export default {
|
|||||||
if (!currentVoiceSupportsLanguage) {
|
if (!currentVoiceSupportsLanguage) {
|
||||||
this.form.ttsVoiceId = filteredVoices.length > 0 ? filteredVoices[0].id : '';
|
this.form.ttsVoiceId = filteredVoices.length > 0 ? filteredVoices[0].id : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 同步到ttsSettings(如果值为null,使用0作为显示默认值,但不修改form中的值)
|
||||||
|
this.ttsSettings = {
|
||||||
|
volume: this.form.ttsVolume !== null && this.form.ttsVolume !== undefined ? this.form.ttsVolume : 0,
|
||||||
|
speed: this.form.ttsRate !== null && this.form.ttsRate !== undefined ? this.form.ttsRate : 0,
|
||||||
|
pitch: this.form.ttsPitch !== null && this.form.ttsPitch !== undefined ? this.form.ttsPitch : 0
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getFunctionDisplayChar(name) {
|
getFunctionDisplayChar(name) {
|
||||||
@@ -763,6 +811,16 @@ export default {
|
|||||||
openContextProviderDialog() {
|
openContextProviderDialog() {
|
||||||
this.showContextProviderDialog = true;
|
this.showContextProviderDialog = true;
|
||||||
},
|
},
|
||||||
|
openTtsAdvancedSettings() {
|
||||||
|
this.showTtsAdvancedDialog = true;
|
||||||
|
},
|
||||||
|
handleTtsSettingsSave(settings) {
|
||||||
|
// 保存TTS设置
|
||||||
|
this.ttsSettings = { ...settings };
|
||||||
|
this.form.ttsVolume = settings.volume;
|
||||||
|
this.form.ttsRate = settings.speed;
|
||||||
|
this.form.ttsPitch = settings.pitch;
|
||||||
|
},
|
||||||
handleUpdateContext(providers) {
|
handleUpdateContext(providers) {
|
||||||
this.currentContextProviders = providers;
|
this.currentContextProviders = providers;
|
||||||
},
|
},
|
||||||
@@ -1316,6 +1374,15 @@ export default {
|
|||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-row .language-select-item {
|
||||||
|
flex: 0 0 35%;
|
||||||
|
max-width: 35%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row .language-select-item .language-select {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.model-row .el-form-item__label {
|
.model-row .el-form-item__label {
|
||||||
font-size: 12px !important;
|
font-size: 12px !important;
|
||||||
color: #3d4566 !important;
|
color: #3d4566 !important;
|
||||||
@@ -1491,4 +1558,30 @@ export default {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.slider-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
padding-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-hint {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
margin-top: 4px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider ::v-deep .el-slider__input {
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tts-slider ::v-deep .el-input__inner {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import queue
|
|||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from asyncio import Task
|
from asyncio import Task
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from core.utils import opus_encoder_utils
|
|
||||||
from core.utils.tts import MarkdownCleaner
|
from core.utils.tts import MarkdownCleaner
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
||||||
@@ -18,6 +18,12 @@ logger = setup_logging()
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume", 0, 100, 50, int),
|
||||||
|
("ttsRate", "rate", 0.5, 2.0, 1.0, lambda v: round(v, 1)),
|
||||||
|
("ttsPitch", "pitch", 0.5, 2.0, 1.0, lambda v: round(v, 1)),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
|
|
||||||
@@ -51,6 +57,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
pitch = config.get("pitch", "1.0")
|
pitch = config.get("pitch", "1.0")
|
||||||
self.pitch = float(pitch) if pitch else 1.0
|
self.pitch = float(pitch) if pitch else 1.0
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
self.header = {
|
self.header = {
|
||||||
"Authorization": f"Bearer {self.api_key}",
|
"Authorization": f"Bearer {self.api_key}",
|
||||||
# "user-agent": "your_platform_info", // 可选
|
# "user-agent": "your_platform_info", // 可选
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
import hmac
|
import hmac
|
||||||
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
|
||||||
from core.providers.tts.base import TTSProviderBase
|
|
||||||
from config.logger import setup_logging
|
|
||||||
import time
|
|
||||||
import uuid
|
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
from datetime import datetime
|
||||||
|
from config.logger import setup_logging
|
||||||
|
from core.providers.tts.base import TTSProviderBase
|
||||||
|
from core.utils.tts import convert_percentage_to_range
|
||||||
|
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
@@ -84,6 +86,11 @@ class AccessToken:
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume", 0, 100, 50, int),
|
||||||
|
("ttsRate", "speech_rate", -500, 500, 0, int),
|
||||||
|
("ttsPitch", "pitch_rate", -500, 500, 0, int),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
@@ -110,6 +117,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
pitch_rate = config.get("pitch_rate", "0")
|
pitch_rate = config.get("pitch_rate", "0")
|
||||||
self.pitch_rate = int(pitch_rate) if pitch_rate else 0
|
self.pitch_rate = int(pitch_rate) if pitch_rate else 0
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
self.host = config.get("host", "nls-gateway-cn-shanghai.aliyuncs.com")
|
self.host = config.get("host", "nls-gateway-cn-shanghai.aliyuncs.com")
|
||||||
self.api_url = f"https://{self.host}/stream/v1/tts"
|
self.api_url = f"https://{self.host}/stream/v1/tts"
|
||||||
self.header = {"Content-Type": "application/json"}
|
self.header = {"Content-Type": "application/json"}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import random
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
import hmac
|
import hmac
|
||||||
@@ -8,16 +8,16 @@ import time
|
|||||||
import queue
|
import queue
|
||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
from asyncio import Task
|
|
||||||
import websockets
|
import websockets
|
||||||
import os
|
|
||||||
from datetime import datetime
|
from asyncio import Task
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
from datetime import datetime
|
||||||
|
from config.logger import setup_logging
|
||||||
|
from core.utils.tts import MarkdownCleaner
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
||||||
from core.utils.tts import MarkdownCleaner
|
|
||||||
from core.utils import opus_encoder_utils, textUtils
|
|
||||||
from config.logger import setup_logging
|
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
@@ -86,6 +86,12 @@ class AccessToken:
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume", 0, 100, 50, int),
|
||||||
|
("ttsRate", "speech_rate", -500, 500, 0, int),
|
||||||
|
("ttsPitch", "pitch_rate", -500, 500, 0, int),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
|
|
||||||
@@ -115,6 +121,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
pitch_rate = config.get("pitch_rate", "0")
|
pitch_rate = config.get("pitch_rate", "0")
|
||||||
self.pitch_rate = int(pitch_rate) if pitch_rate else 0
|
self.pitch_rate = int(pitch_rate) if pitch_rate else 0
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
# WebSocket配置
|
# WebSocket配置
|
||||||
self.host = config.get("host", "nls-gateway-cn-beijing.aliyuncs.com")
|
self.host = config.get("host", "nls-gateway-cn-beijing.aliyuncs.com")
|
||||||
# 如果配置的是内网地址(包含-internal.aliyuncs.com),则使用ws协议,默认是wss协议
|
# 如果配置的是内网地址(包含-internal.aliyuncs.com),则使用ws协议,默认是wss协议
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from typing import Callable, Any
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from core.utils import opus_encoder_utils
|
from core.utils import opus_encoder_utils
|
||||||
from core.utils.tts import MarkdownCleaner
|
from core.utils.tts import MarkdownCleaner, convert_percentage_to_range
|
||||||
from core.utils.output_counter import add_device_output
|
from core.utils.output_counter import add_device_output
|
||||||
from core.handle.reportHandle import enqueue_tts_report
|
from core.handle.reportHandle import enqueue_tts_report
|
||||||
from core.handle.sendAudioHandle import sendAudioMessage
|
from core.handle.sendAudioHandle import sendAudioMessage
|
||||||
@@ -463,3 +463,10 @@ class TTSProviderBase(ABC):
|
|||||||
self.processed_chars += len(full_text)
|
self.processed_chars += len(full_text)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _apply_percentage_params(self, config):
|
||||||
|
"""根据子类定义的 TTS_PARAM_CONFIG 批量应用百分比参数"""
|
||||||
|
for config_key, attr_name, min_val, max_val, base_val, transform in self.TTS_PARAM_CONFIG:
|
||||||
|
if config_key in config:
|
||||||
|
val = convert_percentage_to_range(config[config_key], min_val, max_val, base_val)
|
||||||
|
setattr(self, attr_name, transform(val) if transform else val)
|
||||||
|
|||||||
@@ -2,15 +2,24 @@ import uuid
|
|||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from config.logger import setup_logging
|
||||||
from core.utils.util import check_model_key
|
from core.utils.util import check_model_key
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
from config.logger import setup_logging
|
from core.utils.tts import convert_percentage_to_range
|
||||||
|
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume_ratio", 0.1, 3, 1.0, lambda v: round(float(v), 1)),
|
||||||
|
("ttsRate", "speed_ratio", 0.2, 3, 1.0, lambda v: round(float(v), 1)),
|
||||||
|
("ttsPitch", "pitch_ratio", 0.1, 3, 1.0, lambda v: round(float(v), 1)),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
if config.get("appid"):
|
if config.get("appid"):
|
||||||
@@ -34,6 +43,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.volume_ratio = float(volume_ratio) if volume_ratio else 1.0
|
self.volume_ratio = float(volume_ratio) if volume_ratio else 1.0
|
||||||
self.pitch_ratio = float(pitch_ratio) if pitch_ratio else 1.0
|
self.pitch_ratio = float(pitch_ratio) if pitch_ratio else 1.0
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
self.api_url = config.get("api_url")
|
self.api_url = config.get("api_url")
|
||||||
self.authorization = config.get("authorization")
|
self.authorization = config.get("authorization")
|
||||||
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ import traceback
|
|||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from typing import Callable, Any
|
from typing import Callable, Any
|
||||||
from core.utils.tts import MarkdownCleaner
|
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from core.utils import opus_encoder_utils
|
|
||||||
from core.utils.util import check_model_key
|
from core.utils.util import check_model_key
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
|
from core.utils.tts import MarkdownCleaner, convert_percentage_to_range
|
||||||
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
from core.providers.tts.dto.dto import SentenceType, ContentType, InterfaceType
|
||||||
|
|
||||||
|
|
||||||
@@ -178,6 +177,22 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.additions = {**default_additions, **config.get("additions", {})}
|
self.additions = {**default_additions, **config.get("additions", {})}
|
||||||
self.mix_speaker = {**default_mix_speaker, **config.get("mix_speaker", {})}
|
self.mix_speaker = {**default_mix_speaker, **config.get("mix_speaker", {})}
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
if "ttsVolume" in config:
|
||||||
|
self.audio_params["loudness_rate"] = int(convert_percentage_to_range(
|
||||||
|
config["ttsVolume"], min_val=-50, max_val=100, base_val=0
|
||||||
|
))
|
||||||
|
|
||||||
|
if "ttsRate" in config:
|
||||||
|
self.audio_params["speech_rate"] = int(convert_percentage_to_range(
|
||||||
|
config["ttsRate"], min_val=-50, max_val=100, base_val=0
|
||||||
|
))
|
||||||
|
|
||||||
|
if "ttsPitch" in config:
|
||||||
|
self.additions["post_process"]["pitch"] = int(convert_percentage_to_range(
|
||||||
|
config["ttsPitch"], min_val=-12, max_val=12, base_val=0
|
||||||
|
))
|
||||||
|
|
||||||
self.ws_url = config.get("ws_url")
|
self.ws_url = config.get("ws_url")
|
||||||
self.authorization = config.get("authorization")
|
self.authorization = config.get("authorization")
|
||||||
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import asyncio
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
import requests
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from core.utils import textUtils
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from core.utils.tts import MarkdownCleaner
|
|
||||||
from core.utils.util import parse_string_to_list
|
from core.utils.util import parse_string_to_list
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
from core.utils import opus_encoder_utils, textUtils
|
|
||||||
from core.providers.tts.dto.dto import SentenceType, ContentType
|
from core.providers.tts.dto.dto import SentenceType, ContentType
|
||||||
|
from core.utils.tts import MarkdownCleaner, convert_percentage_to_range
|
||||||
|
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
@@ -56,6 +58,22 @@ class TTSProvider(TTSProviderBase):
|
|||||||
if self.voice:
|
if self.voice:
|
||||||
self.voice_setting["voice_id"] = self.voice
|
self.voice_setting["voice_id"] = self.voice
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
if "ttsVolume" in config:
|
||||||
|
self.voice_setting["vol"] = round(convert_percentage_to_range(
|
||||||
|
config["ttsVolume"], min_val=0.1, max_val=10, base_val=1.0
|
||||||
|
), 1)
|
||||||
|
|
||||||
|
if "ttsRate" in config:
|
||||||
|
self.voice_setting["speed"] = round(convert_percentage_to_range(
|
||||||
|
config["ttsRate"], min_val=0.5, max_val=2, base_val=1.0
|
||||||
|
), 1)
|
||||||
|
|
||||||
|
if "ttsPitch" in config:
|
||||||
|
self.voice_setting["pitch"] = int(convert_percentage_to_range(
|
||||||
|
config["ttsPitch"], min_val=-12, max_val=12, base_val=0
|
||||||
|
))
|
||||||
|
|
||||||
self.host = "api.minimaxi.com" # 备用地址:api-bj.minimaxi.com
|
self.host = "api.minimaxi.com" # 备用地址:api-bj.minimaxi.com
|
||||||
self.api_url = f"https://{self.host}/v1/t2a_v2?GroupId={self.group_id}"
|
self.api_url = f"https://{self.host}/v1/t2a_v2?GroupId={self.group_id}"
|
||||||
self.header = {
|
self.header = {
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ logger = setup_logging()
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume", 0, 3, 1.0, lambda v: round(float(v), 1)),
|
||||||
|
("ttsRate", "speed", 0, 3, 1.0, lambda v: round(float(v), 1)),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
self.url = config.get("url", "ws://192.168.1.10:8092/paddlespeech/tts/streaming")
|
self.url = config.get("url", "ws://192.168.1.10:8092/paddlespeech/tts/streaming")
|
||||||
@@ -33,6 +38,10 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.volume = float(volume) if volume else 1.0
|
self.volume = float(volume) if volume else 1.0
|
||||||
|
|
||||||
self.delete_audio_file = config.get("delete_audio", True)
|
self.delete_audio_file = config.get("delete_audio", True)
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
if not self.delete_audio_file:
|
if not self.delete_audio_file:
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
save_path = config.get("save_path")
|
save_path = config.get("save_path")
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ from core.providers.tts.base import TTSProviderBase
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "gain", -10, 10, 0, int),
|
||||||
|
("ttsRate", "speed", 0.25, 4, 1, lambda v: round(float(v), 1)),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
self.model = config.get("model")
|
self.model = config.get("model")
|
||||||
@@ -16,6 +21,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.speed = float(config.get("speed", 1.0))
|
self.speed = float(config.get("speed", 1.0))
|
||||||
self.gain = config.get("gain")
|
self.gain = config.get("gain")
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
self.host = "api.siliconflow.cn"
|
self.host = "api.siliconflow.cn"
|
||||||
self.api_url = f"https://{self.host}/v1/audio/speech"
|
self.api_url = f"https://{self.host}/v1/audio/speech"
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ logger = setup_logging()
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume_change_dB", -10, 10, 0, int),
|
||||||
|
("ttsRate", "speed_factor", 0.5, 2, 0, lambda v: round(float(v), 1)),
|
||||||
|
("ttsPitch", "pitch_factor", -8, 8, 0, lambda v: round(float(v), 1)),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
self.url = config.get(
|
self.url = config.get(
|
||||||
@@ -34,6 +40,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.emotion = int(config.get("emotion", 1))
|
self.emotion = int(config.get("emotion", 1))
|
||||||
self.header = {"Content-Type": "application/json"}
|
self.header = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
def generate_filename(self, extension=".mp3"):
|
def generate_filename(self, extension=".mp3"):
|
||||||
return os.path.join(
|
return os.path.join(
|
||||||
self.output_file,
|
self.output_file,
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import hashlib
|
|||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from asyncio import Task
|
from asyncio import Task
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
from core.utils import opus_encoder_utils
|
|
||||||
from core.utils.tts import MarkdownCleaner
|
from core.utils.tts import MarkdownCleaner
|
||||||
from urllib.parse import urlencode, urlparse
|
from urllib.parse import urlencode, urlparse
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
@@ -59,6 +59,12 @@ class XunfeiWSAuth:
|
|||||||
|
|
||||||
|
|
||||||
class TTSProvider(TTSProviderBase):
|
class TTSProvider(TTSProviderBase):
|
||||||
|
TTS_PARAM_CONFIG = [
|
||||||
|
("ttsVolume", "volume", 0, 100, 50, int),
|
||||||
|
("ttsRate", "speed", 0, 100, 50, int),
|
||||||
|
("ttsPitch", "pitch", 0, 100, 50, int),
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
|
|
||||||
@@ -88,6 +94,9 @@ class TTSProvider(TTSProviderBase):
|
|||||||
pitch = config.get("pitch", "50")
|
pitch = config.get("pitch", "50")
|
||||||
self.pitch = int(pitch) if pitch else 50
|
self.pitch = int(pitch) if pitch else 50
|
||||||
|
|
||||||
|
# 应用百分比调整(如果存在),否则使用公有化配置
|
||||||
|
self._apply_percentage_params(config)
|
||||||
|
|
||||||
# 音频编码配置
|
# 音频编码配置
|
||||||
self.format = config.get("format", "raw")
|
self.format = config.get("format", "raw")
|
||||||
|
|
||||||
|
|||||||
@@ -141,4 +141,31 @@ class MarkdownCleaner:
|
|||||||
# 去除emoji表情
|
# 去除emoji表情
|
||||||
text = check_emoji(text)
|
text = check_emoji(text)
|
||||||
|
|
||||||
return text.strip()
|
return text.strip()
|
||||||
|
|
||||||
|
def convert_percentage_to_range(percentage, min_val, max_val, base_val=None):
|
||||||
|
"""
|
||||||
|
将百分比(-100~100)转换为指定范围的值
|
||||||
|
|
||||||
|
Args:
|
||||||
|
percentage: 百分比值 (-100 到 100)
|
||||||
|
min_val: 目标范围最小值
|
||||||
|
max_val: 目标范围最大值
|
||||||
|
base_val: 基准值(可选,默认为范围中点)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
转换后的值
|
||||||
|
"""
|
||||||
|
if base_val is None:
|
||||||
|
base_val = (min_val + max_val) / 2
|
||||||
|
|
||||||
|
# 百分比 -100 对应 min_val, 0 对应 base_val, 100 对应 max_val
|
||||||
|
if percentage < 0:
|
||||||
|
# 负百分比:从 base_val 向 min_val 线性插值
|
||||||
|
result = base_val + (base_val - min_val) * (percentage / 100)
|
||||||
|
else:
|
||||||
|
# 正百分比:从 base_val 向 max_val 线性插值
|
||||||
|
result = base_val + (max_val - base_val) * (percentage / 100)
|
||||||
|
|
||||||
|
# 确保结果在有效范围内
|
||||||
|
return max(min_val, min(max_val, result))
|
||||||
|
|||||||
Reference in New Issue
Block a user