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
  • BatchTranscodeProgress:批量转码进度快照
  • 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 BatchTranscodeProgress, transcode_tree


def on_progress(progress: BatchTranscodeProgress) -> None:
    print(progress.completed_count, progress.total_count, progress.failed_count)

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

progress_callback 会在父进程汇总结果时异步收到 BatchTranscodeProgress,回调异常不会中断转码。

使用默认可选播放后端:

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.1.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.1-cp314-cp314-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.14Windows x86-64

pyvgmstream-0.1.1-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.1-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pyvgmstream-0.1.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pyvgmstream-0.1.1-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.1-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pyvgmstream-0.1.1-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.1-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pyvgmstream-0.1.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: pyvgmstream-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 56a79bb93a8894730c0b4f3d42c0c2aee218668d6a36f0eb160f18626467b35a
MD5 9255007190df6c9839b3049c8a00cfd6
BLAKE2b-256 1283f937c638178e54b60822bb8db800028fb89aae9684b845263133906328d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1.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.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c704b63ae57f535c930e2b69822617cfabd40a1b9e36d0701565d4cd64f817a3
MD5 2cd7f9f5603b835dbd62f24536c4e84e
BLAKE2b-256 32f16e0960978a3b4773f07076fb2390ab288d21be492e9ef2e5f7f60b8de744

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 59671533542ff1f95a1cf97ec9e58bacc42fc3fcb403fb9fd4ccc28e5ea1c41b
MD5 cff9ff8afe3d8380539bbd4cb686cdc0
BLAKE2b-256 1d593cf8ba505b3fd672a51486bbf4ff7f6dca32fa9bfb956749c3cea4f0bf2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7e0b8a52e03a0cb1bf79c0e8a84c2b8800b6979bc55ad99cd430241fa2c84b4
MD5 cfd14899d0bc984b6f93585aea7109ba
BLAKE2b-256 ee04dd15b3ef8eefc2e3c97bfc115bbe84729c81480b5e67c11345bf6eb3ad1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6ac2e05d789b5bbdd3150a8180c6de140fe7abdda9d1cf4a6c8211f4431e4fbc
MD5 52524585c132118229e5b78fe1a0f890
BLAKE2b-256 6a3a79fdee43cac0eb8766b25b0fcea885c5fd2de9a29b3c942e713f32fea8d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 88e7b92020e4f161697481fe3e736c8eb47458b8b6548c75195db2a67fcd8f4e
MD5 7ed67463cd4e5e2eb6c8230117cce84a
BLAKE2b-256 7ab19db4612b5c8025ed0a0948e2151914e468f858c1fb4a8916c388dc830b41

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12855fc41a38dd5387be8af98c0b92289c8910f6c9b46df9e83583dc1807aa91
MD5 ba1c1dcdfc30137420d818d96544694e
BLAKE2b-256 8349048cd2fe77e176efb9d3284e777ae98efd83a7fd9e0cc106bb56c4e1a78b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 eb73f713e108013db735baa6c949c45eec815d60ae3ac0a8547e136fe2bdbdc8
MD5 68d09847af2d25b74690bbc098c69cdd
BLAKE2b-256 a77d495beb754f4a942110d6554f3f41699260362d562d5f232df602f8248b0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f98896739af0103a6780827d005206670e5b21024a2d3e087765e0fd77261178
MD5 46638cd98e548ffaa0bc136f44366308
BLAKE2b-256 8bd898923d31cc6dc2e3fb56eec0da9d2c9f7e7cc5f4eebd7ec1c8010f47da05

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1d25214b056e869b2a0001e458075e6e45a626a415b3b0b58f47605263844dc3
MD5 c6be387dde09d910f1f19a5841f2d35f
BLAKE2b-256 acde8285c1e9b5c4a707ee058c2df5bbd6083a428dca1ffc0d60393196b62136

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fcdc1f3f02fd61cfb56ced5d67bd2175d441b78c401796d092d5e10164ea77f0
MD5 d450c2323f5029b0fb708edb379e64d6
BLAKE2b-256 483dc2808fea29b7979c20bb219217c618f2bbe8319bcc807fac2d673188214e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48a58832e2bf42998a3770cffacb40ba1d42a1f33bdd1bc0540daabf171c92f7
MD5 fb0815c17d75bc324d45c6e0d920c00e
BLAKE2b-256 7e6f42d314e594537d253bbb55cd1ebe7e8774a7da52eaf2e9e6ef36ecc243be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b759cf5e3e23f3cca319208292b063da5707213e93c3043ead88f2556389f2c7
MD5 128b669dbc0dc5788da419ba8381a431
BLAKE2b-256 f469979b1c56426ddd96984506794fbbd9bfba3698ea2735beed82db91b0f5b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f53c8aa72cf6d84d3f09bf882fd992bc0e33eeb9c72c70986f4f2b61a223db6d
MD5 6fe8407c3587c5a1c12e11ee44deb3a4
BLAKE2b-256 c77efdf37861743e7a68911e7d7bbdd6e8260695f3c880a5db5bef9ce30800b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dc77ceea14094436d04164be1d7766a187b34a2b3bb07c86ef28c8be8db45e10
MD5 7fa078685462f00feb1b8db88f93be87
BLAKE2b-256 7b890791ad5b16bac7913ecd3aac6fc90a0efbc7e4661a182e31d8649d22328a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvgmstream-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 377cd43a446acea8fa830307292556173d6e982e23bb76091694fd5e6499e432
MD5 f1c13bbc2a6b126b7972d0be7bb921b3
BLAKE2b-256 8ee7b0b11af9900966860572fb447ef1215ea3f04cc77e8530ef98025ad0d41d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvgmstream-0.1.1-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