util API
maai.util
conv_2float_2_byte(val1, val2)
Convert two double-precision floats into a combined byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val1
|
float
|
First float. |
required |
val2
|
float
|
Second float. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
Combined byte array. |
Source code in src/maai/util.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
conv_2int16_2_byte(val1, val2)
Convert two integers into a combined byte array using 2 bytes each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val1
|
int
|
First integer. |
required |
val2
|
int
|
Second integer. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
Combined byte array. |
Source code in src/maai/util.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
conv_byte_2_2float(b1, b2)
Convert two double-precision byte blocks back into floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b1
|
bytes
|
First byte block. |
required |
b2
|
bytes
|
Second byte block. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple[float, float]: The decoded floats. |
Source code in src/maai/util.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
conv_bytearray_2_vapresult(barr)
Deserialize a byte array back into a VAP result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded VAP result data. |
Source code in src/maai/util.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
conv_bytearray_2_vapresult_bc_det(barr)
Deserialize a byte array back into a BC detection result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded BC detection result data. |
Source code in src/maai/util.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
conv_bytearray_2_vapresult_bc_det_mono(barr)
Deserialize a byte array back into a mono BC detection result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded mono BC detection result data with a |
|
|
scalar |
Source code in src/maai/util.py
821 822 823 824 825 826 827 828 829 830 831 832 833 | |
conv_bytearray_2_vapresult_mono(barr)
Deserialize a byte array back into a mono VAP result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded mono VAP result data with scalar |
|
|
|
Source code in src/maai/util.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
conv_bytearray_2_vapresult_vad(barr)
Deserialize a byte array back into a VAD result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded VAD result data. |
Source code in src/maai/util.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
conv_bytearray_2_vapresult_vad_mono(barr)
Deserialize a byte array back into a mono VAD result dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
barr
|
bytes
|
Serialized byte array. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The decoded mono VAD result data with a scalar |
Source code in src/maai/util.py
720 721 722 723 724 725 726 727 728 729 730 731 | |
conv_vapresult_2_bytearray(vap_result)
Serialize a VAP result dictionary into a byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
VAP result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
conv_vapresult_2_bytearray_bc_det(vap_result)
Serialize a BC detection result dictionary into a byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
BC detection result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
conv_vapresult_2_bytearray_bc_det_mono(vap_result)
Serialize a mono BC detection result dictionary into a byte array.
The scalar p_bc_det value is wrapped into a length-1 array so the
wire format stays identical to the two-channel one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
Mono BC detection result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
conv_vapresult_2_bytearray_mono(vap_result)
Serialize a mono VAP result dictionary into a byte array.
Scalar p_now / p_future / vad values are wrapped into
length-1 arrays so the wire format stays identical to the stereo one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
Mono VAP result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
conv_vapresult_2_bytearray_vad(vap_result)
Serialize a VAD result dictionary into a byte array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
VAD result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | |
conv_vapresult_2_bytearray_vad_mono(vap_result)
Serialize a mono VAD result dictionary into a byte array.
The scalar vad value is wrapped into a length-1 array so the wire
format stays identical to the two-channel one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vap_result
|
Dict[str, Any]
|
Mono VAD result data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The serialized byte array. |
Source code in src/maai/util.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
download_continuous_mimi_onnx(precision='fp32', cache_dir=None, force_download=False, frames_per_call=1)
Resolve paths to the streaming Mimi ONNX model and JSON sidecar on disk.
Files are fetched from maai-kyoto/continuous-mimi-onnx via hf_hub_download
(cached under the usual Hugging Face cache layout, or under cache_dir when set).
frames_per_call selects the microbatch export contract: 1 (default) is the
original one-frame-per-call export (continuous_mimi_{precision}.onnx); N > 1
selects the N-frames-per-call export (continuous_mimi_{precision}_{N}f.onnx),
which produces N VAP frames per ONNX call.
Source code in src/maai/util.py
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | |
euler_to_quaternion(rx, ry, rz)
XYZ intrinsic Euler angles (radians) to quaternion (qx, qy, qz, qw).
Source code in src/maai/util.py
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 | |
generate_natural_nod(range_rad, count, use_pre_rise, velocity, fps=30, decay_rate=0.6, pre_rise_ratio=0.8)
Generate a natural nodding motion sequence (pitch in radians vs time in seconds).
Interpolation is cubic spline (CubicSpline) when scipy is available,
else cosine interpolation between keyframes.
Parameters
range_rad : float Nod depth in radians (absolute value). count : int Number of nods (>= 1). use_pre_rise : bool Whether to include a pre-rise before the first nod. velocity : float Target average angular velocity (rad/s). fps : int Output frame rate. decay_rate : float Amplitude decay per nod (0–1). pre_rise_ratio : float Pre-rise amplitude as a ratio of range_rad.
Returns
motion : np.ndarray Pitch values in radians, one per frame. time_axis : np.ndarray Time stamps in seconds, same length as motion.
Source code in src/maai/util.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
get_available_models()
Retrieve a dictionary of available pre-trained models from the Hugging Face hub.
Returns:
| Type | Description |
|---|---|
|
Dict[str, List[str]]: A mapping of repository IDs to their available model files. |
Source code in src/maai/util.py
350 351 352 353 354 355 356 357 358 359 360 | |
load_vap_model(mode, frame_rate, context_len_sec, language='jp', device='cpu', cache_dir=None, force_download=False, model_type='normal')
Load a pretrained VAP model from the Hugging Face hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
The operational mode of the model (e.g., 'vap', 'vap_mc', 'bc', 'nod'). |
required |
frame_rate
|
float
|
The frame rate expected by the model. |
required |
context_len_sec
|
float
|
The context length in seconds. |
required |
language
|
str
|
The language identifier for the model (e.g., 'jp', 'en'). |
'jp'
|
device
|
str
|
The device to load the model onto ('cpu', 'cuda'). |
'cpu'
|
cache_dir
|
str
|
Directory to cache the downloaded model. |
None
|
force_download
|
bool
|
If True, forces download even if cached. |
False
|
model_type
|
str
|
The general model architecture type. |
'normal'
|
Returns:
| Type | Description |
|---|---|
|
Dict[str, Any]: The loaded state dictionary of the model. |
Source code in src/maai/util.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
resolve_encoder_type(model_type='normal')
Resolve the encoder type based on the provided model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
str
|
The type of model (e.g., 'normal', 'normal-ver2'). |
'normal'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The corresponding encoder type ('cpc' or 'mimi'). |
Source code in src/maai/util.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |