Audiotoken
Tokenize audio to get acoustic and semantic tokens.
Installation
pip install audiotoken
Usage
Encoding
You can either use an acoustic or semantic encoder to encode audio and get tokens.
from pathlib import Path
from audiotoken import AudioToken, Tokenizers
encoder = AudioToken(tokenizer=Tokenizers.acoustic, device='cuda:0')
encoded_audio = encoder.encode(Path('path/to/audio.wav'))
There are 1 acoustic and 2 semantic tokenizers available:
Tokenizers.acousticTokenizers.semantic_s(Small)Tokenizers.semantic_m(Medium)
Decoding
You can decode acoustic tokens like this:
from pathlib import Path
from audiotoken import AudioToken, Tokenizers
tokenizer = AudioToken(tokenizer=Tokenizers.acoustic, device='cuda:0')
encoded_audio = tokenizer.encode(Path('path/to/audio.wav'))
decoded_audio = tokenizer.decode(encoded_audio)
# Save the decoded audio and compare it with the original audio
import torch
import torchaudio
torchaudio.save(
'reconstructed.wav',
decoded_audio,
sample_rate=24000
)
You can decode semantic tokens like this:
from pathlib import Path
from audiotoken import AudioToken, Tokenizers
semantic_tokenizer = AudioToken(tokenizer=Tokenizers.semantic_s, device='cuda:0')
semantic_toks = semantic_tokenizer.encode(Path('path/to/audio.wav'))
decoded_audio = semantic_tokenizer.decode(semantic_toks)
# Save the decoded audio and compare it with the original audio
import torch
import torchaudio
torchaudio.save(
'reconstructed.wav',
decoded_audio,
sample_rate=24000
)
See examples/usage.ipynb for more usage examples.
APIs
Core class
from audiotoken import AudioToken, Tokenizers
tokenizer = AudioToken(tokenizer=Tokenizers.semantic_m, device='cuda:0')
See audiotoken/core.py for complete documentation of APIs.
There are 3 APIs provided:
tokenizer.encode: Encode single audio files/arrays at a timetokenizer.encode_batch_files: Encode multiple audio files in batches and save them to disk directly- NOTE:
encode_batch_filesis not safe to run multiple times on the same list of files as it can result in incorrect data. This will be fixed in a future release.
- NOTE:
tokenizer.decode: Decode acoustic/semantic tokens
Metadata
Release files for audiotoken 0.3.1
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 |
|---|---|---|---|---|
| audiotoken-0.3.1.tar.gz | 31.5 kB | Without provenance | Details for audiotoken-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| audiotoken-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for audiotoken-0.3.1-py3-none-any.whl |
Total release size: 68.0 kB
Release files / audiotoken-0.3.1.tar.gz
| Download URL | audiotoken-0.3.1.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2be566893858388eac77879a0cbfae8aeac75390b05db69ee773d8c9fdbd7795
|
|
BLAKE2b-256 checksum How to use checksums |
d7ada1fce7449c898c718b904b0d435a5207555d7f0aa8439eff05a990836ee0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.7
|
Release files / audiotoken-0.3.1-py3-none-any.whl
| Download URL | audiotoken-0.3.1-py3-none-any.whl |
|---|---|
| Size | 36.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e804767e269c5efeca537e8aa1a57c562aa3914bc82fca2103bfb60bc4bca426
|
|
BLAKE2b-256 checksum How to use checksums |
e0b4903610c0e8d6d2f754b37c797bc2203b0272672ff69cb32ef8681e496397
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.7
|
Security for audiotoken 0.3.1
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.