Skip to main content

Live2D Mouth-sync artifact

Project description

PyPI - Python Version PyPI - License PyPI - Version PyPI - Downloads

pymouth

pymouth 是基于Python的Live2D口型同步库. 你可以用音频文件, 甚至是AI模型输出的ndarray, 就能轻松的让你的Live2D形象开口 唱跳RAP v.
效果演示视频. Demo video

Quick Start

Environment

  • Python>=3.10
  • VTubeStudio>=1.28.0 (可选)

Installation

pip install pymouth

Get Started

注意: 在开始前你需要打开 VTubeStudio 的 Server 开关. 端口一般默认是8001.
下面是一个完整的Demo,你可以找一个音频文件替换some.wav.

import asyncio
from pymouth import VTSAdapter, DBAnalyser


async def main():
    async with VTSAdapter(DBAnalyser) as a:
        await a.action(audio='some.wav', samplerate=44100, output_channels=1)
        await asyncio.sleep(100000)  # do something


if __name__ == "__main__":
    asyncio.run(main())

第一次运行程序时, VTubeStudio会弹出插件授权界面, 通过授权后, 插件会在runtime路径下生成pymouth_vts_token.txt文件, 之后运行不会重复授权, 除非token文件丢失或在VTubeStudio移除授权.

More Details

High Level

关键的代码只有两行,且都是异步的:

async with VTSAdapter(DBAnalyser) as a:
    await a.action(audio='some.wav', samplerate=44100, output_channels=1)

async with VTSAdapter(DBAnalyser) as a: 用来描述需要用到的 AdapterAnalyser. 目前支持的 Adapter 只有 VTSAdapter, 支持的 Analyser 只有 DBAnalyser. 如果真有人用的话可能会适配更多. 以下是详细的参数说明:

param required default describe
analyser Y 分析仪,必须是 Analyser 的子类,目前只支持DBAnalyser
db_vts_mouth_param 'MouthOpen' 针对于DBAnalyser, VTS中控制mouth_input的参数,这个参数一般是 'MouthOpen', 如果不是请自行修改.
plugin_info None 插件信息,一般不用改,可以自定义.
vts_api None VTS API的一些配置,一般不用改, 这里可以自定义 VTS server port(8001)

await a.action(audio='some.wav', samplerate=44100, output_channels=1) 会开始处理音频数据. 以下是详细的参数说明:

param required default describe
audio Y 音频数据, 可以是文件path, 可以是SoundFile对象, 也可以是ndarray
samplerate Y 采样率, 这取决与音频数据的采样率, 如果你无法获取到音频数据的采样率, 可以尝试输出设备的采样率.
output_channels Y 输出设备通道, 这取决与你的硬件, 你也可以使用虚拟设备.
finished_callback None 音频处理完成会回调这个方法
auto_play True 是否自动播放音频, 默认为True, 如果为True,会播放音频(自动将audio写入指定output_channels)

Low Level

Get Started 演示了一种High Level API 如果你不使用 VTubeStudio 或者想更加灵活的使用, 可以尝试Low Level API. 下面是一个Demo.

import time
from pymouth import DBAnalyser


def callback(y, data):
    print(y)  # do something


with DBAnalyser('zh.wav', 44100, output_channels=1, callback=callback) as a:
    a.async_action()  # no block
    # a.sync_action() # block
    print("end")
    time.sleep(1000000)

TODO

  • 文档补全
  • CI
  • 基于元音的口型同步API
  • Test case

Special Thanks

Idea源: 卜卜口

https://github.com/itorr/itorr/issues/7

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymouth-1.0.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

pymouth-1.0.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pymouth-1.0.2.tar.gz.

File metadata

  • Download URL: pymouth-1.0.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pymouth-1.0.2.tar.gz
Algorithm Hash digest
SHA256 474cb0c83eb2cd37c113c52bc65daa9eb877bb1545e19ef9d3cedf6e4ee5ce49
MD5 ec288383f47df774669cc7e1a3ea68ac
BLAKE2b-256 14a0452b2db26bcefe9ad5c4dc7c47caa1fc4b042f0f5edaea2e35d58584b7d2

See more details on using hashes here.

File details

Details for the file pymouth-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pymouth-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pymouth-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c8ae7754268b205978594137e1e1165595ba2b23f5723eed47800f9655c09ae
MD5 89f8cf0dfcaa29726614b1f126062e8b
BLAKE2b-256 48c519934bf08be99e0144aee7aaf3301496f1f4693acbbf49be9cfdab3ba551

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page