pykaldi / pykaldi

A Python wrapper for Kaldi
https://pykaldi.github.io
Apache License 2.0
991 stars 248 forks source link

Plda score #231

Closed lalimili6 closed 2 years ago

lalimili6 commented 4 years ago

Hi dears I want to use Kaldi pre-train speaker verification models. suppose I have two arrays or something else that contain ivectors of two voice (e.g. a=[1,1,1] b=[2,2,2]) and I want to compute plda score between them using Kaldi pre-train model (e.g. plda_scor(a,b)). Is it possible to use pykaldi for that purpose? is it some example of it?

best regards

JerryPeng21cuhk commented 4 years ago

It's possible. Firstly, you can use pykaldi to load the plda parameters into numpy arrays. Then re-write the kaldi C++ plda scoring function to python.

Here is the code to load plda parameters.

from kaldi.base.io import expect_token
from kaldi.ivector import Plda
from kaldi.matrix import DoubleMatrix, DoubleVector
from kaldi.util.io import xopen

plda = Plda()

with xopen("plda", "w") as ko:
    plda.write(ko.stream(), ko.binary)

with xopen("plda") as ki:
    expect_token(ki.stream(), ki.binary, "<Plda>")
    mean = DoubleVector().read_(ki.stream(), ki.binary)
    transform = DoubleMatrix().read_(ki.stream(), ki.binary)
    psi = DoubleVector().read_(ki.stream(), ki.binary)
    expect_token(ki.stream(), ki.binary, "</Plda>")

reference: https://github.com/pykaldi/pykaldi/issues/74