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

  1. 在开始前你需要打开 VTubeStudio 的 Server 开关. 端口一般默认是8001.
    server_start.png

  2. 你需要确定自己Live2D口型同步的支持参数.
    请注意:下面提供一种简单的判断方式,但这种方式会修改(重置)Live2D模型口型部分参数,使用前请备份好自己的模型。
    如果你对自己的模型了如指掌,可以跳过这步。
    setup.png

    • 确认重置参数后,如果出现以下信息,则说明你的模型仅支持 基于分贝的口型同步 db.png
    • 确认重置参数后,如果出现以下信息,则说明你的模型仅支持 基于元音的口型同步 vowel.png
    • 如果VTubeStudio找到了所有参数,并且重置成功,说明两种方式都支持。只需要在接下来的代码中选择一种方式即可.
  3. 下面是两种基于不同方式的Demo.
    你可以找一个音频文件替换some.wav.
    samplerate:音频数据的采样率.
    output_device:输出设备Index. 可以参考audio_devices_utils.py

    • 基于分贝的口型同步
    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_device=2)
            await asyncio.sleep(100000)  # do something
    
    
    if __name__ == "__main__":
        asyncio.run(main())
    
    • 基于元音的口型同步
    import asyncio
    from pymouth import VTSAdapter, VowelAnalyser
    
    
    async def main():
        async with VTSAdapter(VowelAnalyser) as a:
            await a.action(audio='some.wav', samplerate=44100, output_device=2)
            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_device=2)

VTSAdapter以下是详细的参数说明:

param required default describe
analyser Y 分析仪,必须是 Analyser 的子类,目前支持DBAnalyserVowelAnalyser
db_vts_mouth_param 'MouthOpen' 仅作用于DBAnalyser, VTS中控制mouth_input的参数, 如果不是默认值请自行修改.
vowel_vts_mouth_param dict[str,str] 仅作用于VowelAnalyser, VTS中控制mouth_input的参数, 如果不是默认值请自行修改.
plugin_info dict 插件信息,可以自定义
vts_api dict VTS API的一些配置,这里可以自定义 VTS server port(8001)

await a.action() 会开始处理音频数据. 以下是详细的参数说明:

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

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_device=2, callback=callback) as a:
    a.async_action()  # no block
    # a.sync_action() # block
    print("end")
    time.sleep(1000000)

TODO

  • 文档补全
  • Test case

Special Thanks

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.1.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

pymouth-1.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymouth-1.1.0.tar.gz
Algorithm Hash digest
SHA256 387b641cd75842c5b3b8312aea142043fcfb45b30c2d56ae919b80e9e38527f8
MD5 4c141b43672dec949ca61a15ec0e535e
BLAKE2b-256 53bedca7e3fe77cd302b79d1cbc853f383a8d79471b032f28a781a0bfba4caac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymouth-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54df533a2dfd1d6f804b559aa1769841cdd0943d2444f96830d2d793ed159e66
MD5 cb4cc2905eeb366cb5234b6c24a2d959
BLAKE2b-256 e5ed7899cd93ef30b257bd37be04a73c447a96801f0615d2d3be9a0c12e792ac

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