Instructions to use litert-community/ZONOS3-Mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/ZONOS3-Mini with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Add ZONOS3-Mini as three float32 LiteRT graphs with an Android runner
Browse filesThree float32 .tflite graphs of Zyphra/ZONOS3-Mini-hf at commit e39d30df for the CPU, with a prebuilt arm64 Android runner that speaks six prepared sentences and a desktop Python script for English sentences of your own.
This view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +29 -0
- HOST.md +34 -0
- NOTICE +13 -0
- README.md +99 -0
- android/libLiteRt.so +3 -0
- android/zonos_host +3 -0
- desktop/README.md +15 -0
- desktop/host.py +268 -0
- desktop/requirements.txt +43 -0
- desktop/speak.py +204 -0
- graphs/codec_dec_f150.tflite +3 -0
- graphs/lm_step_p768.tflite +3 -0
- graphs/spk_enc_t998.tflite +3 -0
- host/audio.cpp +72 -0
- host/core.hpp +48 -0
- host/graphs.cpp +57 -0
- host/main.cpp +210 -0
- include/pocketfft.h +0 -0
- kit/MANIFEST.json +295 -0
- kit/shared/books.f32 +3 -0
- kit/shared/dec_cos.f32 +3 -0
- kit/shared/dec_sin.f32 +3 -0
- kit/shared/embeddings.f32 +3 -0
- kit/shared/hann2208.f32 +0 -0
- kit/shared/hann736.f32 +0 -0
- kit/shared/lm_cos.f32 +0 -0
- kit/shared/lm_sin.f32 +0 -0
- kit/shared/mixer.f32 +0 -0
- kit/shared/resample.f32 +3 -0
- kit/shared/text_pad.f32 +0 -0
- kit/shared/window0.f32 +0 -0
- kit/shared/window1.f32 +3 -0
- kit/shared/window2.f32 +3 -0
- kit/shared/window3.f32 +3 -0
- kit/shared/window4.f32 +3 -0
- kit/takes/s00/draws.f32 +3 -0
- kit/takes/s00/prompt.f32 +3 -0
- kit/takes/s00/reference/take_codes.npy +3 -0
- kit/takes/s00/reference/waveform.npy +3 -0
- kit/takes/s00/reference/waveform.wav +3 -0
- kit/takes/s00/request.json +6 -0
- kit/takes/s00/silence.i32 +0 -0
- kit/takes/s01/draws.f32 +3 -0
- kit/takes/s01/prompt.f32 +3 -0
- kit/takes/s01/reference/take_codes.npy +3 -0
- kit/takes/s01/reference/waveform.npy +3 -0
- kit/takes/s01/reference/waveform.wav +3 -0
- kit/takes/s01/request.json +6 -0
- kit/takes/s01/silence.i32 +0 -0
- kit/takes/s02/draws.f32 +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,32 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
android/libLiteRt.so filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
android/zonos_host filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
kit/shared/books.f32 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
kit/shared/dec_cos.f32 filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
kit/shared/dec_sin.f32 filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
kit/shared/embeddings.f32 filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
kit/shared/resample.f32 filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
kit/shared/window1.f32 filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
kit/shared/window2.f32 filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
kit/shared/window3.f32 filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
kit/shared/window4.f32 filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
kit/takes/s00/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
kit/takes/s00/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
kit/takes/s00/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
kit/takes/s01/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
kit/takes/s01/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
kit/takes/s01/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
kit/takes/s02/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
kit/takes/s02/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
kit/takes/s02/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
kit/takes/s03/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
kit/takes/s03/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
kit/takes/s03/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
kit/takes/s04/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
kit/takes/s04/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
kit/takes/s04/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
kit/takes/s05/draws.f32 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
kit/takes/s05/prompt.f32 filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
kit/takes/s05/reference/waveform.wav filter=lfs diff=lfs merge=lfs -text
|
HOST.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Android arm64 host and kit format
|
| 2 |
+
|
| 3 |
+
Build from the release root with Android NDK 29.0.13113456. Set NDK_BIN to the LLVM bin directory for your build machine. The pocketfft header at revision 0fa0ef591e38c2758e3184c6c23e497b9f732ffa is supplied as include/pocketfft.h. The tested target is Android API 28 and arm64-v8a.
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
"$NDK_BIN/aarch64-linux-android28-clang++" -std=c++17 -O2 -ffp-contract=off -Iinclude host/main.cpp host/audio.cpp host/graphs.cpp -static-libstdc++ -Landroid -lLiteRt -Wl,-rpath,'$ORIGIN' -o android/zonos_host
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
Place the runner and libLiteRt.so together. With the release directory on the device, the invocation for the first sentence is:
|
| 10 |
+
|
| 11 |
+
```sh
|
| 12 |
+
LD_LIBRARY_PATH=android android/zonos_host kit s00 graphs/lm_step_p768.tflite graphs/codec_dec_f150.tflite out/s00
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
The last argument must be a new directory. It receives codes.i32, waveform.f32 and waveform.wav. Standard error records the sentence tag, frames, sample count and elapsed seconds.
|
| 16 |
+
|
| 17 |
+
## Kit contract
|
| 18 |
+
|
| 19 |
+
kit/MANIFEST.json describes the graph form (`"form": "F"` = the fp32 graphs in graphs/), four CPU threads, Savannah, six tagged requests and little-endian byte order. Its files dictionary maps kit-relative payload paths to byte counts and SHA-256. Its graph records carry paths relative to the release root, byte counts and SHA-256. The graph files are external to the kit.
|
| 20 |
+
|
| 21 |
+
| Input | On-disk representation |
|
| 22 |
+
|---|---|
|
| 23 |
+
| takes/TAG/request.json | Tag, language, original text, seed. |
|
| 24 |
+
| takes/TAG/prompt.f32 | Contiguous float32 [P,1024] summed prompt embeddings, including voice and conditions. P is file bytes / 4096. |
|
| 25 |
+
| takes/TAG/silence.i32 | Three delayed prefill rows of ten little-endian int32 audio IDs. |
|
| 26 |
+
| takes/TAG/draws.f32 | One float32 [10,4098] matrix of independent unit-rate exponential draws per sampled row. The stream contains 769−P rows, enough through the last LM position. |
|
| 27 |
+
| shared/ | Generation embedding tables [10,4098,1024] plus the text-pad vector [1024], LM RoPE cosine/sine [768,16], ten codec codebooks [10,4096,8], decoder RoPE and five causal window masks, Hann windows, mixer and resampler coefficients. All use contiguous float32 in row-major order. |
|
| 28 |
+
| takes/TAG/reference/ | take_codes.npy [frames,10], served waveform.npy and PCM16 waveform.wav at 44100 Hz, made with the fp32 graphs on a Mac CPU, for comparison. |
|
| 29 |
+
|
| 30 |
+
These requests use precomputed Savannah voice prefixes. The Android CLI invokes the LM and decoder graphs; a reference-recording frontend can use the separate speaker graph. Keep the full set of inputs together when validating an output against the reference.
|
| 31 |
+
|
| 32 |
+
## Provenance
|
| 33 |
+
|
| 34 |
+
This conversion derives the fp32 graphs and table blobs from Zyphra/ZONOS3-Mini-hf at e39d30df560125d9c434acd5cb0e83e4c2d64e0d. Conversion changes include a one-row recurrent LM signature with external state, static padded codec and speaker signatures, and host-side audio reconstruction. The desktop utility adapts the original request path to call these graphs. Keep the model NOTICE, the packaged license texts and the pocketfft header’s redistribution notice with any copy of these files.
|
NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ZONOS3-Mini (transformers port)
|
| 2 |
+
Copyright (c) 2026 Zyphra, Inc.
|
| 3 |
+
|
| 4 |
+
The model weights are released under the Apache License 2.0. The remote code (configuration_zonos3.py,
|
| 5 |
+
modeling_zonos3.py) is ported from github.com/Zyphra/ZONOS3-Mini (MIT, licenses/ZONOS3-MIT.txt) and includes:
|
| 6 |
+
|
| 7 |
+
1. AntSpeaker (https://github.com/ant-research/AntSpeaker), Copyright (c) 2026 Ant Group Co., Ltd., Apache-2.0
|
| 8 |
+
(licenses/antspeaker-Apache-2.0.txt): the MECT-B2 speaker encoder model code, re-implemented.
|
| 9 |
+
2. Hugging Face Transformers (https://github.com/huggingface/transformers), Copyright 2025 The Qwen team, Alibaba Group
|
| 10 |
+
and the HuggingFace Inc. team, Apache-2.0 (licenses/transformers-Apache-2.0.txt): torch_chunk_gated_delta_rule and
|
| 11 |
+
torch_recurrent_gated_delta_rule, adapted from the Qwen3-Next model.
|
| 12 |
+
3. torchaudio (https://github.com/pytorch/audio), Copyright (c) 2017 Facebook Inc. (Soumith Chintala), BSD-2-Clause
|
| 13 |
+
(licenses/torchaudio-BSD-2-Clause.txt): the Kaldi fbank and the sinc resampling kernel, re-implemented.
|
README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language: [en]
|
| 4 |
+
pipeline_tag: text-to-speech
|
| 5 |
+
base_model: Zyphra/ZONOS3-Mini-hf
|
| 6 |
+
base_model_relation: quantized
|
| 7 |
+
library_name: litert
|
| 8 |
+
tags: [litert, tflite, android, text-to-speech, zonos3]
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# ZONOS3-Mini for LiteRT
|
| 12 |
+
|
| 13 |
+
This repository contains [Zyphra/ZONOS3-Mini-hf](https://huggingface.co/Zyphra/ZONOS3-Mini-hf/tree/e39d30df560125d9c434acd5cb0e83e4c2d64e0d), Zyphra's text-to-speech model, as three float32 LiteRT `.tflite` graphs for the CPU, with a prebuilt Android runner and a desktop Python script. On a Pixel 11 Pro's CPU, one prepared sentence of about 4 s took about 37 s from start to WAV, loading the graphs included. Speed still being tuned (updates follow).
|
| 14 |
+
|
| 15 |
+
On a Mac's CPU, the graphs gave the same audio codes as the publisher's PyTorch model in 60 of 60 test runs. On a Pixel 11 Pro and a Galaxy S26 (Snapdragon, SM8850), six prepared sentences gave the same codes as on the Mac in every frame.
|
| 16 |
+
|
| 17 |
+
On an Android phone, one command of the runner `android/zonos_host` speaks one of the six prepared sentences in `kit/` to a WAV file ([Use it](#use-it)). The runner takes no text, only these prepared inputs. An English sentence of your own goes through `desktop/speak.py`, which needs the publisher's files and which we ran on a Mac. On a GPU, the output was not shown to match: run the graphs on the CPU ([Notes](#notes)).
|
| 18 |
+
|
| 19 |
+
## Use it
|
| 20 |
+
|
| 21 |
+
### 1. Download
|
| 22 |
+
|
| 23 |
+
<!-- usage:download -->
|
| 24 |
+
```bash
|
| 25 |
+
pip install -U huggingface_hub
|
| 26 |
+
hf download litert-community/ZONOS3-Mini --local-dir ZONOS3-Mini
|
| 27 |
+
cd ZONOS3-Mini
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
The download is about 4.7 GB.
|
| 31 |
+
|
| 32 |
+
### 2. Speak a prepared sentence on an Android phone
|
| 33 |
+
|
| 34 |
+
You need an arm64 Android phone with USB debugging on, `adb`, and about 4.8 GB free on the phone, and the runner's peak memory on both phones was 3.54 GB.
|
| 35 |
+
|
| 36 |
+
<!-- usage:android -->
|
| 37 |
+
```bash
|
| 38 |
+
adb shell mkdir -p /data/local/tmp/zonos3
|
| 39 |
+
adb push android graphs kit /data/local/tmp/zonos3/
|
| 40 |
+
adb shell "cd /data/local/tmp/zonos3 && chmod 755 android/zonos_host && LD_LIBRARY_PATH=android android/zonos_host kit s00 graphs/lm_step_p768.tflite graphs/codec_dec_f150.tflite out/s00"
|
| 41 |
+
adb pull /data/local/tmp/zonos3/out/s00/waveform.wav s00.wav
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
The runner speaks `s00`, the first prepared sentence. It writes three files into `out/s00`, which must not exist yet: `waveform.wav` (mono, 16-bit, 44.1 kHz), `waveform.f32` (the same audio in float32) and `codes.i32` (ten codes per frame). On standard error it prints `TAKE s00 frames=62 samples=182280 wall_s=…`, where `wall_s` is the time from its start to the written WAV. Replace `s00` with `s01` to `s05` for the other sentences.
|
| 45 |
+
|
| 46 |
+
Every input the runner reads is prepared. `kit/takes/s00/prompt.f32` contains the sentence and the voice Savannah as rows of 1,024 numbers, made in Python on a Mac, and `draws.f32` contains the random draws for sampling. This release has no text front end for Android, so the runner speaks only these six sentences:
|
| 47 |
+
|
| 48 |
+
| sentence | text |
|
| 49 |
+
|---|---|
|
| 50 |
+
| `s00` | The quick brown fox jumps over the lazy dog near the riverbank. |
|
| 51 |
+
| `s01` | Please remember to bring an umbrella, because it might rain this afternoon. |
|
| 52 |
+
| `s02` | She opened the window and listened to the birds singing in the garden. |
|
| 53 |
+
| `s03` | The train leaves at 7:45 and arrives in Boston about 3 hours later. |
|
| 54 |
+
| `s04` | Thank you for calling. Your order has been shipped and will arrive soon. |
|
| 55 |
+
| `s05` | a Japanese sentence, written in `kit/takes/s05/request.json` |
|
| 56 |
+
|
| 57 |
+
### 3. Speak your own English sentence on a Mac
|
| 58 |
+
|
| 59 |
+
This needs Python 3.12 and the publisher's files at commit e39d30df (2.39 GB: code, tokenizer, voices and weights).
|
| 60 |
+
|
| 61 |
+
<!-- usage:desktop -->
|
| 62 |
+
```bash
|
| 63 |
+
hf download Zyphra/ZONOS3-Mini-hf --revision e39d30df560125d9c434acd5cb0e83e4c2d64e0d --local-dir ZONOS3-Mini-hf
|
| 64 |
+
python3.12 -m venv .venv
|
| 65 |
+
source .venv/bin/activate
|
| 66 |
+
pip install -r desktop/requirements.txt
|
| 67 |
+
MODEL=ZONOS3-Mini-hf
|
| 68 |
+
python -I -B desktop/speak.py "Please remember to bring an umbrella." --model "$MODEL" --graphs graphs --out umbrella
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
The script loads the publisher's model and code from `$MODEL` (with `trust_remote_code`) and runs the graphs with ai-edge-litert 2.3.0 on 4 CPU threads. It writes `umbrella/speech.wav` (mono, 16-bit, 44.1 kHz), `umbrella/codes.npy`, `umbrella/waveform.npy` and `umbrella/run.json`, and `umbrella` must not exist yet. It speaks English in the voice Savannah and samples with PyTorch's generator from `--seed` (1000 by default). With `--speaker-wav <file.wav>`, it takes the voice of a recording instead: the speaker graph reads only the first 10 s, where the publisher's model reads up to 60 s.
|
| 72 |
+
|
| 73 |
+
## Files
|
| 74 |
+
|
| 75 |
+
| file | bytes | what |
|
| 76 |
+
|---|---|---|
|
| 77 |
+
| `graphs/lm_step_p768.tflite` | 3,342,543,296 | the language model |
|
| 78 |
+
| `graphs/codec_dec_f150.tflite` | 572,522,276 | the decoder: audio codes in, spectral rows out |
|
| 79 |
+
| `graphs/spk_enc_t998.tflite` | 45,122,316 | the speaker encoder: a voice embedding from a recording, used by the desktop script only |
|
| 80 |
+
| `android/zonos_host` | 7,139,128 | the Android runner, built for arm64-v8a and Android API level 28; its C++ source is in `host/` and `include/` |
|
| 81 |
+
| `android/libLiteRt.so` | 5,629,696 | LiteRT 2.3.0, the runtime library the runner loads (`com.google.ai.edge.litert:litert:2.3.0` on Google Maven) |
|
| 82 |
+
| `desktop/speak.py` | | speaks an English sentence to a WAV file with Python; `host.py`, `requirements.txt` and `README.md` sit beside it |
|
| 83 |
+
| `kit/` | 768,008,027 in 59 files | the prepared inputs: six sentences in `kit/takes/`, the tables they share in `kit/shared/`, and reference outputs |
|
| 84 |
+
| [`HOST.md`](https://huggingface.co/litert-community/ZONOS3-Mini/blob/main/HOST.md) | | how to rebuild the runner (Android NDK 29.0.13113456) and call it, and the files of `kit/` |
|
| 85 |
+
| `NOTICE`, `licenses/` | | the publisher's notice and license texts, LiteRT's license and notices, and the Android NDK toolchain notice ([License](#license)) |
|
| 86 |
+
|
| 87 |
+
## Notes
|
| 88 |
+
|
| 89 |
+
- **GPU.** On a Mac's GPU, the language-model graph did not match the publisher's model in 910 of 910 steps, and the phones' GPUs were not tried.
|
| 90 |
+
- **Length.** One call of the decoder graph speaks at most 150 frames (10 s, the three silence frames that open the speech included). Longer speech stops with `BucketExceeded`: split longer text and speak each part.
|
| 91 |
+
- **Positions.** The prompt and the generated speech share 768 positions of the language-model graph. When they are used up, generation stops with `CapacityReached`.
|
| 92 |
+
- **Random draws.** The prepared inputs carry their random draws, which is why their output matches the reference exactly. An app supplies its own draws, and its codes then differ from the reference.
|
| 93 |
+
- **How the files were made.** The three graphs were exported in float32 with litert-torch 0.10.0 from the publisher's weights at commit e39d30df.
|
| 94 |
+
|
| 95 |
+
## License
|
| 96 |
+
|
| 97 |
+
The graphs and the tables in `kit/` are derived from the publisher's weights, which the publisher releases under the Apache License 2.0 ([NOTICE](https://huggingface.co/litert-community/ZONOS3-Mini/blob/main/NOTICE)). The publisher's repository has no LICENSE file. Our own files in this repository are released under the Apache License 2.0, like the weights: the runner's source in `host/`, `HOST.md` and the scripts in `desktop/`.
|
| 98 |
+
|
| 99 |
+
`NOTICE` and the four texts in `licenses/` that it names come unchanged from that repository at commit e39d30df: the MIT license of the original ZONOS3-Mini code and the licenses of the AntSpeaker, Hugging Face Transformers and torchaudio code that the publisher's model code adapts. `android/libLiteRt.so` is LiteRT 2.3.0 from Google Maven, with its license and third-party notices in `licenses/LiteRT-LICENSE.txt` and `licenses/LiteRT-THIRD_PARTY_NOTICE.txt`. The runner links the Android NDK's C++ runtime statically (notice: `licenses/NDK-NOTICE.toolchain`), and `include/pocketfft.h` carries its own BSD license.
|
android/libLiteRt.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e5b7e3413a8b428b1a1b669f368cf613058868bc7b63e10d0b9c2e6ba55c97d8
|
| 3 |
+
size 5629696
|
android/zonos_host
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:53cc7a359b0343b086cc5fcd4bef368e6a887d8e2f72f71a4d88fe8a5df5b964
|
| 3 |
+
size 7139128
|
desktop/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# One English sentence on macOS
|
| 2 |
+
|
| 3 |
+
Use the three fp32 graphs in graphs/, the local author snapshot at e39d30df560125d9c434acd5cb0e83e4c2d64e0d and the Python environment in requirements.txt. The snapshot supplies the tokenizer, voice table, host weights and the author’s request and sampling code. The command uses four Mac CPU threads. [Model source at commit e39d30df](https://huggingface.co/Zyphra/ZONOS3-Mini-hf/tree/e39d30df560125d9c434acd5cb0e83e4c2d64e0d)
|
| 4 |
+
|
| 5 |
+
From the release root, set MODEL to the local snapshot directory and run the following command. Supply a fresh output directory.
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
python -I -B desktop/speak.py "Please remember to bring an umbrella." --model "$MODEL" --graphs graphs --out umbrella
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
Listen to umbrella/speech.wav (mono PCM16 at 44100 Hz). umbrella/codes.npy contains ten int32 codes per frame. umbrella/waveform.npy contains the served float32 samples before PCM quantization, and umbrella/run.json records the seed, dimensions and graph call counts.
|
| 12 |
+
|
| 13 |
+
Savannah uses released voice codes. For a recording, add `--speaker-wav reference.wav`; the speaker graph uses up to the first ten seconds and returns a 192-float embedding. With `--seed N`, the author’s sampler uses its PyTorch CPU generator. Add `--draws kit/takes/s00/draws.f32` to use the stored exponential variates instead. Exact s00 replay also uses its original sentence, Savannah and seed 1000. A sentence must fit the 768-position LM cache and the 150-frame decoder bucket.
|
| 14 |
+
|
| 15 |
+
The tested interpreter was CPython 3.12.13 on arm64 macOS 27.0. requirements.txt gives the installed version and its PyPI page for each direct dependency and its active transitive dependencies. Model and graph loading is local. The Transformers module cache uses HF_HOME, defaulting to .zonos-cache/hf under the working directory.
|
desktop/host.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Host operations for the fp32 LiteRT graphs.
|
| 2 |
+
|
| 3 |
+
The Kaldi feature extraction and resampling algorithms follow the model's
|
| 4 |
+
upstream implementation. See the model NOTICE for attribution.
|
| 5 |
+
This module provides graph inputs and NumPy audio processing for synthesis.
|
| 6 |
+
"""
|
| 7 |
+
import math
|
| 8 |
+
import numpy as np
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
|
| 12 |
+
NEG = -30000.0
|
| 13 |
+
|
| 14 |
+
def layer_kinds(c):
|
| 15 |
+
gdn = [l for l in range(c["n_layers"]) if (l + 1) % c["gdn_period"] != 0]
|
| 16 |
+
attn = [l for l in range(c["n_layers"]) if (l + 1) % c["gdn_period"] == 0]
|
| 17 |
+
return gdn, attn
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def empty_state(c, past):
|
| 21 |
+
"""Zero cache for a new sequence: (kv [1, kv, 2A P, hd], gdn_state, conv_state), numpy float32."""
|
| 22 |
+
import numpy as np
|
| 23 |
+
gdn, attn = layer_kinds(c)
|
| 24 |
+
inner = c["gdn_heads"] * c["gdn_head_dim"]
|
| 25 |
+
return (np.zeros((1, c["n_kv_heads"], 2 * len(attn) * past, c["head_dim"]), np.float32),
|
| 26 |
+
np.zeros((len(gdn), c["gdn_heads"], c["gdn_head_dim"], c["gdn_head_dim"]), np.float32),
|
| 27 |
+
np.zeros((len(gdn), c["gdn_kernel"] - 1, 3 * inner), np.float32))
|
| 28 |
+
|
| 29 |
+
class LMHost:
|
| 30 |
+
def __init__(self, model, past):
|
| 31 |
+
lm = model.lm.inner if hasattr(model.lm, "inner") else model.lm
|
| 32 |
+
self.c = lm.c
|
| 33 |
+
self.past = past
|
| 34 |
+
self.n_attn = len(layer_kinds(self.c)[1])
|
| 35 |
+
self.emb = [e.weight.detach().float().numpy() for e in lm.multi_embedder.embedders]
|
| 36 |
+
self.spk = lm.speaker_projection
|
| 37 |
+
self.cond = [e.weight.detach().float().numpy() for e in lm.condition_embeddings]
|
| 38 |
+
hd = self.c["head_dim"]
|
| 39 |
+
self.freq = self.c["rope_theta"] ** (-torch.arange(0, hd, 2, dtype=torch.float32) / hd)
|
| 40 |
+
|
| 41 |
+
def row(self, ids, pos, speaker_rows=None, condition_rows=None):
|
| 42 |
+
"""ids [11] int -> the LM input row [1, 1, 1024] float32 (before the graph's RMS norm)."""
|
| 43 |
+
x = self.emb[0][int(ids[0])].copy()
|
| 44 |
+
for cb in range(1, len(self.emb)):
|
| 45 |
+
x = x + self.emb[cb][int(ids[cb])]
|
| 46 |
+
if speaker_rows and pos in speaker_rows:
|
| 47 |
+
w = self.spk
|
| 48 |
+
vec = torch.as_tensor(speaker_rows[pos], dtype=torch.float32).reshape(-1)
|
| 49 |
+
x = F.linear(vec, w.weight.float(), w.bias.float()).detach().numpy()
|
| 50 |
+
if condition_rows and pos in condition_rows:
|
| 51 |
+
table = sorted(condition_rows).index(pos)
|
| 52 |
+
x = self.cond[table][int(condition_rows[pos])].copy()
|
| 53 |
+
return x.reshape(1, 1, -1).astype(np.float32)
|
| 54 |
+
|
| 55 |
+
def rope(self, pos):
|
| 56 |
+
ang = torch.tensor([float(pos)], dtype=torch.float32)[:, None] * self.freq[None, :]
|
| 57 |
+
return (ang.cos().numpy().reshape(1, 1, 1, -1).astype(np.float32),
|
| 58 |
+
ang.sin().numpy().reshape(1, 1, 1, -1).astype(np.float32))
|
| 59 |
+
|
| 60 |
+
def mask(self, pos):
|
| 61 |
+
m = np.full((1, 1, 1, self.past + 1), NEG, np.float32)
|
| 62 |
+
m[..., :pos] = 0.0
|
| 63 |
+
m[..., self.past] = 0.0
|
| 64 |
+
return m
|
| 65 |
+
|
| 66 |
+
def fresh(self):
|
| 67 |
+
"""A new sequence's state: {"pos", "kv" [1, kv, 2A P, hd], "gdn", "conv"}."""
|
| 68 |
+
kv, gdn, conv = empty_state(self.c, self.past)
|
| 69 |
+
return {"pos": 0, "kv": kv, "gdn": gdn, "conv": conv}
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def copy_state(st):
|
| 73 |
+
return {"pos": st["pos"], "kv": st["kv"].copy(), "gdn": st["gdn"].copy(), "conv": st["conv"].copy()}
|
| 74 |
+
|
| 75 |
+
def inputs(self, st, x):
|
| 76 |
+
cos, sin = self.rope(st["pos"])
|
| 77 |
+
return [x, cos, sin, self.mask(st["pos"]), st["kv"], st["gdn"], st["conv"]]
|
| 78 |
+
|
| 79 |
+
def step(self, run, st, x):
|
| 80 |
+
"""run(inputs list) -> outputs list; one row. Returns logits [n_cb, vocab], updates st in place."""
|
| 81 |
+
pos = st["pos"]
|
| 82 |
+
assert pos < self.past, (pos, self.past)
|
| 83 |
+
logits, kv_new, gdn, conv = run(self.inputs(st, x))
|
| 84 |
+
for j in range(kv_new.shape[2]): # kv_new [1, kv, 2A, hd]: k, v of each attention layer along dim 2
|
| 85 |
+
st["kv"][:, :, j * self.past + pos] = kv_new[:, :, j]
|
| 86 |
+
st["gdn"] = np.array(gdn, np.float32, copy=True)
|
| 87 |
+
st["conv"] = np.array(conv, np.float32, copy=True)
|
| 88 |
+
st["pos"] = pos + 1
|
| 89 |
+
return np.asarray(logits).reshape(self.c["n_codebooks"], -1)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# ===================================================================================================== codec
|
| 93 |
+
def codec_tables(cfg, frames, hd=64):
|
| 94 |
+
"""The decoder graph's static inputs: RoPE cos / sin of positions 0 .. 16 T - 1 [1, 1, 16 T, hd / 2] (the
|
| 95 |
+
reference's formula, float32) and the causal sliding-window masks [1, 1, T_s, T_s] of the stages."""
|
| 96 |
+
freq = torch.exp(torch.arange(hd // 2, dtype=torch.float32) * (-math.log(10000.0) * 2 / hd))
|
| 97 |
+
n = frames * 2 ** (len(cfg["stages"]) - 1)
|
| 98 |
+
ph = torch.arange(n, dtype=torch.float32)[:, None] * freq[None, :]
|
| 99 |
+
cos = ph.cos().numpy().reshape(1, 1, n, hd // 2).astype(np.float32)
|
| 100 |
+
sin = ph.sin().numpy().reshape(1, 1, n, hd // 2).astype(np.float32)
|
| 101 |
+
wins = []
|
| 102 |
+
for si, s in enumerate(cfg["stages"]):
|
| 103 |
+
t = frames * 2 ** si
|
| 104 |
+
d = np.arange(t)[:, None] - np.arange(t)[None, :]
|
| 105 |
+
wins.append(np.where((d >= 0) & (d < s["context_frames"]), 0.0, NEG).astype(np.float32).reshape(1, 1, t, t))
|
| 106 |
+
return cos, sin, wins
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def codec_frame_masks(frames, f, n_stages=5):
|
| 110 |
+
out = []
|
| 111 |
+
for si in range(n_stages):
|
| 112 |
+
r = 2 ** si
|
| 113 |
+
m = np.zeros((1, frames * r, 1), np.float32)
|
| 114 |
+
m[:, : f * r] = 1.0
|
| 115 |
+
out.append(m)
|
| 116 |
+
return out
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class CodecHost:
|
| 120 |
+
def __init__(self, model, frames):
|
| 121 |
+
codec = model.codec
|
| 122 |
+
self.c = codec.c
|
| 123 |
+
self.frames = frames
|
| 124 |
+
assert self.c["head_hop"] == 184 and self.c["fir_kernel"] == 127 and self.c["hop"] == 2940
|
| 125 |
+
assert (self.c["resample_orig"], self.c["resample_new"], self.c["resample_width"]) == (736, 735, 17)
|
| 126 |
+
self.books = [q.codebook.detach().float().numpy() for q in codec.quantizers]
|
| 127 |
+
self.mixer = codec.head.mixer.weight.detach().float().numpy() # [1, 2, 127]
|
| 128 |
+
self.kernel = codec.to_external_kernel.detach().float().numpy() # [735, 1, 770]
|
| 129 |
+
self.windows = {n: torch.hann_window(n, periodic=True).float().numpy() for n in self.c["n_ffts"]}
|
| 130 |
+
assert len(self.c["stages"]) == 5
|
| 131 |
+
self.cos, self.sin, self.wins = codec_tables(self.c, frames)
|
| 132 |
+
|
| 133 |
+
def inputs(self, codes):
|
| 134 |
+
"""codes [F, n_cb] int (F <= bucket) -> graph inputs (cv, cos, sin, 5 windows, 5 frame masks)."""
|
| 135 |
+
f = codes.shape[0]
|
| 136 |
+
assert f <= self.frames, (f, self.frames)
|
| 137 |
+
dim = self.books[0].shape[1]
|
| 138 |
+
cv = np.zeros((1, self.frames, dim * len(self.books)), np.float32)
|
| 139 |
+
for i, book in enumerate(self.books):
|
| 140 |
+
cv[0, :f, dim * i:dim * (i + 1)] = book[np.asarray(codes)[:, i]]
|
| 141 |
+
return [cv, self.cos, self.sin] + self.wins + codec_frame_masks(self.frames, f)
|
| 142 |
+
|
| 143 |
+
def split(self, head, f):
|
| 144 |
+
"""The graph's packed head output [1, 16 T, 738 + 2210] -> (out736, out2208) of the F valid frames."""
|
| 145 |
+
h = np.asarray(head, np.float32).reshape(16 * self.frames, -1)[: 16 * f]
|
| 146 |
+
n0 = self.c["n_ffts"][0] + 2
|
| 147 |
+
return h[:, :n0], h[:, n0:]
|
| 148 |
+
|
| 149 |
+
# ---- head outputs -> audio
|
| 150 |
+
def _spec(self, out, n):
|
| 151 |
+
logmag, phase = np.split(out.astype(np.float32), 2, axis=-1) # [frames, n/2 + 1] each
|
| 152 |
+
mag = np.exp(np.minimum(logmag, np.float32(math.log(100.0))))
|
| 153 |
+
return mag, phase
|
| 154 |
+
|
| 155 |
+
def istft_np(self, mag, phase, n, length):
|
| 156 |
+
"""NumPy iSTFT, center=True, periodic Hann, hop 184 (fp32 FFT path: norm="forward" then 1/n in float32)."""
|
| 157 |
+
hop = 184
|
| 158 |
+
spec = np.empty(mag.shape, np.complex64) # [T, bins]
|
| 159 |
+
spec.real = mag * np.cos(phase)
|
| 160 |
+
spec.imag = mag * np.sin(phase)
|
| 161 |
+
fr = np.fft.irfft(spec, n=n, axis=-1, norm="forward")
|
| 162 |
+
assert fr.dtype == np.float32, fr.dtype
|
| 163 |
+
fr = fr * np.float32(1.0 / n)
|
| 164 |
+
w = self.windows[n]
|
| 165 |
+
fr = fr * w[None, :]
|
| 166 |
+
t = fr.shape[0]
|
| 167 |
+
k = n // hop
|
| 168 |
+
seg = np.zeros((t + k - 1, hop), np.float32)
|
| 169 |
+
env = np.zeros((t + k - 1, hop), np.float32)
|
| 170 |
+
w2 = (w * w).reshape(k, hop)
|
| 171 |
+
frs = fr.reshape(t, k, hop)
|
| 172 |
+
for j in range(k):
|
| 173 |
+
seg[j:j + t] += frs[:, j]
|
| 174 |
+
env[j:j + t] += w2[j][None, :]
|
| 175 |
+
y = seg.reshape(-1)
|
| 176 |
+
e = env.reshape(-1)
|
| 177 |
+
y = y / np.where(e > 1e-11, e, np.float32(1.0))
|
| 178 |
+
return y[n // 2: n // 2 + length]
|
| 179 |
+
|
| 180 |
+
def audio_np(self, o736, o2208):
|
| 181 |
+
frames = o736.shape[0]
|
| 182 |
+
length = frames * 184
|
| 183 |
+
br = []
|
| 184 |
+
for out, n in ((o736, 736), (o2208, 2208)):
|
| 185 |
+
mag, ph = self._spec(out, n)
|
| 186 |
+
br.append(self.istft_np(mag, ph, n, length))
|
| 187 |
+
xs = np.stack(br) # [2, length]
|
| 188 |
+
xp = np.pad(xs, ((0, 0), (63, 63)))
|
| 189 |
+
w = self.mixer[0] # [2, 127]
|
| 190 |
+
mix = np.zeros(length, np.float32)
|
| 191 |
+
for c in range(2):
|
| 192 |
+
win = np.lib.stride_tricks.sliding_window_view(xp[c], 127) # [length, 127]
|
| 193 |
+
mix = mix + (win @ w[c]).astype(np.float32)
|
| 194 |
+
xp2 = np.pad(mix, (17, 17 + 736))
|
| 195 |
+
fr = np.lib.stride_tricks.sliding_window_view(xp2, 770)[::736] # [J, 770]
|
| 196 |
+
y = (fr @ self.kernel[:, 0, :].T).astype(np.float32).reshape(-1)
|
| 197 |
+
y = y[: math.ceil(735 * length / 736)]
|
| 198 |
+
return y[: (frames // 16) * 2940]
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class SpeakerHost:
|
| 203 |
+
def __init__(self, model, mm, frames=998):
|
| 204 |
+
enc = model.speaker_encoder
|
| 205 |
+
self.c = enc.c
|
| 206 |
+
self.mm = mm
|
| 207 |
+
self.frames = frames
|
| 208 |
+
# the reference's own fbank tables (hamming window, mel banks), computed once with its code path
|
| 209 |
+
sr = float(self.c["sample_rate"])
|
| 210 |
+
self.size = int(sr * self.c["frame_length_ms"] * 0.001)
|
| 211 |
+
self.shift = int(sr * self.c["frame_shift_ms"] * 0.001)
|
| 212 |
+
self.padded = 2 ** (self.size - 1).bit_length()
|
| 213 |
+
self.window = torch.hamming_window(self.size, periodic=False, alpha=0.54, beta=0.46, dtype=torch.float32).numpy()
|
| 214 |
+
self.banks = self._banks()
|
| 215 |
+
|
| 216 |
+
def _banks(self):
|
| 217 |
+
nb = int(self.c["num_mel_bins"])
|
| 218 |
+
sr = float(self.c["sample_rate"])
|
| 219 |
+
dtype = torch.float32
|
| 220 |
+
padded = self.padded
|
| 221 |
+
fft_bin_width = sr / padded
|
| 222 |
+
mel_low, mel_high = 1127.0 * math.log(1.0 + 20.0 / 700.0), 1127.0 * math.log(1.0 + 0.5 * sr / 700.0)
|
| 223 |
+
delta = (mel_high - mel_low) / (nb + 1)
|
| 224 |
+
bins = torch.arange(nb, dtype=dtype).unsqueeze(1)
|
| 225 |
+
left, center, right = mel_low + bins * delta, mel_low + (bins + 1.0) * delta, mel_low + (bins + 2.0) * delta
|
| 226 |
+
mel = (1127.0 * (1.0 + fft_bin_width * torch.arange(padded / 2, dtype=dtype) / 700.0).log()).unsqueeze(0)
|
| 227 |
+
banks = torch.max(torch.zeros(1, dtype=dtype), torch.min((mel - left) / (center - left), (right - mel) / (right - center)))
|
| 228 |
+
return F.pad(banks, (0, 1), mode="constant", value=0).numpy() # [80, 257]
|
| 229 |
+
|
| 230 |
+
def wav16k(self, wav, sr):
|
| 231 |
+
enc_in = torch.as_tensor(wav, dtype=torch.float32)
|
| 232 |
+
if enc_in.ndim == 1:
|
| 233 |
+
enc_in = enc_in[None]
|
| 234 |
+
if enc_in.shape[0] > 1:
|
| 235 |
+
enc_in = enc_in.mean(dim=0, keepdim=True)
|
| 236 |
+
y = self.mm.sinc_resample(enc_in, int(sr), int(self.c["sample_rate"]))
|
| 237 |
+
return y[..., : int(float(self.c["max_seconds"]) * int(self.c["sample_rate"]))][0].numpy()
|
| 238 |
+
|
| 239 |
+
def fbank_np(self, x16k):
|
| 240 |
+
x = (x16k.astype(np.float32) * np.float32(self.c["waveform_scale"]))
|
| 241 |
+
n = 1 + (len(x) - self.size) // self.shift
|
| 242 |
+
fr = np.lib.stride_tricks.as_strided(x, (n, self.size), (self.shift * 4, 4)).copy()
|
| 243 |
+
fr = fr - fr.mean(axis=1, keepdims=True, dtype=np.float32)
|
| 244 |
+
prev = np.concatenate([fr[:, :1], fr[:, :-1]], axis=1)
|
| 245 |
+
fr = fr - np.float32(0.97) * prev
|
| 246 |
+
fr = fr * self.window[None, :]
|
| 247 |
+
fr = np.pad(fr, ((0, 0), (0, self.padded - self.size)))
|
| 248 |
+
spec = np.fft.rfft(fr, axis=-1, norm="forward") * np.float32(self.padded)
|
| 249 |
+
power = (np.abs(spec).astype(np.float32)) ** 2
|
| 250 |
+
mel = power @ self.banks.T
|
| 251 |
+
return np.log(np.maximum(mel, np.float32(np.finfo(np.float32).eps))).astype(np.float32) # [frames, 80]
|
| 252 |
+
|
| 253 |
+
def inputs(self, fb):
|
| 254 |
+
"""fbank [frames, 80] -> graph inputs (feats [1, 80, T], m1, m2, k1, k2)."""
|
| 255 |
+
f = fb.shape[0]
|
| 256 |
+
assert f <= self.frames, (f, self.frames)
|
| 257 |
+
feats = fb.T - fb.T.mean(axis=-1, keepdims=True, dtype=np.float32)
|
| 258 |
+
x = np.zeros((1, fb.shape[1], self.frames), np.float32)
|
| 259 |
+
x[0, :, :f] = feats
|
| 260 |
+
t2 = (self.frames + 1) // 2
|
| 261 |
+
f2 = (f + 1) // 2
|
| 262 |
+
m1 = np.zeros((1, 1, 1, self.frames), np.float32)
|
| 263 |
+
m1[..., :f] = 1.0
|
| 264 |
+
m2 = np.zeros((1, 1, 1, t2), np.float32)
|
| 265 |
+
m2[..., :f2] = 1.0
|
| 266 |
+
k1 = np.where(m1 > 0, 0.0, NEG).astype(np.float32)
|
| 267 |
+
k2 = np.where(m2 > 0, 0.0, NEG).astype(np.float32)
|
| 268 |
+
return [x, m1, m2, k1, k2]
|
desktop/requirements.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CPython 3.12.13, macOS 27.0, arm64. https://www.python.org/downloads/
|
| 2 |
+
# Measured installed versions, including the active macOS distribution dependencies.
|
| 3 |
+
ai-edge-litert==2.3.0 # https://pypi.org/project/ai-edge-litert/2.3.0/
|
| 4 |
+
annotated-doc==0.0.5 # https://pypi.org/project/annotated-doc/0.0.5/
|
| 5 |
+
anyio==4.14.2 # https://pypi.org/project/anyio/4.14.2/
|
| 6 |
+
backports-strenum==1.2.8 # https://pypi.org/project/backports-strenum/1.2.8/
|
| 7 |
+
click==8.5.1 # https://pypi.org/project/click/8.5.1/
|
| 8 |
+
filelock==4.2.9 # https://pypi.org/project/filelock/4.2.9/
|
| 9 |
+
flatbuffers==25.12.19 # https://pypi.org/project/flatbuffers/25.12.19/
|
| 10 |
+
fsspec==2026.9.0 # https://pypi.org/project/fsspec/2026.9.0/
|
| 11 |
+
h11==0.16.0 # https://pypi.org/project/h11/0.16.0/
|
| 12 |
+
hf-xet==1.8.0 # https://pypi.org/project/hf-xet/1.8.0/
|
| 13 |
+
httpcore2==2.16.0 # https://pypi.org/project/httpcore2/2.16.0/
|
| 14 |
+
httpx2==2.16.0 # https://pypi.org/project/httpx2/2.16.0/
|
| 15 |
+
huggingface-hub==2.4.0 # https://pypi.org/project/huggingface-hub/2.4.0/
|
| 16 |
+
idna==3.20 # https://pypi.org/project/idna/3.20/
|
| 17 |
+
jinja2==3.1.6 # https://pypi.org/project/jinja2/3.1.6/
|
| 18 |
+
markdown-it-py==4.2.0 # https://pypi.org/project/markdown-it-py/4.2.0/
|
| 19 |
+
markupsafe==3.0.4 # https://pypi.org/project/markupsafe/3.0.4/
|
| 20 |
+
mdurl==0.1.2 # https://pypi.org/project/mdurl/0.1.2/
|
| 21 |
+
ml-dtypes==0.6.0 # https://pypi.org/project/ml-dtypes/0.6.0/
|
| 22 |
+
mpmath==1.3.0 # https://pypi.org/project/mpmath/1.3.0/
|
| 23 |
+
networkx==3.7 # https://pypi.org/project/networkx/3.7/
|
| 24 |
+
numpy==2.5.4 # https://pypi.org/project/numpy/2.5.4/
|
| 25 |
+
packaging==26.3 # https://pypi.org/project/packaging/26.3/
|
| 26 |
+
protobuf==7.36.2 # https://pypi.org/project/protobuf/7.36.2/
|
| 27 |
+
pygments==2.21.0 # https://pypi.org/project/pygments/2.21.0/
|
| 28 |
+
pyyaml==6.0.3 # https://pypi.org/project/pyyaml/6.0.3/
|
| 29 |
+
regex==2026.11.9 # https://pypi.org/project/regex/2026.11.9/
|
| 30 |
+
rich==15.0.0 # https://pypi.org/project/rich/15.0.0/
|
| 31 |
+
safetensors==0.8.0 # https://pypi.org/project/safetensors/0.8.0/
|
| 32 |
+
scipy==1.18.1 # https://pypi.org/project/scipy/1.18.1/
|
| 33 |
+
setuptools==84.2.1 # https://pypi.org/project/setuptools/84.2.1/
|
| 34 |
+
shellingham==1.5.4 # https://pypi.org/project/shellingham/1.5.4/
|
| 35 |
+
sympy==1.14.0 # https://pypi.org/project/sympy/1.14.0/
|
| 36 |
+
tokenizers==0.23.3 # https://pypi.org/project/tokenizers/0.23.3/
|
| 37 |
+
torch==2.14.1 # https://pypi.org/project/torch/2.14.1/
|
| 38 |
+
tqdm==4.70.1 # https://pypi.org/project/tqdm/4.70.1/
|
| 39 |
+
transformers==5.22.2 # https://pypi.org/project/transformers/5.22.2/
|
| 40 |
+
truststore==0.10.5 # https://pypi.org/project/truststore/0.10.5/
|
| 41 |
+
typer==0.28.0 # https://pypi.org/project/typer/0.28.0/
|
| 42 |
+
typing-extensions==4.12.2 # https://pypi.org/project/typing-extensions/4.12.2/
|
| 43 |
+
zyphra-textnorm==0.3.1 # https://pypi.org/project/zyphra-textnorm/0.3.1/
|
desktop/speak.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Synthesize one English request using three fp32 LiteRT graphs and four Mac CPU threads."""
|
| 2 |
+
import argparse
|
| 3 |
+
import contextlib
|
| 4 |
+
import json
|
| 5 |
+
import math
|
| 6 |
+
import mmap
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import sys
|
| 10 |
+
import tempfile
|
| 11 |
+
|
| 12 |
+
os.environ["OMP_NUM_THREADS"] = "4"
|
| 13 |
+
os.environ["HF_HUB_OFFLINE"] = "1"
|
| 14 |
+
os.environ["HF_HUB_DISABLE_XET"] = "1"
|
| 15 |
+
os.environ.setdefault("HF_HOME", str(Path.cwd() / ".zonos-cache" / "hf"))
|
| 16 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 17 |
+
|
| 18 |
+
import numpy as np
|
| 19 |
+
import torch
|
| 20 |
+
from ai_edge_litert import compiled_model as cm, schema_py_generated as schema
|
| 21 |
+
from scipy.io import wavfile
|
| 22 |
+
from transformers import AutoModel
|
| 23 |
+
from host import CodecHost, LMHost, SpeakerHost
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def graph_layout(path):
|
| 27 |
+
"""Read signature names and shapes, leaving external weight buffers mapped."""
|
| 28 |
+
with path.open("rb") as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as data:
|
| 29 |
+
model = schema.Model.GetRootAsModel(data, 0)
|
| 30 |
+
sig = model.SignatureDefs(0)
|
| 31 |
+
sg = model.Subgraphs(sig.SubgraphIndex())
|
| 32 |
+
layout = {}
|
| 33 |
+
for role in ("Inputs", "Outputs"):
|
| 34 |
+
items = {}
|
| 35 |
+
for i in range(getattr(sig, role + "Length")()):
|
| 36 |
+
mapping = getattr(sig, role)(i)
|
| 37 |
+
tensor = sg.Tensors(mapping.TensorIndex())
|
| 38 |
+
if tensor.Type() != schema.TensorType.FLOAT32:
|
| 39 |
+
raise ValueError(f"{path.name}: graph signature inputs and outputs must use float32")
|
| 40 |
+
items[mapping.Name().decode()] = tuple(map(int, tensor.ShapeAsNumpy()))
|
| 41 |
+
layout[role] = items
|
| 42 |
+
return layout
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class CpuGraph:
|
| 46 |
+
def __init__(self, path, environment, resources):
|
| 47 |
+
layout = graph_layout(path)
|
| 48 |
+
options = cm.Options(hardware_accelerators=cm.HardwareAccelerator.CPU,
|
| 49 |
+
cpu_options=cm.CpuOptions(num_threads=4))
|
| 50 |
+
self.model = cm.CompiledModel.from_file(str(path), options=options, environment=environment)
|
| 51 |
+
resources.callback(self.model.close)
|
| 52 |
+
signature = self.model.get_signature_by_index(0)
|
| 53 |
+
self.inputs = self.model.create_input_buffers(0)
|
| 54 |
+
self.outputs = self.model.create_output_buffers(0)
|
| 55 |
+
for buffer in self.inputs + self.outputs:
|
| 56 |
+
resources.callback(buffer.destroy)
|
| 57 |
+
self.input_layout = [(int(n.removeprefix("args_")), layout["Inputs"][n]) for n in signature["inputs"]]
|
| 58 |
+
self.output_layout = [(int(n.removeprefix("output_")), layout["Outputs"][n]) for n in signature["outputs"]]
|
| 59 |
+
self.calls = 0
|
| 60 |
+
|
| 61 |
+
def run(self, args):
|
| 62 |
+
for buffer, (index, shape) in zip(self.inputs, self.input_layout, strict=True):
|
| 63 |
+
x = np.ascontiguousarray(args[index], dtype=np.float32)
|
| 64 |
+
if x.shape != shape:
|
| 65 |
+
raise ValueError(f"args_{index} has shape {x.shape}, expected {shape}")
|
| 66 |
+
buffer.write(x)
|
| 67 |
+
self.model.run_by_index(0, self.inputs, self.outputs)
|
| 68 |
+
self.calls += 1
|
| 69 |
+
result = [None] * len(self.outputs)
|
| 70 |
+
for buffer, (index, shape) in zip(self.outputs, self.output_layout, strict=True):
|
| 71 |
+
result[index] = buffer.read(math.prod(shape), np.float32).reshape(shape)
|
| 72 |
+
return result
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class StepLM(torch.nn.Module):
|
| 76 |
+
def __init__(self, model, graph):
|
| 77 |
+
super().__init__()
|
| 78 |
+
self.multi_output = model.lm.multi_output
|
| 79 |
+
self.host = LMHost(model, 768)
|
| 80 |
+
self.graph = graph
|
| 81 |
+
|
| 82 |
+
def forward(self, ids, cache, *, speaker_rows=None, condition_rows=None, logits_to_keep=0):
|
| 83 |
+
if not hasattr(cache, "_lrt"):
|
| 84 |
+
cache._lrt = self.host.fresh()
|
| 85 |
+
state = cache._lrt
|
| 86 |
+
if state["pos"] != cache.position:
|
| 87 |
+
raise ValueError("inconsistent LM cache position")
|
| 88 |
+
if state["pos"] + len(ids) > 768:
|
| 89 |
+
raise ValueError("CapacityReached: LM step position must be below 768")
|
| 90 |
+
results = []
|
| 91 |
+
for r, row in enumerate(ids.cpu().numpy()):
|
| 92 |
+
x = self.host.row(row, state["pos"], speaker_rows, condition_rows)
|
| 93 |
+
logits = self.host.step(self.graph.run, state, x)
|
| 94 |
+
if logits_to_keep <= 0 or r >= len(ids) - logits_to_keep:
|
| 95 |
+
results.append(logits)
|
| 96 |
+
cache.position = state["pos"]
|
| 97 |
+
return torch.from_numpy(np.stack(results))
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class KitDraws(torch.overrides.TorchFunctionMode):
|
| 101 |
+
"""Use the kit variates for the author's final multinomial operation only."""
|
| 102 |
+
def __init__(self, stream):
|
| 103 |
+
super().__init__()
|
| 104 |
+
self.stream = stream
|
| 105 |
+
self.rows = 0
|
| 106 |
+
|
| 107 |
+
def __torch_function__(self, func, types, args=(), kwargs=None):
|
| 108 |
+
kwargs = kwargs or {}
|
| 109 |
+
if func is not torch.multinomial:
|
| 110 |
+
return func(*args, **kwargs)
|
| 111 |
+
probs, = args
|
| 112 |
+
if probs.shape != (10, 4098) or kwargs.get("num_samples") != 1:
|
| 113 |
+
raise ValueError("unexpected multinomial call from the model")
|
| 114 |
+
n = probs.numel()
|
| 115 |
+
noise = np.fromfile(self.stream, dtype="<f4", count=n)
|
| 116 |
+
if noise.size != n or not np.isfinite(noise).all() or np.any(noise <= 0):
|
| 117 |
+
raise ValueError(f"missing or invalid kit draws at sampled row {self.rows}")
|
| 118 |
+
self.rows += 1
|
| 119 |
+
return (probs / torch.from_numpy(noise).view_as(probs)).argmax(1, keepdim=True)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def clip_embedding(path, model, graph):
|
| 123 |
+
rate, pcm = wavfile.read(path)
|
| 124 |
+
if pcm.dtype == np.uint8:
|
| 125 |
+
wave = (pcm.astype(np.float32) - 128) / 128
|
| 126 |
+
elif pcm.dtype.kind == "i":
|
| 127 |
+
wave = pcm.astype(np.float32) / float(1 << (pcm.dtype.itemsize * 8 - 1))
|
| 128 |
+
elif pcm.dtype.kind == "f":
|
| 129 |
+
wave = pcm.astype(np.float32)
|
| 130 |
+
else:
|
| 131 |
+
raise ValueError(f"unsupported WAV encoding: {pcm.dtype}")
|
| 132 |
+
front = SpeakerHost(model, sys.modules[type(model).__module__])
|
| 133 |
+
# A 10 s bucket contains 998 complete 25 ms windows at a 10 ms hop.
|
| 134 |
+
mono = front.wav16k(wave.T.copy(), rate)[:160000]
|
| 135 |
+
if len(mono) < front.size or not np.isfinite(mono).all():
|
| 136 |
+
raise ValueError("speaker WAV requires at least one finite 25 ms frame")
|
| 137 |
+
fb = front.fbank_np(mono)[:998]
|
| 138 |
+
embedding, = graph.run(front.inputs(fb))
|
| 139 |
+
return torch.from_numpy(embedding.reshape(-1))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def main():
|
| 143 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 144 |
+
parser.add_argument("sentence")
|
| 145 |
+
parser.add_argument("--model", required=True, type=Path, help="local Zyphra/ZONOS3-Mini-hf snapshot at e39d30df")
|
| 146 |
+
parser.add_argument("--graphs", required=True, type=Path, help="directory containing the fp32 language model, decoder, and speaker encoder graphs")
|
| 147 |
+
parser.add_argument("--out", required=True, type=Path, help="new output folder")
|
| 148 |
+
parser.add_argument("--draws", type=Path, help="optional kit takes/<tag>/draws.f32")
|
| 149 |
+
parser.add_argument("--speaker-wav", type=Path, help="condition on a recording instead of Savannah reference codes")
|
| 150 |
+
parser.add_argument("--seed", type=int, default=1000)
|
| 151 |
+
args = parser.parse_args()
|
| 152 |
+
if not args.sentence.strip() or args.out.exists():
|
| 153 |
+
parser.error("supply a nonempty sentence and a new output directory")
|
| 154 |
+
torch.set_num_threads(4)
|
| 155 |
+
model = AutoModel.from_pretrained(str(args.model.resolve()), trust_remote_code=True,
|
| 156 |
+
local_files_only=True, dtype=torch.float32).to("cpu").eval()
|
| 157 |
+
environment = cm.Environment.create(options=cm.EnvironmentOptions(runtime_path=str(Path(cm.__file__).parent)))
|
| 158 |
+
files = {"lm":"lm_step_p768.tflite", "codec":"codec_dec_f150.tflite", "speaker":"spk_enc_t998.tflite"}
|
| 159 |
+
with contextlib.ExitStack() as resources, torch.no_grad():
|
| 160 |
+
graphs = {key: CpuGraph(args.graphs / name, environment, resources) for key, name in files.items()}
|
| 161 |
+
if args.speaker_wav:
|
| 162 |
+
voice = {"speaker_embedding": clip_embedding(args.speaker_wav, model, graphs["speaker"]),
|
| 163 |
+
"speaker_mode": "embedding"}
|
| 164 |
+
else:
|
| 165 |
+
voice = {"voice":"Savannah"}
|
| 166 |
+
model.lm = StepLM(model, graphs["lm"])
|
| 167 |
+
codec = CodecHost(model, 150)
|
| 168 |
+
|
| 169 |
+
def decode(codes):
|
| 170 |
+
frames = len(codes)
|
| 171 |
+
if frames > codec.frames:
|
| 172 |
+
raise ValueError(f"BucketExceeded: {frames} frames exceed decoder bucket 150")
|
| 173 |
+
head, = graphs["codec"].run(codec.inputs(codes.cpu().numpy()))
|
| 174 |
+
audio = codec.audio_np(*codec.split(head, frames))
|
| 175 |
+
return torch.from_numpy(np.ascontiguousarray(audio, dtype=np.float32))
|
| 176 |
+
|
| 177 |
+
model.decode_codes = decode
|
| 178 |
+
draws = KitDraws(resources.enter_context(args.draws.open("rb"))) if args.draws else None
|
| 179 |
+
with draws if draws is not None else contextlib.nullcontext():
|
| 180 |
+
take = model.generate(args.sentence, language="en_us", seed=args.seed, **voice)
|
| 181 |
+
wave = take.waveform.detach().cpu().numpy().reshape(-1)
|
| 182 |
+
if not wave.size or not np.isfinite(wave).all():
|
| 183 |
+
raise ValueError("empty or nonfinite output")
|
| 184 |
+
codes = take.codes.cpu().numpy().astype("<i4")
|
| 185 |
+
record = {"text": args.sentence, "language":"en_us", "seed":args.seed,
|
| 186 |
+
"voice":"recording" if args.speaker_wav else "Savannah", "threads":torch.get_num_threads(),
|
| 187 |
+
"sampling":"kit" if draws is not None else "seeded PyTorch",
|
| 188 |
+
"kit_draw_rows":draws.rows if draws is not None else 0,
|
| 189 |
+
"graph_calls":{key:g.calls for key,g in graphs.items()}, "frames":len(codes),
|
| 190 |
+
"samples":len(wave),"sample_rate_hz":take.sampling_rate}
|
| 191 |
+
|
| 192 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 193 |
+
with tempfile.TemporaryDirectory(dir=args.out.parent) as tmp:
|
| 194 |
+
stage = Path(tmp) / "audio"
|
| 195 |
+
stage.mkdir()
|
| 196 |
+
np.save(stage / "codes.npy", codes)
|
| 197 |
+
np.save(stage / "waveform.npy", wave)
|
| 198 |
+
wavfile.write(stage / "speech.wav", take.sampling_rate, (np.clip(wave, -1, 1)*32767).round().astype("<i2"))
|
| 199 |
+
(stage / "run.json").write_text(json.dumps(record, indent=2)+"\n")
|
| 200 |
+
stage.rename(args.out)
|
| 201 |
+
print(json.dumps(record))
|
| 202 |
+
|
| 203 |
+
if __name__ == "__main__":
|
| 204 |
+
main()
|
graphs/codec_dec_f150.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eb9a108f7c466f67045f7c547c73a1d14b0a8840c4ed0d415854eb0927abb9ca
|
| 3 |
+
size 572522276
|
graphs/lm_step_p768.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:068e500d7daedb2d3b5cf2a1348db4c3cc4ff392d80edb236c258a9ab9c13753
|
| 3 |
+
size 3342543296
|
graphs/spk_enc_t998.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3672c911c17dcc18052a1060c1be9d3d96d620a52fd97f33756644a91299f0b4
|
| 3 |
+
size 45122316
|
host/audio.cpp
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "core.hpp"
|
| 2 |
+
#define POCKETFFT_NO_MULTITHREADING
|
| 3 |
+
#include "pocketfft.h"
|
| 4 |
+
|
| 5 |
+
static Floats branch_audio(const Floats& head, int frames, int fft, int offset, const Floats& window) {
|
| 6 |
+
const int hop = 184, rows = frames * 16, bins = fft/2 + 1;
|
| 7 |
+
Floats sum((rows-1)*hop + fft), env(sum.size()), block(fft);
|
| 8 |
+
std::vector<std::complex<float>> spectrum(bins);
|
| 9 |
+
// Reverse window blocks to match istft_np's increasing block-offset sum.
|
| 10 |
+
for (int t=rows-1; t>=0; --t) {
|
| 11 |
+
auto src = head.data() + t*2948 + offset;
|
| 12 |
+
for (int i=0; i<bins; ++i) {
|
| 13 |
+
float mag = std::exp(std::min(src[i], std::log(100.f)));
|
| 14 |
+
spectrum[i] = {mag*std::cos(src[bins+i]), mag*std::sin(src[bins+i])};
|
| 15 |
+
}
|
| 16 |
+
pocketfft::c2r<float>({size_t(fft)}, {sizeof(std::complex<float>)}, {sizeof(float)}, 0,
|
| 17 |
+
false, spectrum.data(), block.data(), 1.f);
|
| 18 |
+
for (int i=0; i<fft; ++i) {
|
| 19 |
+
sum[t*hop+i] += (block[i]*(1.f/fft))*window[i];
|
| 20 |
+
env[t*hop+i] += window[i]*window[i];
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
Floats audio(rows*hop);
|
| 24 |
+
for (size_t i=0; i<audio.size(); ++i) {
|
| 25 |
+
size_t j = i + fft/2;
|
| 26 |
+
audio[i] = sum[j] / (env[j] > 1e-11f ? env[j] : 1.f);
|
| 27 |
+
}
|
| 28 |
+
return audio;
|
| 29 |
+
}
|
| 30 |
+
Floats decode_audio(const Floats& head, int frames, const fs::path& shared) {
|
| 31 |
+
auto a = branch_audio(head, frames, 736, 0, read_file<float>(shared/"hann736.f32",736));
|
| 32 |
+
auto b = branch_audio(head, frames, 2208, 738, read_file<float>(shared/"hann2208.f32",2208));
|
| 33 |
+
auto mixer = read_file<float>(shared/"mixer.f32",254);
|
| 34 |
+
auto kernel = read_file<float>(shared/"resample.f32",735*770);
|
| 35 |
+
Floats mix(17 + a.size() + 17 + 736);
|
| 36 |
+
for (int ch=0; ch<2; ++ch) {
|
| 37 |
+
Floats padded(a.size()+126);
|
| 38 |
+
auto& x = ch ? b : a;
|
| 39 |
+
std::copy(x.begin(), x.end(), padded.begin()+63);
|
| 40 |
+
for (size_t j=0; j<x.size(); ++j) {
|
| 41 |
+
float v=0;
|
| 42 |
+
for (int k=0; k<127; ++k) v += padded[j+k]*mixer[ch*127+k];
|
| 43 |
+
mix[17+j] += v;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
Floats wave(frames*2940);
|
| 47 |
+
const float gain=std::pow(10., -3./20.), knee=std::pow(10., -1./20.);
|
| 48 |
+
for (size_t i=0; i<wave.size(); ++i) {
|
| 49 |
+
const float* segment=mix.data()+(i/735)*736;
|
| 50 |
+
const float* coeff=kernel.data()+(i%735)*770;
|
| 51 |
+
float sample=0;
|
| 52 |
+
for (int k=0; k<770; ++k) sample += segment[k]*coeff[k];
|
| 53 |
+
sample *= gain;
|
| 54 |
+
if (std::abs(sample)>knee)
|
| 55 |
+
sample=std::copysign(knee+(1-knee)*std::tanh((std::abs(sample)-knee)/(1-knee)),sample);
|
| 56 |
+
require(std::isfinite(sample), "nonfinite waveform");
|
| 57 |
+
wave[i]=sample;
|
| 58 |
+
}
|
| 59 |
+
return wave;
|
| 60 |
+
}
|
| 61 |
+
void save_audio(const fs::path& dest, const Floats& wave) {
|
| 62 |
+
write_file(dest/"waveform.f32",wave);
|
| 63 |
+
std::ofstream f(dest/"waveform.wav",std::ios::binary);
|
| 64 |
+
auto u16=[&](uint16_t v){f.write(reinterpret_cast<const char*>(&v),2);};
|
| 65 |
+
auto u32=[&](uint32_t v){f.write(reinterpret_cast<const char*>(&v),4);};
|
| 66 |
+
f.write("RIFF",4); u32(36+wave.size()*2); f.write("WAVEfmt ",8); u32(16);
|
| 67 |
+
u16(1); u16(1); u32(44100); u32(88200); u16(2); u16(16);
|
| 68 |
+
f.write("data",4); u32(wave.size()*2);
|
| 69 |
+
for (float x:wave) u16(static_cast<int16_t>(std::nearbyint(std::clamp(x,-1.f,1.f)*32767.f)));
|
| 70 |
+
f.close();
|
| 71 |
+
require(bool(f),"write waveform.wav");
|
| 72 |
+
}
|
host/core.hpp
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <algorithm>
|
| 3 |
+
#include <array>
|
| 4 |
+
#include <chrono>
|
| 5 |
+
#include <cmath>
|
| 6 |
+
#include <complex>
|
| 7 |
+
#include <cstdint>
|
| 8 |
+
#include <cstring>
|
| 9 |
+
#include <filesystem>
|
| 10 |
+
#include <fstream>
|
| 11 |
+
#include <iostream>
|
| 12 |
+
#include <memory>
|
| 13 |
+
#include <numeric>
|
| 14 |
+
#include <stdexcept>
|
| 15 |
+
#include <string>
|
| 16 |
+
#include <vector>
|
| 17 |
+
|
| 18 |
+
namespace fs = std::filesystem;
|
| 19 |
+
using Floats = std::vector<float>;
|
| 20 |
+
using Row = std::array<int32_t, 10>;
|
| 21 |
+
struct View { const float* data; size_t size; };
|
| 22 |
+
inline View view(const Floats& v) { return {v.data(), v.size()}; }
|
| 23 |
+
inline void require(bool ok, const std::string& reason) {
|
| 24 |
+
if (!ok) throw std::runtime_error(reason);
|
| 25 |
+
}
|
| 26 |
+
template<class T> std::vector<T> read_file(const fs::path& p, size_t expected = 0) {
|
| 27 |
+
auto bytes = fs::file_size(p);
|
| 28 |
+
require(bytes % sizeof(T) == 0 && (!expected || bytes == expected * sizeof(T)), "bad size: " + p.string());
|
| 29 |
+
std::vector<T> data(bytes / sizeof(T));
|
| 30 |
+
std::ifstream f(p, std::ios::binary);
|
| 31 |
+
require(bool(f.read(reinterpret_cast<char*>(data.data()), bytes)), "read: " + p.string());
|
| 32 |
+
return data;
|
| 33 |
+
}
|
| 34 |
+
template<class T> void write_file(const fs::path& p, const std::vector<T>& data) {
|
| 35 |
+
std::ofstream f(p, std::ios::binary);
|
| 36 |
+
f.write(reinterpret_cast<const char*>(data.data()), data.size()*sizeof(T));
|
| 37 |
+
f.close();
|
| 38 |
+
require(bool(f), "write: " + p.string());
|
| 39 |
+
}
|
| 40 |
+
using Outputs = std::vector<Floats*>;
|
| 41 |
+
class Graph {
|
| 42 |
+
public:
|
| 43 |
+
virtual void run(const std::vector<View>& inputs, const Outputs& outputs) = 0;
|
| 44 |
+
virtual ~Graph() = default;
|
| 45 |
+
};
|
| 46 |
+
std::unique_ptr<Graph> open_graph(const fs::path& model, bool decoder);
|
| 47 |
+
Floats decode_audio(const Floats& head, int frames, const fs::path& shared);
|
| 48 |
+
void save_audio(const fs::path& dest, const Floats& wav);
|
host/graphs.cpp
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "core.hpp"
|
| 2 |
+
// Opaque ABI subset of the LiteRT 2.3 TensorFlow Lite C signature-runner API.
|
| 3 |
+
extern "C" {
|
| 4 |
+
struct TfLiteModel; struct TfLiteInterpreterOptions; struct TfLiteInterpreter;
|
| 5 |
+
struct TfLiteSignatureRunner; struct TfLiteTensor;
|
| 6 |
+
TfLiteModel* TfLiteModelCreateFromFile(const char*);
|
| 7 |
+
void TfLiteModelDelete(TfLiteModel*);
|
| 8 |
+
TfLiteInterpreterOptions* TfLiteInterpreterOptionsCreate();
|
| 9 |
+
void TfLiteInterpreterOptionsSetNumThreads(TfLiteInterpreterOptions*, int32_t);
|
| 10 |
+
void TfLiteInterpreterOptionsDelete(TfLiteInterpreterOptions*);
|
| 11 |
+
TfLiteInterpreter* TfLiteInterpreterCreate(const TfLiteModel*, const TfLiteInterpreterOptions*);
|
| 12 |
+
void TfLiteInterpreterDelete(TfLiteInterpreter*);
|
| 13 |
+
TfLiteSignatureRunner* TfLiteInterpreterGetSignatureRunner(const TfLiteInterpreter*, const char*);
|
| 14 |
+
void TfLiteSignatureRunnerDelete(TfLiteSignatureRunner*);
|
| 15 |
+
int TfLiteSignatureRunnerAllocateTensors(TfLiteSignatureRunner*);
|
| 16 |
+
TfLiteTensor* TfLiteSignatureRunnerGetInputTensor(TfLiteSignatureRunner*, const char*);
|
| 17 |
+
const TfLiteTensor* TfLiteSignatureRunnerGetOutputTensor(const TfLiteSignatureRunner*, const char*);
|
| 18 |
+
int TfLiteSignatureRunnerInvoke(TfLiteSignatureRunner*);
|
| 19 |
+
int TfLiteTensorCopyFromBuffer(TfLiteTensor*, const void*, size_t);
|
| 20 |
+
int TfLiteTensorCopyToBuffer(const TfLiteTensor*, void*, size_t);
|
| 21 |
+
}
|
| 22 |
+
template<class T, void(*Delete)(T*)> using Handle = std::unique_ptr<T, decltype(Delete)>;
|
| 23 |
+
class CpuGraph final : public Graph {
|
| 24 |
+
Handle<TfLiteModel, TfLiteModelDelete> model{nullptr, TfLiteModelDelete};
|
| 25 |
+
Handle<TfLiteInterpreter, TfLiteInterpreterDelete> interpreter{nullptr, TfLiteInterpreterDelete};
|
| 26 |
+
Handle<TfLiteSignatureRunner, TfLiteSignatureRunnerDelete> signature{nullptr, TfLiteSignatureRunnerDelete};
|
| 27 |
+
public:
|
| 28 |
+
explicit CpuGraph(const fs::path& path) {
|
| 29 |
+
model.reset(TfLiteModelCreateFromFile(path.c_str()));
|
| 30 |
+
require(bool(model), "load " + path.string());
|
| 31 |
+
Handle<TfLiteInterpreterOptions, TfLiteInterpreterOptionsDelete> opts(
|
| 32 |
+
TfLiteInterpreterOptionsCreate(), TfLiteInterpreterOptionsDelete);
|
| 33 |
+
require(bool(opts), "create CPU options");
|
| 34 |
+
TfLiteInterpreterOptionsSetNumThreads(opts.get(), 4);
|
| 35 |
+
interpreter.reset(TfLiteInterpreterCreate(model.get(), opts.get()));
|
| 36 |
+
require(bool(interpreter), "create CPU interpreter");
|
| 37 |
+
signature.reset(TfLiteInterpreterGetSignatureRunner(interpreter.get(), "serving_default"));
|
| 38 |
+
require(signature && TfLiteSignatureRunnerAllocateTensors(signature.get()) == 0, "allocate signature");
|
| 39 |
+
}
|
| 40 |
+
void run(const std::vector<View>& inputs, const Outputs& outputs) override {
|
| 41 |
+
for (size_t i=0; i<inputs.size(); ++i) {
|
| 42 |
+
auto name = "args_" + std::to_string(i);
|
| 43 |
+
auto t = TfLiteSignatureRunnerGetInputTensor(signature.get(), name.c_str());
|
| 44 |
+
require(t && TfLiteTensorCopyFromBuffer(t, inputs[i].data, inputs[i].size*sizeof(float)) == 0, name);
|
| 45 |
+
}
|
| 46 |
+
require(TfLiteSignatureRunnerInvoke(signature.get()) == 0, "invoke signature");
|
| 47 |
+
for (size_t i=0; i<outputs.size(); ++i) {
|
| 48 |
+
auto name = "output_" + std::to_string(i);
|
| 49 |
+
auto t = TfLiteSignatureRunnerGetOutputTensor(signature.get(), name.c_str());
|
| 50 |
+
auto& v = *outputs[i];
|
| 51 |
+
require(t && TfLiteTensorCopyToBuffer(t, v.data(), v.size()*sizeof(float)) == 0, name);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
};
|
| 55 |
+
std::unique_ptr<Graph> open_graph(const fs::path& path, bool) {
|
| 56 |
+
return std::make_unique<CpuGraph>(path);
|
| 57 |
+
}
|
host/main.cpp
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "core.hpp"
|
| 2 |
+
|
| 3 |
+
constexpr int P=768, C=10, V=4098, STOP=4096, PAD=4097, H=1024;
|
| 4 |
+
using Rows=std::vector<Row>;
|
| 5 |
+
static_assert(sizeof(Row)==10*sizeof(int32_t));
|
| 6 |
+
|
| 7 |
+
class Generation {
|
| 8 |
+
const fs::path shared;
|
| 9 |
+
Floats embeds, text_pad, cosines, sines;
|
| 10 |
+
Floats kv=Floats(4*3072*32), gdn=Floats(9*4*128*128), conv=Floats(9*3*1536);
|
| 11 |
+
Floats new_kv=Floats(4*4*32), mask=Floats(P+1);
|
| 12 |
+
std::unique_ptr<Graph> graph;
|
| 13 |
+
std::ifstream replay_logits, replay_x;
|
| 14 |
+
int pos=0;
|
| 15 |
+
public:
|
| 16 |
+
Floats logits=Floats(C*V);
|
| 17 |
+
Generation(const fs::path& s, const fs::path& lm, const fs::path& replay):shared(s) {
|
| 18 |
+
embeds=read_file<float>(s/"embeddings.f32",C*V*H);
|
| 19 |
+
text_pad=read_file<float>(s/"text_pad.f32",H);
|
| 20 |
+
if (replay.empty()) {
|
| 21 |
+
graph=open_graph(lm,false);
|
| 22 |
+
cosines=read_file<float>(s/"lm_cos.f32",P*16);
|
| 23 |
+
sines=read_file<float>(s/"lm_sin.f32",P*16);
|
| 24 |
+
} else {
|
| 25 |
+
replay_logits.open(replay/"logits.f32",std::ios::binary);
|
| 26 |
+
replay_x.open(replay/"rows.f32",std::ios::binary);
|
| 27 |
+
require(replay_logits && replay_x,"open replay");
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
void step(const float* x) {
|
| 31 |
+
require(pos<P,"CapacityReached");
|
| 32 |
+
if (graph) {
|
| 33 |
+
std::fill(mask.begin(),mask.end(),-30000.f);
|
| 34 |
+
std::fill_n(mask.begin(),pos,0.f);
|
| 35 |
+
mask[P]=0.f;
|
| 36 |
+
graph->run({{x,H},{cosines.data()+pos*16,16},{sines.data()+pos*16,16},
|
| 37 |
+
view(mask),view(kv),view(gdn),view(conv)}, {&logits,&new_kv,&gdn,&conv});
|
| 38 |
+
for (int h=0; h<4; ++h)
|
| 39 |
+
for (int j=0; j<4; ++j)
|
| 40 |
+
std::copy_n(new_kv.data()+(h*4+j)*32,32,kv.data()+((h*4+j)*P+pos)*32);
|
| 41 |
+
} else {
|
| 42 |
+
float check[H];
|
| 43 |
+
require(bool(replay_x.read(reinterpret_cast<char*>(check),sizeof(check))),"missing replay row");
|
| 44 |
+
require(std::memcmp(check,x,sizeof(check))==0,"replay input row mismatch at "+std::to_string(pos));
|
| 45 |
+
require(bool(replay_logits.read(reinterpret_cast<char*>(logits.data()),logits.size()*4)), "missing logits");
|
| 46 |
+
}
|
| 47 |
+
++pos;
|
| 48 |
+
}
|
| 49 |
+
void feed(const Row& row) {
|
| 50 |
+
Floats x(H);
|
| 51 |
+
for (int cb=0; cb<C; ++cb) {
|
| 52 |
+
auto e=embeds.data()+(cb*V+row[cb])*H;
|
| 53 |
+
for (int h=0; h<H; ++h) x[h] += e[h];
|
| 54 |
+
}
|
| 55 |
+
for (int h=0; h<H; ++h) x[h]+=text_pad[h];
|
| 56 |
+
step(x.data());
|
| 57 |
+
}
|
| 58 |
+
void finish() {
|
| 59 |
+
if (!graph)
|
| 60 |
+
require(replay_logits.peek()==EOF && replay_x.peek()==EOF,"unused captured LM calls");
|
| 61 |
+
}
|
| 62 |
+
};
|
| 63 |
+
static Row sample(const Floats& logits, const Rows& generated, const Floats& draws) {
|
| 64 |
+
Row row{};
|
| 65 |
+
std::vector<int> order(STOP+1);
|
| 66 |
+
Floats x(STOP+1), weights(STOP+1);
|
| 67 |
+
for (int cb=0; cb<C; ++cb) {
|
| 68 |
+
std::array<bool,STOP> recent{};
|
| 69 |
+
if (cb<6) {
|
| 70 |
+
int begin=std::max(0,static_cast<int>(generated.size())-96);
|
| 71 |
+
for (size_t r=begin; r<generated.size(); ++r) {
|
| 72 |
+
int id=generated[r][cb];
|
| 73 |
+
if (id<STOP) recent[id]=true;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
for (int id=0; id<=STOP; ++id) {
|
| 77 |
+
float value=logits[cb*V+id];
|
| 78 |
+
require(std::isfinite(value),"nonfinite logits");
|
| 79 |
+
if (id<STOP && recent[id]) value=value>0 ? value/2.4f : value*2.4f;
|
| 80 |
+
x[id]=value/0.75f;
|
| 81 |
+
}
|
| 82 |
+
std::iota(order.begin(),order.end(),0);
|
| 83 |
+
auto higher=[&](int a,int b){return x[a]==x[b] ? a<b : x[a]>x[b];};
|
| 84 |
+
std::nth_element(order.begin(),order.begin()+79,order.end(),higher);
|
| 85 |
+
float cutoff=x[order[79]];
|
| 86 |
+
auto end=std::partition(order.begin(),order.end(),[&](int i){return x[i]>=cutoff;});
|
| 87 |
+
std::sort(order.begin(),end,higher);
|
| 88 |
+
double total=0;
|
| 89 |
+
for (auto it=order.begin(); it!=end; ++it) {
|
| 90 |
+
weights[*it]=std::exp(x[*it]-x[order.front()]);
|
| 91 |
+
total+=weights[*it];
|
| 92 |
+
}
|
| 93 |
+
double prefix=0;
|
| 94 |
+
auto kept_end=end;
|
| 95 |
+
double kept_sum=0;
|
| 96 |
+
for (auto it=order.begin(); it!=end; ++it) {
|
| 97 |
+
int id=*it;
|
| 98 |
+
float probability=static_cast<float>(weights[id]/total);
|
| 99 |
+
prefix+=probability;
|
| 100 |
+
if (static_cast<float>(prefix)-probability>0.69f) {
|
| 101 |
+
kept_end=it;
|
| 102 |
+
break;
|
| 103 |
+
}
|
| 104 |
+
weights[id]=probability;
|
| 105 |
+
kept_sum+=probability;
|
| 106 |
+
}
|
| 107 |
+
float best=-1;
|
| 108 |
+
for (auto it=order.begin(); it!=kept_end; ++it) {
|
| 109 |
+
int id=*it;
|
| 110 |
+
float normalized=weights[id]/static_cast<float>(kept_sum);
|
| 111 |
+
float race=normalized/draws[cb*V+id];
|
| 112 |
+
if (race>best || (race==best && id<row[cb])) {
|
| 113 |
+
best=race;
|
| 114 |
+
row[cb]=id;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
return row;
|
| 119 |
+
}
|
| 120 |
+
static Rows generate(const fs::path& take, const fs::path& shared, const fs::path& lm, const fs::path& replay) {
|
| 121 |
+
auto prompt=read_file<float>(take/"prompt.f32");
|
| 122 |
+
require(!prompt.empty() && prompt.size()%H==0 && prompt.size()/H<P,"invalid prompt rows");
|
| 123 |
+
auto silence=read_file<Row>(take/"silence.i32");
|
| 124 |
+
Generation gen(shared,lm,replay);
|
| 125 |
+
for (size_t i=0; i<prompt.size(); i+=H) gen.step(prompt.data()+i);
|
| 126 |
+
std::ifstream stream(take/"draws.f32",std::ios::binary);
|
| 127 |
+
Floats draws(C*V);
|
| 128 |
+
Rows rows;
|
| 129 |
+
int eos=-1, countdown=-1;
|
| 130 |
+
// The kit specifies Savannah reference prompts with three delayed silence rows.
|
| 131 |
+
require(silence.size()==3,"expected Savannah silence prefix");
|
| 132 |
+
for (int n=0;; ++n) {
|
| 133 |
+
require(bool(stream.read(reinterpret_cast<char*>(draws.data()),draws.size()*4)),"draw stream exhausted");
|
| 134 |
+
auto accepted=sample(gen.logits,rows,draws);
|
| 135 |
+
rows.push_back(accepted);
|
| 136 |
+
for (int j=C-1; j>=0 && eos<0; --j) {
|
| 137 |
+
if (accepted[j]==STOP) { eos=std::max(0,n-j); countdown=C+1; }
|
| 138 |
+
}
|
| 139 |
+
if (countdown>0 && --countdown==0) break;
|
| 140 |
+
gen.feed(accepted);
|
| 141 |
+
}
|
| 142 |
+
gen.finish();
|
| 143 |
+
int prefill=silence.size(), target=prefill+eos;
|
| 144 |
+
for (int r=0; r<static_cast<int>(rows.size()); ++r)
|
| 145 |
+
for (int j=0; j<C; ++j)
|
| 146 |
+
if (rows[r][j]==STOP) target=std::min(target,std::max(0,prefill+r-j));
|
| 147 |
+
silence.insert(silence.end(),rows.begin(),rows.end());
|
| 148 |
+
target=std::min(target,static_cast<int>(silence.size())-C+1);
|
| 149 |
+
if (target<=prefill) return {};
|
| 150 |
+
require(target<=150,"BucketExceeded: "+std::to_string(target)+" frames");
|
| 151 |
+
Rows codes(target);
|
| 152 |
+
for (int t=0; t<target; ++t)
|
| 153 |
+
for (int j=0; j<C; ++j) {
|
| 154 |
+
codes[t][j]=silence[t+j][j];
|
| 155 |
+
require(codes[t][j]>=0 && codes[t][j]<STOP,"invalid undelayed code");
|
| 156 |
+
}
|
| 157 |
+
return codes;
|
| 158 |
+
}
|
| 159 |
+
static Floats decode(const Rows& codes,const fs::path& shared,const fs::path& model,const fs::path& replay) {
|
| 160 |
+
if (codes.empty()) return {};
|
| 161 |
+
auto books=read_file<float>(shared/"books.f32",C*STOP*8);
|
| 162 |
+
Floats vectors(150*80);
|
| 163 |
+
for (size_t t=0; t<codes.size(); ++t)
|
| 164 |
+
for (int j=0; j<C; ++j)
|
| 165 |
+
std::copy_n(books.data()+(j*STOP+codes[t][j])*8,8,vectors.data()+t*80+j*8);
|
| 166 |
+
Floats head;
|
| 167 |
+
if (replay.empty()) {
|
| 168 |
+
std::vector<Floats> inputs;
|
| 169 |
+
inputs.push_back(std::move(vectors));
|
| 170 |
+
for (auto name:{"dec_cos.f32","dec_sin.f32"}) inputs.push_back(read_file<float>(shared/name,2400*32));
|
| 171 |
+
for (int i=0; i<5; ++i) {
|
| 172 |
+
int length=150<<i;
|
| 173 |
+
inputs.push_back(read_file<float>(shared/("window"+std::to_string(i)+".f32"),length*length));
|
| 174 |
+
}
|
| 175 |
+
for (int i=0; i<5; ++i) {
|
| 176 |
+
inputs.emplace_back(150<<i,0.f);
|
| 177 |
+
std::fill_n(inputs.back().begin(),codes.size()<<i,1.f);
|
| 178 |
+
}
|
| 179 |
+
std::vector<View> views;
|
| 180 |
+
for (auto& input:inputs) views.push_back(view(input));
|
| 181 |
+
head.resize(2400*2948);
|
| 182 |
+
open_graph(model,true)->run(views,{&head});
|
| 183 |
+
} else {
|
| 184 |
+
require(vectors==read_file<float>(replay/"cv.f32",150*80),"replay codec input mismatch");
|
| 185 |
+
head=read_file<float>(replay/"head.f32",2400*2948);
|
| 186 |
+
}
|
| 187 |
+
return decode_audio(head,codes.size(),shared);
|
| 188 |
+
}
|
| 189 |
+
int main(int argc,char** argv) {
|
| 190 |
+
try {
|
| 191 |
+
require(argc==6 || argc==7,"usage: zonos_host KIT TAG LM_GRAPH DEC_GRAPH OUTPUT [REPLAY_TAKE_DIR]");
|
| 192 |
+
fs::path kit=argv[1], dest=argv[5], replay=argc==7 ? argv[6] : "";
|
| 193 |
+
auto shared=kit/"shared", take=kit/"takes"/argv[2];
|
| 194 |
+
require(!fs::exists(dest),"output directory already exists");
|
| 195 |
+
std::ios::sync_with_stdio(false);
|
| 196 |
+
std::cin.tie(nullptr);
|
| 197 |
+
const auto start=std::chrono::steady_clock::now();
|
| 198 |
+
auto codes=generate(take,shared,argv[3],replay);
|
| 199 |
+
auto wave=decode(codes,shared,argv[4],replay);
|
| 200 |
+
fs::create_directories(dest);
|
| 201 |
+
write_file(dest/"codes.i32",codes);
|
| 202 |
+
save_audio(dest,wave);
|
| 203 |
+
double seconds=std::chrono::duration<double>(std::chrono::steady_clock::now()-start).count();
|
| 204 |
+
std::cerr<<"TAKE "<<argv[2]<<" frames="<<codes.size()<<" samples="<<wave.size()<<" wall_s="<<seconds<<"\n";
|
| 205 |
+
return 0;
|
| 206 |
+
} catch (const std::exception& e) {
|
| 207 |
+
std::cerr<<"TAKE_ERROR "<<e.what()<<"\n";
|
| 208 |
+
return 1;
|
| 209 |
+
}
|
| 210 |
+
}
|
include/pocketfft.h
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
kit/MANIFEST.json
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"form": "F",
|
| 3 |
+
"threads": 4,
|
| 4 |
+
"voice": "Savannah",
|
| 5 |
+
"byte_order": "little",
|
| 6 |
+
"takes": [
|
| 7 |
+
{
|
| 8 |
+
"tag": "s00",
|
| 9 |
+
"text": "The quick brown fox jumps over the lazy dog near the riverbank.",
|
| 10 |
+
"language": "en_us",
|
| 11 |
+
"seed": 1000
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"tag": "s01",
|
| 15 |
+
"text": "Please remember to bring an umbrella, because it might rain this afternoon.",
|
| 16 |
+
"language": "en_us",
|
| 17 |
+
"seed": 1001
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"tag": "s02",
|
| 21 |
+
"text": "She opened the window and listened to the birds singing in the garden.",
|
| 22 |
+
"language": "en_us",
|
| 23 |
+
"seed": 1002
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"tag": "s03",
|
| 27 |
+
"text": "The train leaves at 7:45 and arrives in Boston about 3 hours later.",
|
| 28 |
+
"language": "en_us",
|
| 29 |
+
"seed": 1003
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"tag": "s04",
|
| 33 |
+
"text": "Thank you for calling. Your order has been shipped and will arrive soon.",
|
| 34 |
+
"language": "en_us",
|
| 35 |
+
"seed": 1004
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"tag": "s05",
|
| 39 |
+
"text": "今日はとても良い天気ですね。散歩に行きましょう。",
|
| 40 |
+
"language": "ja",
|
| 41 |
+
"seed": 1005
|
| 42 |
+
}
|
| 43 |
+
],
|
| 44 |
+
"files": {
|
| 45 |
+
"shared/books.f32": {
|
| 46 |
+
"bytes": 1310720,
|
| 47 |
+
"sha256": "2c761e8a451f30a85d92e9eb2ba4911a76cfd3b5656ca732bffd5610a05db3e4"
|
| 48 |
+
},
|
| 49 |
+
"shared/dec_cos.f32": {
|
| 50 |
+
"bytes": 307200,
|
| 51 |
+
"sha256": "4581ddfa7adbb64544d338e29eeeb954c00bffd961f23d75d5711af9bfc9ad95"
|
| 52 |
+
},
|
| 53 |
+
"shared/dec_sin.f32": {
|
| 54 |
+
"bytes": 307200,
|
| 55 |
+
"sha256": "5d8a3460b8f31ac43b1a74423f7eee2a6ebd4eb17dc46f3fc18f7e45074954b6"
|
| 56 |
+
},
|
| 57 |
+
"shared/embeddings.f32": {
|
| 58 |
+
"bytes": 167854080,
|
| 59 |
+
"sha256": "63a22f3c6be20cab25331ecfa7cebf618899c57db79e820b9a9db576b6e8cc77"
|
| 60 |
+
},
|
| 61 |
+
"shared/hann2208.f32": {
|
| 62 |
+
"bytes": 8832,
|
| 63 |
+
"sha256": "38ec67e7c506ae2718ad7d0e6b8ee7a31a1b1465da25fe0fc8559019c1322661"
|
| 64 |
+
},
|
| 65 |
+
"shared/hann736.f32": {
|
| 66 |
+
"bytes": 2944,
|
| 67 |
+
"sha256": "053c115aca717a92de4f327c23f2c8918554dac3075fab220304ebb5ead0cea2"
|
| 68 |
+
},
|
| 69 |
+
"shared/lm_cos.f32": {
|
| 70 |
+
"bytes": 49152,
|
| 71 |
+
"sha256": "190cd094b3599cf428615d6b72f56b0d41efe5adba15550edd9df76ad52f6230"
|
| 72 |
+
},
|
| 73 |
+
"shared/lm_sin.f32": {
|
| 74 |
+
"bytes": 49152,
|
| 75 |
+
"sha256": "34736dc609cbe7957af492cb0ae6c5603fa873a685dcbfaa6760f5aea7df0fed"
|
| 76 |
+
},
|
| 77 |
+
"shared/mixer.f32": {
|
| 78 |
+
"bytes": 1016,
|
| 79 |
+
"sha256": "a109a28ae31b6085cab432025fb851e863f4aded01e56c7088bd5d83d59b1564"
|
| 80 |
+
},
|
| 81 |
+
"shared/resample.f32": {
|
| 82 |
+
"bytes": 2263800,
|
| 83 |
+
"sha256": "b28a672492915aa12a53b3a2e517a48218315fc1903eafd6b9593f680f38dce8"
|
| 84 |
+
},
|
| 85 |
+
"shared/text_pad.f32": {
|
| 86 |
+
"bytes": 4096,
|
| 87 |
+
"sha256": "c011b128778e7a2f369db144372687ac4aa9c82d54c9643ae6208a097b9fd0cd"
|
| 88 |
+
},
|
| 89 |
+
"shared/window0.f32": {
|
| 90 |
+
"bytes": 90000,
|
| 91 |
+
"sha256": "f85d1b572598d4cacbb2fd01b85fa022568de6d4b3e207cb9cfebe151380cc6a"
|
| 92 |
+
},
|
| 93 |
+
"shared/window1.f32": {
|
| 94 |
+
"bytes": 360000,
|
| 95 |
+
"sha256": "765535371ee8d579be3341bc754c30a502a537f7db58ac4b42795cc5090a669e"
|
| 96 |
+
},
|
| 97 |
+
"shared/window2.f32": {
|
| 98 |
+
"bytes": 1440000,
|
| 99 |
+
"sha256": "e94155eb436370499dede59e5b1b240472a3d061be8229732fcca1f92e9aa303"
|
| 100 |
+
},
|
| 101 |
+
"shared/window3.f32": {
|
| 102 |
+
"bytes": 5760000,
|
| 103 |
+
"sha256": "e21c7d692d6052c5ce15d53fbf26d3e8755cb3a88cc2f691ce68c8fce5e8a51d"
|
| 104 |
+
},
|
| 105 |
+
"shared/window4.f32": {
|
| 106 |
+
"bytes": 23040000,
|
| 107 |
+
"sha256": "fe8197a213825210324d136166577efbcfee2c2dacad81b42d8c494cc6634917"
|
| 108 |
+
},
|
| 109 |
+
"takes/s00/draws.f32": {
|
| 110 |
+
"bytes": 92123040,
|
| 111 |
+
"sha256": "312fed2148863dd4c014a99bd58a9016e94d89aa010f95a8d551daf68bca8896"
|
| 112 |
+
},
|
| 113 |
+
"takes/s00/prompt.f32": {
|
| 114 |
+
"bytes": 847872,
|
| 115 |
+
"sha256": "2e5137cd12edba955912dac92a2f1fb3a40e581bc7ab71862d8d31ecde3aa8cb"
|
| 116 |
+
},
|
| 117 |
+
"takes/s00/reference/take_codes.npy": {
|
| 118 |
+
"bytes": 2608,
|
| 119 |
+
"sha256": "6a3a358fbcaa1535bd69498a181498b2a6652ba247d41174db437539e164fc75"
|
| 120 |
+
},
|
| 121 |
+
"takes/s00/reference/waveform.npy": {
|
| 122 |
+
"bytes": 729248,
|
| 123 |
+
"sha256": "bde9cacb2a873b9933cac99210420753892d23af6cc53e752740bea411ffe05f"
|
| 124 |
+
},
|
| 125 |
+
"takes/s00/reference/waveform.wav": {
|
| 126 |
+
"bytes": 364604,
|
| 127 |
+
"sha256": "209f5f0ae7e5e6da4bca4dd48116a5a0f9cafa26b664fbc159b8760ebd8b68f3"
|
| 128 |
+
},
|
| 129 |
+
"takes/s00/request.json": {
|
| 130 |
+
"bytes": 130,
|
| 131 |
+
"sha256": "0aaec1b97e91ba6736ca646765c4c308975b7cd7d5d61eec5a762fba555edb26"
|
| 132 |
+
},
|
| 133 |
+
"takes/s00/silence.i32": {
|
| 134 |
+
"bytes": 120,
|
| 135 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 136 |
+
},
|
| 137 |
+
"takes/s01/draws.f32": {
|
| 138 |
+
"bytes": 92123040,
|
| 139 |
+
"sha256": "c2c8475e56d42dd714b8f010c4bdf0690d4591b852dc6eb1062c8cdaa74a730c"
|
| 140 |
+
},
|
| 141 |
+
"takes/s01/prompt.f32": {
|
| 142 |
+
"bytes": 847872,
|
| 143 |
+
"sha256": "1d66b25f0054335a9b4a358aecfdee7c705ee9b5a48fcaff9269f6adda1fb1ca"
|
| 144 |
+
},
|
| 145 |
+
"takes/s01/reference/take_codes.npy": {
|
| 146 |
+
"bytes": 2688,
|
| 147 |
+
"sha256": "2708e20f2c59204691f3b4ee5511caa47a6d2b86286be1cde76f3f0a8fa2c429"
|
| 148 |
+
},
|
| 149 |
+
"takes/s01/reference/waveform.npy": {
|
| 150 |
+
"bytes": 752768,
|
| 151 |
+
"sha256": "87a4b6bd65b9260d4376e089d04df3f8bf841adba5a4c6c17cdfed5e36828968"
|
| 152 |
+
},
|
| 153 |
+
"takes/s01/reference/waveform.wav": {
|
| 154 |
+
"bytes": 376364,
|
| 155 |
+
"sha256": "19c5b47bb2c705d8caf7f47fb2d957507a4424fb337ecdb3a1291b5452b09cf0"
|
| 156 |
+
},
|
| 157 |
+
"takes/s01/request.json": {
|
| 158 |
+
"bytes": 142,
|
| 159 |
+
"sha256": "d2ff07c4d84b34df9f7d6325f249d8b0b07bc4e03025e3c06c9d7f972fa215a2"
|
| 160 |
+
},
|
| 161 |
+
"takes/s01/silence.i32": {
|
| 162 |
+
"bytes": 120,
|
| 163 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 164 |
+
},
|
| 165 |
+
"takes/s02/draws.f32": {
|
| 166 |
+
"bytes": 92286960,
|
| 167 |
+
"sha256": "9bb30210143ac37b3e2ed779768f94294402a06a00a10d66601604a782c38c98"
|
| 168 |
+
},
|
| 169 |
+
"takes/s02/prompt.f32": {
|
| 170 |
+
"bytes": 843776,
|
| 171 |
+
"sha256": "21da54fa59088a8b3d16670f35fc25228a0200f8e8cdbffcf984fafc5166f6bd"
|
| 172 |
+
},
|
| 173 |
+
"takes/s02/reference/take_codes.npy": {
|
| 174 |
+
"bytes": 2408,
|
| 175 |
+
"sha256": "a97365e74aae29a5ef9bc2526d92ab0608cf864d72c1d3c7ced093e0f250e4a6"
|
| 176 |
+
},
|
| 177 |
+
"takes/s02/reference/waveform.npy": {
|
| 178 |
+
"bytes": 670448,
|
| 179 |
+
"sha256": "ee2aca497e854296a2b746f00a089b3f45bdfcfe63a8c7a05e23e9c206afaf78"
|
| 180 |
+
},
|
| 181 |
+
"takes/s02/reference/waveform.wav": {
|
| 182 |
+
"bytes": 335204,
|
| 183 |
+
"sha256": "f9e0ec9c571119e3ca794409e0046a02c9316927532c999372dda4624b3d33fd"
|
| 184 |
+
},
|
| 185 |
+
"takes/s02/request.json": {
|
| 186 |
+
"bytes": 137,
|
| 187 |
+
"sha256": "3f5ea33afa4dfb8e49e63887777e06fc8402c6b34c2fa848a02b7838637c1b0c"
|
| 188 |
+
},
|
| 189 |
+
"takes/s02/silence.i32": {
|
| 190 |
+
"bytes": 120,
|
| 191 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 192 |
+
},
|
| 193 |
+
"takes/s03/draws.f32": {
|
| 194 |
+
"bytes": 91795200,
|
| 195 |
+
"sha256": "710758704376a74acc0b5747394eee0009c0c7448bcefc8c7e51d0334ffe9722"
|
| 196 |
+
},
|
| 197 |
+
"takes/s03/prompt.f32": {
|
| 198 |
+
"bytes": 856064,
|
| 199 |
+
"sha256": "1f5812052c0e8fd0100153225954b1871bd1257e466344fa04b2aa0a5f29ff2c"
|
| 200 |
+
},
|
| 201 |
+
"takes/s03/reference/take_codes.npy": {
|
| 202 |
+
"bytes": 3168,
|
| 203 |
+
"sha256": "a610e00525120ee0ce84147d9712923e04c540a4456060da655421049049bc15"
|
| 204 |
+
},
|
| 205 |
+
"takes/s03/reference/waveform.npy": {
|
| 206 |
+
"bytes": 893888,
|
| 207 |
+
"sha256": "fcccdaff1142297283accfdbbb90ae47b9b0efa6469334d562fb5b252f179a2b"
|
| 208 |
+
},
|
| 209 |
+
"takes/s03/reference/waveform.wav": {
|
| 210 |
+
"bytes": 446924,
|
| 211 |
+
"sha256": "acadff4f5ce6c6dea3fbb306bd987b6bd570c785b722b42ee9152299515d3769"
|
| 212 |
+
},
|
| 213 |
+
"takes/s03/request.json": {
|
| 214 |
+
"bytes": 134,
|
| 215 |
+
"sha256": "58ea4fe64ba8d78694bdc34791814cd1f0304e9221cc45482d3f489666fae138"
|
| 216 |
+
},
|
| 217 |
+
"takes/s03/silence.i32": {
|
| 218 |
+
"bytes": 120,
|
| 219 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 220 |
+
},
|
| 221 |
+
"takes/s04/draws.f32": {
|
| 222 |
+
"bytes": 92450880,
|
| 223 |
+
"sha256": "7e7e2ba557606016b53985914c591f1dbde8137cdd4c2bd904f552cef7c378ab"
|
| 224 |
+
},
|
| 225 |
+
"takes/s04/prompt.f32": {
|
| 226 |
+
"bytes": 839680,
|
| 227 |
+
"sha256": "5a9a961e04481566361576ca66ce0669d7fe7eae853bbf0e1b418aedf28b4002"
|
| 228 |
+
},
|
| 229 |
+
"takes/s04/reference/take_codes.npy": {
|
| 230 |
+
"bytes": 2928,
|
| 231 |
+
"sha256": "daa78893175d7cd9253f113e91ce70b1c2d3b03d8f0fc9dd8ec9e13d9172e9df"
|
| 232 |
+
},
|
| 233 |
+
"takes/s04/reference/waveform.npy": {
|
| 234 |
+
"bytes": 823328,
|
| 235 |
+
"sha256": "27287f36d7b329b1c8cf4b8358b1fa6fe9983b31a9d4d8f5be47366450b8c7d5"
|
| 236 |
+
},
|
| 237 |
+
"takes/s04/reference/waveform.wav": {
|
| 238 |
+
"bytes": 411644,
|
| 239 |
+
"sha256": "b48aa7fe7b9b1ad9ca06c0ba55500ff684281b10a3859876c4c7c32d2ae0c146"
|
| 240 |
+
},
|
| 241 |
+
"takes/s04/request.json": {
|
| 242 |
+
"bytes": 139,
|
| 243 |
+
"sha256": "42890a3340b02debee65735f8945be74d203d2736194dea38ab0c24ab03dbba4"
|
| 244 |
+
},
|
| 245 |
+
"takes/s04/silence.i32": {
|
| 246 |
+
"bytes": 120,
|
| 247 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 248 |
+
},
|
| 249 |
+
"takes/s05/draws.f32": {
|
| 250 |
+
"bytes": 92286960,
|
| 251 |
+
"sha256": "7d2e8de6bd985aed81a4d2ea4d39cde7d1d71431fd3703df40a83b9043abc955"
|
| 252 |
+
},
|
| 253 |
+
"takes/s05/prompt.f32": {
|
| 254 |
+
"bytes": 843776,
|
| 255 |
+
"sha256": "3ea1ae3028b5e745d8cf5ac492832d89fcf70a787cf7b0db4f06567f925c2660"
|
| 256 |
+
},
|
| 257 |
+
"takes/s05/reference/take_codes.npy": {
|
| 258 |
+
"bytes": 2808,
|
| 259 |
+
"sha256": "5bc1368693b4e3bdd2c1c8a6a2afcb6f9a8347f678b224561efc7b1364fa32c4"
|
| 260 |
+
},
|
| 261 |
+
"takes/s05/reference/waveform.npy": {
|
| 262 |
+
"bytes": 788048,
|
| 263 |
+
"sha256": "2abfb59ff5c8acfa1f8194fd8a4a447754eef78c00fbb5c30de245a585cffd1a"
|
| 264 |
+
},
|
| 265 |
+
"takes/s05/reference/waveform.wav": {
|
| 266 |
+
"bytes": 394004,
|
| 267 |
+
"sha256": "2da55b7f18287e7cfb45a28b31bb127ca349b63bb5d6136de6c522fa95b0a1f5"
|
| 268 |
+
},
|
| 269 |
+
"takes/s05/request.json": {
|
| 270 |
+
"bytes": 136,
|
| 271 |
+
"sha256": "a2418e57c325376d36e84deafb5c541c2ddde330a93e278ec98267a1eecd7954"
|
| 272 |
+
},
|
| 273 |
+
"takes/s05/silence.i32": {
|
| 274 |
+
"bytes": 120,
|
| 275 |
+
"sha256": "063e65c87d4b5cd2c747ae44ac0ebdd6dfc2f7f84ffabc276d0daeaca319d97f"
|
| 276 |
+
}
|
| 277 |
+
},
|
| 278 |
+
"graphs": [
|
| 279 |
+
{
|
| 280 |
+
"path": "graphs/lm_step_p768.tflite",
|
| 281 |
+
"bytes": 3342543296,
|
| 282 |
+
"sha256": "068e500d7daedb2d3b5cf2a1348db4c3cc4ff392d80edb236c258a9ab9c13753"
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"path": "graphs/codec_dec_f150.tflite",
|
| 286 |
+
"bytes": 572522276,
|
| 287 |
+
"sha256": "eb9a108f7c466f67045f7c547c73a1d14b0a8840c4ed0d415854eb0927abb9ca"
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"path": "graphs/spk_enc_t998.tflite",
|
| 291 |
+
"bytes": 45122316,
|
| 292 |
+
"sha256": "3672c911c17dcc18052a1060c1be9d3d96d620a52fd97f33756644a91299f0b4"
|
| 293 |
+
}
|
| 294 |
+
]
|
| 295 |
+
}
|
kit/shared/books.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2c761e8a451f30a85d92e9eb2ba4911a76cfd3b5656ca732bffd5610a05db3e4
|
| 3 |
+
size 1310720
|
kit/shared/dec_cos.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4581ddfa7adbb64544d338e29eeeb954c00bffd961f23d75d5711af9bfc9ad95
|
| 3 |
+
size 307200
|
kit/shared/dec_sin.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d8a3460b8f31ac43b1a74423f7eee2a6ebd4eb17dc46f3fc18f7e45074954b6
|
| 3 |
+
size 307200
|
kit/shared/embeddings.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63a22f3c6be20cab25331ecfa7cebf618899c57db79e820b9a9db576b6e8cc77
|
| 3 |
+
size 167854080
|
kit/shared/hann2208.f32
ADDED
|
Binary file (8.83 kB). View file
|
|
|
kit/shared/hann736.f32
ADDED
|
Binary file (2.94 kB). View file
|
|
|
kit/shared/lm_cos.f32
ADDED
|
Binary file (49.2 kB). View file
|
|
|
kit/shared/lm_sin.f32
ADDED
|
Binary file (49.2 kB). View file
|
|
|
kit/shared/mixer.f32
ADDED
|
Binary file (1.02 kB). View file
|
|
|
kit/shared/resample.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b28a672492915aa12a53b3a2e517a48218315fc1903eafd6b9593f680f38dce8
|
| 3 |
+
size 2263800
|
kit/shared/text_pad.f32
ADDED
|
Binary file (4.1 kB). View file
|
|
|
kit/shared/window0.f32
ADDED
|
Binary file (90 kB). View file
|
|
|
kit/shared/window1.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:765535371ee8d579be3341bc754c30a502a537f7db58ac4b42795cc5090a669e
|
| 3 |
+
size 360000
|
kit/shared/window2.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e94155eb436370499dede59e5b1b240472a3d061be8229732fcca1f92e9aa303
|
| 3 |
+
size 1440000
|
kit/shared/window3.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e21c7d692d6052c5ce15d53fbf26d3e8755cb3a88cc2f691ce68c8fce5e8a51d
|
| 3 |
+
size 5760000
|
kit/shared/window4.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fe8197a213825210324d136166577efbcfee2c2dacad81b42d8c494cc6634917
|
| 3 |
+
size 23040000
|
kit/takes/s00/draws.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:312fed2148863dd4c014a99bd58a9016e94d89aa010f95a8d551daf68bca8896
|
| 3 |
+
size 92123040
|
kit/takes/s00/prompt.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2e5137cd12edba955912dac92a2f1fb3a40e581bc7ab71862d8d31ecde3aa8cb
|
| 3 |
+
size 847872
|
kit/takes/s00/reference/take_codes.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a3a358fbcaa1535bd69498a181498b2a6652ba247d41174db437539e164fc75
|
| 3 |
+
size 2608
|
kit/takes/s00/reference/waveform.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bde9cacb2a873b9933cac99210420753892d23af6cc53e752740bea411ffe05f
|
| 3 |
+
size 729248
|
kit/takes/s00/reference/waveform.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:209f5f0ae7e5e6da4bca4dd48116a5a0f9cafa26b664fbc159b8760ebd8b68f3
|
| 3 |
+
size 364604
|
kit/takes/s00/request.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tag": "s00",
|
| 3 |
+
"text": "The quick brown fox jumps over the lazy dog near the riverbank.",
|
| 4 |
+
"language": "en_us",
|
| 5 |
+
"seed": 1000
|
| 6 |
+
}
|
kit/takes/s00/silence.i32
ADDED
|
Binary file (120 Bytes). View file
|
|
|
kit/takes/s01/draws.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c2c8475e56d42dd714b8f010c4bdf0690d4591b852dc6eb1062c8cdaa74a730c
|
| 3 |
+
size 92123040
|
kit/takes/s01/prompt.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d66b25f0054335a9b4a358aecfdee7c705ee9b5a48fcaff9269f6adda1fb1ca
|
| 3 |
+
size 847872
|
kit/takes/s01/reference/take_codes.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2708e20f2c59204691f3b4ee5511caa47a6d2b86286be1cde76f3f0a8fa2c429
|
| 3 |
+
size 2688
|
kit/takes/s01/reference/waveform.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87a4b6bd65b9260d4376e089d04df3f8bf841adba5a4c6c17cdfed5e36828968
|
| 3 |
+
size 752768
|
kit/takes/s01/reference/waveform.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19c5b47bb2c705d8caf7f47fb2d957507a4424fb337ecdb3a1291b5452b09cf0
|
| 3 |
+
size 376364
|
kit/takes/s01/request.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tag": "s01",
|
| 3 |
+
"text": "Please remember to bring an umbrella, because it might rain this afternoon.",
|
| 4 |
+
"language": "en_us",
|
| 5 |
+
"seed": 1001
|
| 6 |
+
}
|
kit/takes/s01/silence.i32
ADDED
|
Binary file (120 Bytes). View file
|
|
|
kit/takes/s02/draws.f32
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9bb30210143ac37b3e2ed779768f94294402a06a00a10d66601604a782c38c98
|
| 3 |
+
size 92286960
|