Chanjing SDK
一个用于与禅境API交互的Python客户端库。
功能特点
- 提供数字人定制功能
- 支持声音定制
- 视频合成与管理
- 公共数字人资源访问
- 参数验证
- 错误处理
安装
使用pip安装:
pip install chanjing
使用方法
基础配置
from chanjing import ChanjingHttpClient
# 初始化客户端
client = ChanjingHttpClient(
app_id="your_app_id",
app_secret="your_app_secret"
)
1. 定制数字人
from chanjing.customised.person import CreateCustomisedPersonRequest, CustomisedPerson
# 创建定制数字人
person_request = CreateCustomisedPersonRequest(
name="数字人名称",
material_video="https://example.com/video.mp4", # 训练视频URL
callback="https://your-callback-url.com", # 回调地址
train_type=None # 可选的训练类型
)
person_id = client.customised.person.create(person_request)
# 获取定制数字人列表
list_request = ListCustomisedPersonRequest(page=1, page_size=10)
person_list = client.customised.person.list(list_request)
# 删除定制数字人
delete_request = DeleteCustomisedPersonRequest(id=person_id)
client.customised.person.delete(delete_request)
2. 定制声音
from chanjing.customised.audio import CreateCustomisedAudioRequest, CustomisedAudio
# 创建定制声音
audio_request = CreateCustomisedAudioRequest(
name="声音名称",
url="https://example.com/audio.wav", # 音频文件URL
callback="https://your-callback-url.com" # 回调地址
)
audio_id = client.customised.audio.create(audio_request)
# 获取定制声音列表
list_request = ListCustomisedAudioRequest(page=1, page_size=10)
audio_list = client.customised.audio.list(list_request)
3. 视频合成
from chanjing.synthesis import (
Video, CreateVideoRequest, PersonConfig,
AudioConfig, TTSConfig, BgConfig, SubtitleConfig
)
# 配置数字人
person_config = PersonConfig(
id="digital_person_id", # 数字人ID
x=0, # x坐标位置
y=0, # y坐标位置
width=1080, # 宽度
height=1920, # 高度
figure_type=None, # 可选,whole_body仅用于公共数字人
drive_mode=None, # 可选,支持正常顺序和随机帧动作
is_rgba_mode=False, # 是否使用RGBA模式
backway=1 # 1正放,2倒放
)
# 配置TTS
tts_config = TTSConfig(
text=["您好,这是测试文本"], # 文本内容
speed=1.0, # 语速(0.5-2.0)
audio_man="voice_id" # 音色ID
)
# 配置音频
audio_config = AudioConfig(
tts=tts_config,
wav_url=None, # 可选,外部音频文件URL
type="tts", # "tts"或"audio"
volume=100, # 音量
language="cn" # 语言
)
# 创建视频
video_request = CreateVideoRequest(
person=person_config,
audio=audio_config,
bg_color="#000000", # 背景颜色
screen_width=1080, # 视频宽度
screen_height=1920, # 视频高度
callback="https://your-callback-url.com" # 可选的回调地址
)
video_id = client.video.create(video_request)
# 获取视频列表
list_request = ListVideoRequest(page=1, page_size=10)
video_list = client.video.list(list_request)
更详细的示例请参考 examples/http_client_example.py。
开发环境设置
- 克隆仓库
- 创建并激活虚拟环境
- 安装开发依赖
git clone https://github.com/yourusername/dify_sdk.git
cd dify_sdk
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
pip install -e ".[dev]"
发布到PyPI
本项目使用Hatch作为构建和发布工具。以下是发布到PyPI的步骤:
1. 安装Hatch
pip install hatch
# 或使用uv
uv pip install hatch
2. 配置PyPI凭证
有两种方式配置PyPI凭证:
方式一:使用API令牌(推荐)
- 在PyPI官网注册并登录账号
- 在账号设置中创建API令牌
- 创建
~/.pypirc文件:
[pypi]
username = __token__
password = pypi-AgEIcHlwaS5vcmcCJDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
方式二:使用环境变量
# Windows (PowerShell)
$env:HATCH_INDEX_USER="__token__"
$env:HATCH_INDEX_AUTH="pypi-AgEIcHlwaS5vcmcCJDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Linux/Mac
export HATCH_INDEX_USER=__token__
export HATCH_INDEX_AUTH=pypi-AgEIcHlwaS5vcmcCJDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3. 构建分发包
hatch build
这将在dist/目录下创建源代码分发包(.tar.gz)和轮子分发包(.whl)。
4. 发布到PyPI
hatch publish
如果您想先在测试环境(TestPyPI)上发布:
hatch publish -r test
5. 验证发布
发布成功后,您可以通过pip安装您的包来验证:
pip install chanjing
许可证
MIT
项目结构
chanjing/
├── __init__.py
├── core.py # 核心客户端实现
├── schemas.py # 数据模型定义
├── synthesis.py # 视频合成相关
├── user_info.py # 用户信息管理
└── customised/ # 定制功能模块
├── person.py # 定制数字人
└── audio.py # 定制声音
Metadata
Release files for chanjing2 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chanjing2-0.1.2.tar.gz | 9.7 kB | Without provenance | Details for chanjing2-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chanjing2-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for chanjing2-0.1.2-py3-none-any.whl |
Total release size: 22.9 kB
Release files / chanjing2-0.1.2.tar.gz
| Download URL | chanjing2-0.1.2.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20f6c4bd5344f090aa19db3a322ffe52e1d2a0c5a5763d19ac5a06c031b76cfa
|
|
BLAKE2b-256 checksum How to use checksums |
09561d8e30a36f21a05f6ec1cd86a964f00ace9b508675b7540aa8bb8f777de9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.4
|
Release files / chanjing2-0.1.2-py3-none-any.whl
| Download URL | chanjing2-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5519f37b588790f401fbd8ac9e02cbf299ba5bb86dae6e4014fa9743aee6baf4
|
|
BLAKE2b-256 checksum How to use checksums |
1d836dc09e79ae3d2b66d7deaf67fc3162a0cc1205a16babba126f7e24d59061
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.4
|
Security for chanjing2 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.