Skip to main content

WEM-first Python package shell for vgmstream public API bindings.

Project description

pyvgmstream

English version: README.en.md

pyvgmstream 是一个面向 Python 的 vgmstream 公共 API 包装层。

公开 API

  • probe():读取流元数据
  • probe_buffer():读取内存输入的流元数据
  • open_stream():打开保持上游输出采样格式的解码流
  • open_stream_from_buffer():从内存输入打开解码流
  • set_log_callback() / disable_log_callback():配置或关闭上游全局日志回调
  • decode_to_wav_file():解码并导出为 WAV 文件
  • decode_to_wav_bytes():解码并导出为 WAV 字节
  • decode_buffer_to_wav_file() / decode_buffer_to_wav_bytes():把内存输入解码并导出为 WAV
  • transcode_many() / transcode_tree():批量转码为 WAV
  • PlaybackSession / PlaybackSnapshot / PCM16Sink:播放控制核心
  • pyvgmstream.playback.backends.sounddevice.create_sounddevice_session():默认可选播放后端

基于 open_stream() 返回的 StreamHandle,当前可用的方法和属性包括:

  • 读取当前输出格式帧数据:read_frames(frame_count)
  • 显式读取 PCM16:read_pcm16(frame_count),仅在当前流已经是 PCM16 或显式请求 PCM16 时可用
  • 查询解码进度:tell_samples() / tell_seconds() / done
  • 流位置控制:seek_samples() / seek_seconds() / reset()
  • 读取上游格式元信息:sample_format / sample_size / input_channels / channel_layout / stream_samples / play_samples / duration_seconds / stream_bitrate / loop_start / loop_end / play_forever

安装与构建

如果发布产物中已经包含与你的 Python 版本和平台匹配的 wheel,优先使用 wheel 安装:

  • pip install pyvgmstream

如果没有匹配的 wheel,请按下面的源码构建前提准备环境。

源码构建前提

  • Windows:
    • Python >=3.10
    • CMake >=3.20
    • Visual Studio Build Tools
    • Desktop development with C++
  • macOS:
    • Python >=3.10
    • Xcode Command Line Tools
    • brew install cmake pkg-config libvorbis
  • Linux:
    • Python >=3.10
    • sudo apt-get update
    • sudo apt-get install -y gcc g++ make cmake build-essential git pkg-config libvorbis-dev

需要对照上游构建文档时,参考:

  • vendor/vgmstream/doc/BUILD.md
  • vendor/vgmstream/doc/BUILD-LIB.md

如果你是从 GitHub 仓库源码安装,还需要带上 submodule:

  • git clone --recursive https://github.com/Virace/pyvgmstream
  • 或者在 clone 后执行 git submodule update --init --recursive

如果你是从 PyPI 下载源码分发包,vendored vgmstream 已经包含在 sdist 中,不需要再额外初始化 submodule,但仍然需要本地编译环境。

常见安装路径

从当前仓库源码构建 wheel:

  • uv build --wheel

从当前仓库源码安装:

  • uv pip install .
  • pip install .

如果需要默认的本地播放后端,可安装可选 extra:

  • pip install "pyvgmstream[playback]"

强制走源码构建安装:

  • pip install --no-binary pyvgmstream pyvgmstream

当前说明

  • 当前项目的正式支持范围为 Python >=3.10
  • 发布 workflow 会从 Python 3.10 起覆盖三平台构建。
  • 平台目标当前收敛为:
    • Windows:x64
    • Linux:x86_64
    • macOS:arm64
  • 当前不计划为 macOS 提供 x64 wheel。

使用示例

读取元数据:

from pyvgmstream import probe

info = probe("example.wem")
print(info.sample_rate, info.channels, info.duration_seconds, info.codec_name)

读取内存中的 .wem 数据:

from pyvgmstream import probe_buffer

buffer_info = probe_buffer(wem_bytes, filename_hint="sound.wem")
print(buffer_info.sample_rate, buffer_info.sample_format)

接入上游日志:

from pyvgmstream import LogLevel, disable_log_callback, set_log_callback

set_log_callback(lambda level, message: print(level, message), level=LogLevel.INFO)
# ... 执行 probe/open_stream/decode 等操作
disable_log_callback()

读取保持上游输出采样格式的解码流:

from pyvgmstream import open_stream

with open_stream("example.wem") as stream:
    chunk = stream.read_frames(4096)
    print(stream.sample_format, stream.sample_size, len(chunk))
    print(stream.tell_seconds(), stream.duration_seconds, stream.done)

从内存输入打开解码流:

from pyvgmstream import open_stream_from_buffer

with open_stream_from_buffer(wem_bytes, filename_hint="sound.wem") as stream:
    chunk = stream.read_frames(4096)
    print(stream.sample_rate, len(chunk))

如果你明确需要 PCM16 便捷层,可以显式请求:

from pyvgmstream import DecodeConfig, SampleFormat, open_stream

with open_stream("example.wem", config=DecodeConfig(sample_format=SampleFormat.PCM16)) as stream:
    chunk = stream.read_pcm16(4096)
    print(len(chunk))

导出 WAV 文件:

from pyvgmstream import decode_to_wav_file

result = decode_to_wav_file("example.wem", "example.wav")
print(result.output_path, result.frame_count)

默认 WAV 导出会保留当前流的上游输出格式;如果下游想显式请求 PCM16 / PCM24 / PCM32,可以在 config 里传入对应的 SampleFormat

导出 WAV 字节:

from pyvgmstream import decode_to_wav_bytes

payload = decode_to_wav_bytes("example.wem")
print(len(payload))

直接把内存中的数据转成 WAV:

from pyvgmstream import decode_buffer_to_wav_bytes

payload = decode_buffer_to_wav_bytes(wem_bytes, filename_hint="sound.wem")
print(len(payload))

递归批量转码为 WAV:

from pyvgmstream import transcode_tree

summary = transcode_tree("input_wem", "output_wav", workers=4)
print(summary.processed_count, summary.failed_count)

使用默认可选播放后端:

from pyvgmstream.playback.backends.sounddevice import create_sounddevice_session

session = create_sounddevice_session("example.wem", volume_percent=25.0)
session.start()
session.wait()
print(session.snapshot().duration_seconds)

更完整的 API 说明见:

  • docs/api.md

许可证

  • 包装层自有代码使用 BSD-3-Clause,见 LICENSE
  • 第三方组件与许可证文本见 THIRD_PARTY_NOTICES.md
  • 当前收录的第三方许可证文本包括:
    • LICENSES/pybind11.txt
    • vendor/vgmstream/COPYING
    • vendor/vgmstream/ext_libs/licenses/*

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

pyvgmstream-0.1.0.tar.gz (8.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyvgmstream-0.1.0-cp314-cp314-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.14Windows x86-64

pyvgmstream-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyvgmstream-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyvgmstream-0.1.0-cp313-cp313-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.13Windows x86-64

pyvgmstream-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyvgmstream-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyvgmstream-0.1.0-cp312-cp312-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12Windows x86-64

pyvgmstream-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyvgmstream-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyvgmstream-0.1.0-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

pyvgmstream-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyvgmstream-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyvgmstream-0.1.0-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

pyvgmstream-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyvgmstream-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyvgmstream-0.1.0.tar.gz.

File metadata

  • Download URL: pyvgmstream-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyvgmstream-0.1.0.tar.gz
Algorithm Hash digest
SHA256 552f7c7d89d3e0d862f2058a51880f4aae09ac656b5b61e3dd7c6fce243306d7
MD5 0b3e795e631cb761d5a39f24351bab0a
BLAKE2b-256 8fcc8509554783ca0033b684cdd7151e0a136fec6ad7a25bd1c0fa9ee4a62d71

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0.tar.gz:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8a1f7064c0739760aa496531a068b947c7d3d35151d247ac7683b60b2643e4b5
MD5 d42aa574e2d0881f07a6ef5e0316415b
BLAKE2b-256 15d9b8bebe03adf5fa6056fad7d9e8fee59d8968d7914d6b5200728fb6e6c930

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp314-cp314-win_amd64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f48d5c4e672ba1771bfadd6c6894ad542c8817dd765c90ec846ed3cdb8152133
MD5 1b761913a34a6770561d1b6520a1f2f0
BLAKE2b-256 d9b0bbba1317196720fa3a8912239e350b8ed3c16b03069c8dcf87834a937d36

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1d596404e1d5c45065c06e54be49ccbe615dbcd66cbfd5b8713123d69c5551e
MD5 80ae23e18b5191cbdc47e21b7cdf4dc9
BLAKE2b-256 81b365c02fc2b4d367c3673fb114efa35537b06f0519e69b4fe2be5402a2d030

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2d6b9aeb3956476f32b1f0baf40e27c2f8310495537c92eb1e6e664aebcc0267
MD5 3ef8d9f68498c1f6c4dd6c9a2eace737
BLAKE2b-256 193d35a1cfd639ea3d790b0dd52414e52178155bfeb1029d86a4e46cfc454579

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2686e320c1d9327d8e701ca139b4f184f01efc7cc0b3cb0c5c9f3588d8a70f2a
MD5 2a8859ed672d4819bf1b1775d1e4b5a4
BLAKE2b-256 cf09aec090a74a88a02deef5a1fc8fc1cef53a17372d3c2b5696588fb5ff1a8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1fddadfd5620d569b88bb122aa820d56e777bc47d9cb9aa305c0a75e5f8bb843
MD5 30b86d4e21271d5ac5bc0130f7a71ea0
BLAKE2b-256 01baa724cae67dc6dd3b4fd98f02dbe8bef9fbb89de2dc8e722dec3b373fe92c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b8a65f473d5bdd4061142b489497b52dddf2d1c5af4008c1e2e2a2687be67325
MD5 6ed79ae7bb8471caf3bb7c027f1bc48c
BLAKE2b-256 35e9ee3b23d43aa6ee6be94b00de060eb07492a5502fa290cee0ce08981a6f01

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd2dd6e388d1b14a22ee7f5d1f1ef5fdf15899dc0322a1ab168b5fcf7437dbf4
MD5 4fcb06c9b9f8cb9d19da534a49023d4f
BLAKE2b-256 7469ceba86e1e3554822145a45bb2fb14ec114776bee00f5e328eaf4f33a1d78

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae7afd0de8ddcfcee70894ff978151d996eb5e7413725fd9b685ee6889259c5a
MD5 6f29c5ead58629d9414663f2d7658652
BLAKE2b-256 e10ed868e5a09051128e753d3592d80eb36b2a1ca11def68eca7fac74d7f3d84

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 942abdcebafc0d34600ec1626f29162d5972cef00fc523c975fe54f146958c4f
MD5 fdb4b64334fc413ab8f838e2a989e472
BLAKE2b-256 3b0656ee1a07916a7e231f818e262fbb7a42d4fdf0da9d198f5e67e07624de72

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a369f28949e76bcadee3194e85889fe9a7aae2bd3f6cb1d266bbeee8c59f59f
MD5 2c822f5a0fbbd6b265225c2236686f85
BLAKE2b-256 62ce5f94c5794aa1da6fb4228746b95fdd5cd73a0c88e156d3e79d17781faeed

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6fa15c9997cf45457124b6278285d1157c6bd809df480bbdc59fa5837db3a8f
MD5 aac374c6b03cdf13caa3ffb77e6b63e4
BLAKE2b-256 90581152498b2aa40615de2c195158e92c759914f025626221f47ef79da151a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 af3fe97f0b40288057c3ceecf908be46859cb751d0b873c2b4c6cd3b131f65f3
MD5 2a15667245cb93064f5b74685298227b
BLAKE2b-256 9a331b072fa31e78e5cdc9f7ba79bd2ced6829ab665f81b1fc906998dcc12208

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48ca2c257f6882460907f8f93deb961dda3ebcce874ebac57828ffe64ac9ae3f
MD5 d2d0e6be0579c03a8bd83d2cda016241
BLAKE2b-256 2b3feab161b237778088ce073f7bd24b4684e061dbe5fd98ca40456382885e01

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvgmstream-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a0fc894606a41d5ce741d2de49e3e385291e2cecbbf3275d3ff61cc2b0345ce
MD5 977288cde6e8c8b99e8ed96e8eafd6e3
BLAKE2b-256 09b858bfb4adec45ef34f94f42389e0b70ce8a5ff25f97a470077b6ff08a20f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on Virace/pyvgmstream

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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