Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,55 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
## Usage
|
6 |
+
|
7 |
+
### Python
|
8 |
+
|
9 |
+
```python
|
10 |
+
import os
|
11 |
+
import numpy as np
|
12 |
+
from onnxruntime import InferenceSession
|
13 |
+
|
14 |
+
# Tokens produced by phonemize() and tokenize() in kokoro.py
|
15 |
+
tokens = [50, 157, 43, 135, 16, 53, 135, 46, 16, 43, 102, 16, 56, 156, 57, 135, 6, 16, 102, 62, 61, 16, 70, 56, 16, 138, 56, 156, 72, 56, 61, 85, 123, 83, 44, 83, 54, 16, 53, 65, 156, 86, 61, 62, 131, 83, 56, 4, 16, 54, 156, 43, 102, 53, 16, 156, 72, 61, 53, 102, 112, 16, 70, 56, 16, 138, 56, 44, 156, 76, 158, 123, 56, 16, 62, 131, 156, 43, 102, 54, 46, 16, 102, 48, 16, 81, 47, 102, 54, 16, 54, 156, 51, 158, 46, 16, 70, 16, 92, 156, 135, 46, 16, 54, 156, 43, 102, 48, 4, 16, 81, 47, 102, 16, 50, 156, 72, 64, 83, 56, 62, 16, 156, 51, 158, 64, 83, 56, 16, 44, 157, 102, 56, 16, 44, 156, 76, 158, 123, 56, 4]
|
16 |
+
|
17 |
+
# Context length is 512, but leave room for the pad token 0 at the start & end
|
18 |
+
assert len(tokens) <= 510, len(tokens)
|
19 |
+
|
20 |
+
# Style vector based on len(tokens), ref_s has shape (1, 256)
|
21 |
+
voices = np.fromfile('./voices/af.bin', dtype=np.float32).reshape(-1, 1, 256)
|
22 |
+
ref_s = voices[len(tokens)]
|
23 |
+
|
24 |
+
# Add the pad ids, and reshape tokens, should now have shape (1, <=512)
|
25 |
+
tokens = [[0, *tokens, 0]]
|
26 |
+
|
27 |
+
model_name = 'model.onnx' # Options: model.onnx, model_fp16.onnx, model_quantized.onnx, model_q8f16.onnx, model_uint8.onnx, model_uint8f16.onnx, model_q4.onnx, model_q4f16.onnx
|
28 |
+
sess = InferenceSession(os.path.join('onnx', model_name))
|
29 |
+
|
30 |
+
audio = sess.run(None, dict(
|
31 |
+
input_ids=tokens,
|
32 |
+
style=ref_s,
|
33 |
+
speed=np.ones(1, dtype=np.float32),
|
34 |
+
))[0]
|
35 |
+
```
|
36 |
+
|
37 |
+
Optionally, save the audio to a file:
|
38 |
+
```
|
39 |
+
import scipy.io.wavfile as wavfile
|
40 |
+
wavfile.write('audio.wav', 24000, audio[0])
|
41 |
+
```
|
42 |
+
|
43 |
+
## Samples
|
44 |
+
|
45 |
+
| Model | Size (MB) | Sample |
|
46 |
+
|------------------------------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------|
|
47 |
+
| model.onnx (fp32) | 326 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/njexBuqPzfYUvWgs9eQ-_.wav"></audio> |
|
48 |
+
| model_fp16.onnx (fp16) | 163 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/8Ebl44hMQonZs4MlykExt.wav"></audio> |
|
49 |
+
| model_quantized.onnx (8-bit) | 92.4 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/9SLOt6ETclZ4yRdlJ0VIj.wav"></audio> |
|
50 |
+
| model_q8f16.onnx (Mixed precision) | 86 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/gNDMqb33YEmYMbAIv_Grx.wav"></audio> |
|
51 |
+
| model_uint8.onnx (8-bit & mixed precision) | 177 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/tpOWRHIWwEb0PJX46dCWQ.wav"></audio> |
|
52 |
+
| model_uint8f16.onnx (Mixed precision) | 114 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/vtZhABzjP0pvGD7dRb5Vr.wav"></audio> |
|
53 |
+
| model_q4.onnx (4-bit matmul) | 305 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/8FVn0IJIUfccEBWq8Fnw_.wav"></audio> |
|
54 |
+
| model_q4f16.onnx (4-bit matmul & fp16 weights) | 154 | <audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/7DrgWC_1q00s-wUJuG44X.wav"></audio> |
|
55 |
+
|