main
mula.liu 2026-01-16 17:47:56 +08:00
parent 9fad51851d
commit 61952852d7
7 changed files with 162 additions and 31 deletions

33
.env.example 100644
View File

@ -0,0 +1,33 @@
# ==================== 数据库配置 ====================
# Docker环境使用容器名称
DB_HOST=10.100.51.51
DB_USER=root
DB_PASSWORD=Unis@123
DB_NAME=imeeting_dev
DB_PORT=3306
# ==================== Redis配置 ====================
# Docker环境使用容器名称
REDIS_HOST=10.100.51.51
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=Unis@123
# ==================== API配置 ====================
API_HOST=0.0.0.0
API_PORT=8001
# ==================== 应用配置 ====================
# 应用访问地址(用于生成外部链接、二维码等)
# 开发环境: http://localhost
# 生产环境: https://your-domain.com
BASE_URL=http://imeeting.unisspace.com
# ==================== LLM配置 ====================
# 通义千问API密钥请替换为实际密钥
QWEN_API_KEY=sk-c2bf06ea56b4491ea3d1e37fdb472b8f
# ==================== 转录轮询配置 ====================
TRANSCRIPTION_POLL_INTERVAL=10
TRANSCRIPTION_MAX_WAIT_TIME=1800

View File

@ -24,15 +24,17 @@ def get_voiceprint_template(current_user: dict = Depends(get_current_user)):
权限需要登录 权限需要登录
""" """
try: try:
# 动态从数据库获取声纹模版 # 从字典表中获取声纹配置 (dict_type='voiceprint', dict_code='voiceprint')
template_text = SystemConfigService.get_voiceprint_template( vp_config = SystemConfigService.get_dict_extension('voiceprint', dict_type='voiceprint')
default="我正在进行声纹采集,这段语音将用于身份识别和验证。\n\n声纹技术能够准确识别每个人独特的声音特征。"
) # 使用默认值如果字典中没有配置
default_template = "我正在进行声纹采集,这段语音将用于身份识别和验证。\n\n声纹技术能够准确识别每个人独特的声音特征。"
template_data = VoiceprintTemplate( template_data = VoiceprintTemplate(
template_text=template_text, template_text=vp_config.get('template_text', default_template),
duration_seconds=config_module.VOICEPRINT_CONFIG.get('duration_seconds', 12), duration_seconds=vp_config.get('duration_seconds', 12),
sample_rate=config_module.VOICEPRINT_CONFIG.get('sample_rate', 16000), sample_rate=vp_config.get('sample_rate', 16000),
channels=config_module.VOICEPRINT_CONFIG.get('channels', 1) channels=vp_config.get('channels', 1)
) )
return create_api_response(code="200", message="获取朗读模板成功", data=template_data.dict()) return create_api_response(code="200", message="获取朗读模板成功", data=template_data.dict())
except Exception as e: except Exception as e:

View File

@ -1,6 +1,11 @@
import os import os
import json import json
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv
# 加载 .env 文件
env_path = Path(__file__).parent.parent.parent / ".env"
load_dotenv(dotenv_path=env_path)
# 基础路径配置 # 基础路径配置
BASE_DIR = Path(__file__).parent.parent.parent BASE_DIR = Path(__file__).parent.parent.parent
@ -36,9 +41,9 @@ AVATAR_DIR.mkdir(exist_ok=True)
# 数据库配置 # 数据库配置
DATABASE_CONFIG = { DATABASE_CONFIG = {
'host': os.getenv('DB_HOST', '192.168.4.9'), 'host': os.getenv('DB_HOST', '127.0.0.1'),
'user': os.getenv('DB_USER', 'root'), 'user': os.getenv('DB_USER', 'root'),
'password': os.getenv('DB_PASSWORD', 'sagacity'), 'password': os.getenv('DB_PASSWORD', ''),
'database': os.getenv('DB_NAME', 'imeeting'), 'database': os.getenv('DB_NAME', 'imeeting'),
'port': int(os.getenv('DB_PORT', '3306')), 'port': int(os.getenv('DB_PORT', '3306')),
'charset': 'utf8mb4' 'charset': 'utf8mb4'
@ -51,19 +56,19 @@ API_CONFIG = {
} }
# 七牛云配置 # 七牛云配置
QINIU_ACCESS_KEY = os.getenv('QINIU_ACCESS_KEY', 'A0tp96HCtg-wZCughTgi5vc2pJnw3btClwxRE_e8') # QINIU_ACCESS_KEY = os.getenv('QINIU_ACCESS_KEY', 'A0tp96HCtg-wZCughTgi5vc2pJnw3btClwxRE_e8')
QINIU_SECRET_KEY = os.getenv('QINIU_SECRET_KEY', 'Lj-MSHpaVbmzpS86kMIjmwikvYOT9iPBjCk9hm6k') # QINIU_SECRET_KEY = os.getenv('QINIU_SECRET_KEY', 'Lj-MSHpaVbmzpS86kMIjmwikvYOT9iPBjCk9hm6k')
QINIU_BUCKET = os.getenv('QINIU_BUCKET', 'imeeting_dev') # QINIU_BUCKET = os.getenv('QINIU_BUCKET', 'imeeting_dev')
QINIU_DOMAIN = os.getenv('QINIU_DOMAIN', 't0vogyxkz.hn-bkt.clouddn.com') # QINIU_DOMAIN = os.getenv('QINIU_DOMAIN', 't0vogyxkz.hn-bkt.clouddn.com')
# 应用配置 # 应用配置
APP_CONFIG = { APP_CONFIG = {
'base_url': os.getenv('BASE_URL', 'http://dev.imeeting.unisspace.com') 'base_url': os.getenv('BASE_URL', 'http://imeeting.unisspace.com')
} }
# Redis配置 # Redis配置
REDIS_CONFIG = { REDIS_CONFIG = {
'host': os.getenv('REDIS_HOST', '192.168.4.9'), 'host': os.getenv('REDIS_HOST', '127.0.0.1'),
'port': int(os.getenv('REDIS_PORT', '6379')), 'port': int(os.getenv('REDIS_PORT', '6379')),
'db': int(os.getenv('REDIS_DB', '0')), 'db': int(os.getenv('REDIS_DB', '0')),
'password': os.getenv('REDIS_PASSWORD', ''), 'password': os.getenv('REDIS_PASSWORD', ''),
@ -79,11 +84,4 @@ TRANSCRIPTION_POLL_CONFIG = {
'max_wait_time': int(os.getenv('TRANSCRIPTION_MAX_WAIT_TIME', '1800')), # 最大等待30分钟 'max_wait_time': int(os.getenv('TRANSCRIPTION_MAX_WAIT_TIME', '1800')), # 最大等待30分钟
} }
# 默认声纹配置
VOICEPRINT_CONFIG = {
"template_text": "我正在进行声纹采集,这段语音将用于身份识别和验证。\n\n声纹技术能够准确识别每个人独特的声音特征。",
"duration_seconds": 12,
"sample_rate": 16000,
"channels": 1
}

View File

@ -21,6 +21,43 @@ class SystemConfigService:
LLM_TEMPERATURE = 'llm_temperature' LLM_TEMPERATURE = 'llm_temperature'
LLM_TOP_P = 'llm_top_p' LLM_TOP_P = 'llm_top_p'
@classmethod
def get_dict_extension(cls, dict_code: str, dict_type: str = 'system_config') -> Dict[str, Any]:
"""
获取指定码表项的扩展属性
Args:
dict_code: 码表编码
dict_type: 字典类型默认为 system_config
Returns:
扩展属性字典
"""
try:
with get_db_connection() as conn:
cursor = conn.cursor(dictionary=True)
query = """
SELECT extension_attr
FROM dict_data
WHERE dict_type = %s AND dict_code = %s AND status = 1
LIMIT 1
"""
cursor.execute(query, (dict_type, dict_code))
result = cursor.fetchone()
cursor.close()
if result and result['extension_attr']:
try:
return json.loads(result['extension_attr']) if isinstance(result['extension_attr'], str) else result['extension_attr']
except (json.JSONDecodeError, AttributeError):
pass
return {}
except Exception as e:
print(f"Error getting dict extension {dict_code}: {e}")
return {}
@classmethod @classmethod
def get_config(cls, dict_code: str, default_value: Any = None) -> Any: def get_config(cls, dict_code: str, default_value: Any = None) -> Any:
""" """

View File

@ -1,13 +1,26 @@
# Core Application Framework
fastapi fastapi
uvicorn
# Database & Cache
mysql-connector-python mysql-connector-python
uvicorn[standard] redis
python-multipart
pydantic[email] # Services & External APIs
passlib[bcrypt] requests
qiniu
redis>=5.0.0
dashscope dashscope
PyJWT>=2.8.0 PyJWT
python-jose[cryptography]>=3.3.0 qiniu
# Validation & Forms
email-validator
python-multipart
# System Monitoring
psutil psutil
# APK Parsing
pyaxmlparser pyaxmlparser
# Audio Metadata
tinytagpython-dotenv

View File

@ -0,0 +1,26 @@
-- Migration to unify LLM config into a single dict entry 'llm_model'
-- Using dict_type='system_config' and dict_code='llm_model'
BEGIN;
-- Insert default LLM configuration
INSERT INTO `dict_data` (
`dict_type`, `dict_code`, `parent_code`, `label_cn`, `label_en`,
`sort_order`, `extension_attr`, `is_default`, `status`
) VALUES (
'system_config', 'llm_model', 'ROOT', '大模型配置', 'LLM Model Config',
0, '{"model_name": "qwen-plus", "timeout": 120, "temperature": 0.7, "top_p": 0.9}', 0, 1
)
ON DUPLICATE KEY UPDATE
`label_cn` = VALUES(`label_cn`);
-- Note: We avoid overwriting extension_attr on duplicate key to preserve existing settings if any,
-- UNLESS we want to force reset. The user said "refer to...", implying structure exists or should be this.
-- If I want to ensure the structure exists with keys, I might need to merge.
-- For simplicity, if it exists, I assume it's correct or managed by admin UI.
-- But since this is a new "unification", likely it doesn't exist or we want to establish defaults.
-- Let's update extension_attr if it's NULL, or just leave it.
-- Actually, if I am changing the SCHEMA of config (from individual to unified),
-- I should probably populate it.
-- Since I cannot easily read old values here, I will just ensure the entry exists.
COMMIT;

View File

@ -0,0 +1,22 @@
-- 更新voiceprint配置
-- 将dict_type='system_config'且dict_code='voiceprint_template'的记录改为 dict_type='voiceprint' 且 dict_code='voiceprint'
-- 或者如果已经存在voiceprint类型的配置则更新它
BEGIN;
-- 1. 尝试删除旧的voiceprint配置如果存在
DELETE FROM `dict_data` WHERE `dict_type` = 'system_config' AND `dict_code` = 'voiceprint_template';
-- 2. 插入或更新新的voiceprint配置
INSERT INTO `dict_data` (
`dict_type`, `dict_code`, `parent_code`, `label_cn`, `label_en`,
`sort_order`, `extension_attr`, `is_default`, `status`
) VALUES (
'voiceprint', 'voiceprint', 'ROOT', '声纹配置', 'Voiceprint Config',
0, '{"channels": 1, "sample_rate": 16000, "template_text": "我正在进行声纹采集,这段语音将用于身份识别和验证。\n\n声纹技术能够准确识别每个人独特的声音特征。", "duration_seconds": 12}', 0, 1
)
ON DUPLICATE KEY UPDATE
`extension_attr` = VALUES(`extension_attr`),
`label_cn` = VALUES(`label_cn`);
COMMIT;