File size: 839 Bytes
76d09f0
3559195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Pingo acoustic model in MLX with the firmware's 4-bit weights, dequantized."""
import numpy as np
import mlx.core as mx
from mlx.utils import tree_flatten, tree_unflatten
from . import weights as W
from . import acoustic_mlx as A


class AcousticMLX:
    def __init__(self, path=W.DEFAULT):
        z, meta = W.load(path); cfg, ac = W.acoustic(z, meta)
        self.cfg = cfg; self.model = A.Acoustic(cfg)
        flat = [(k, mx.array(np.ascontiguousarray(ac[W.cname(k)].reshape(v.shape)))) for k, v in tree_flatten(self.model.parameters())]
        self.model.update(tree_unflatten(flat)); mx.eval(self.model.parameters())

    def features(self, ids, stress, voice, speed=1.0, phone_mask=None):
        return A.acoustic_features(self.model, [int(i) for i in ids], [int(i) for i in stress], int(voice), speed, np.asarray(phone_mask))