Skip to content

怎么使用流式的fsmn-kws #2193

Open
@hajkeoadf

Description

@hajkeoadf

Notice: In order to resolve issues more efficiently, please raise issue following the template.
(注意:为了更加高效率解决您遇到的问题,请按照模板提问,补充细节)

❓ Questions and Help

如题,我想使用流式的fsmn-kws,直接传入chunk不可行

import hydra
import logging
from omegaconf import DictConfig, OmegaConf, ListConfig
import soundfile
from funasr.auto.auto_model import AutoModel


@hydra.main(config_name=None, version_base=None)
def main_hydra(cfg: DictConfig):
    def to_plain_list(cfg_item):
        if isinstance(cfg_item, ListConfig):
            return OmegaConf.to_container(cfg_item, resolve=True)
        elif isinstance(cfg_item, DictConfig):
            return {k: to_plain_list(v) for k, v in cfg_item.items()}
        else:
            return cfg_item

    kwargs = to_plain_list(cfg)

    if kwargs.get("debug", False):
        import pdb

        pdb.set_trace()
    model = AutoModel(**kwargs)

    speech, sample_rate = soundfile.read(kwargs["input"])
    chunk_size = [0, 10, 5] #[0, 10, 5] 600ms, [0, 8, 4] 480ms
    encoder_chunk_look_back = 4 #number of chunks to lookback for encoder self-attention
    decoder_chunk_look_back = 1 #number of encoder chunks to lookback for decoder cross-attention
    chunk_stride = chunk_size[1] * 960 # 600ms
    cache = {}
    total_chunk_num = int(len((speech)-1)/chunk_stride+1)
    for i in range(total_chunk_num):
        speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
        is_final = i == total_chunk_num - 1
        res = model.generate(input=speech_chunk, cache=cache, is_final=is_final, chunk_size=chunk_size, encoder_chunk_look_back=encoder_chunk_look_back, decoder_chunk_look_back=decoder_chunk_look_back)
        print(res)


if __name__ == "__main__":
    main_hydra()

输出

[2024-11-04 15:10:30,792][root][INFO] - Loading ckpt: /mnt/roboair/home/flora.he/keyword-spotting/fsmn_kws/exp/finetune_outputs/model.pt.avg10, status: <All keys matched successfully>
rtf_avg: 1.209: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  1.38it/s]
[{'key': 'rand_key_2yW4Acq9GFz6Y', 'text': 'rejected'}]
rtf_avg: 0.071: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 22.94it/s]
[{'key': 'rand_key_1t9EwL56nGisi', 'text': 'rejected'}]
rtf_avg: 0.072: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 22.66it/s]
[{'key': 'rand_key_WgNZq6ITZM5jt', 'text': 'rejected'}]
rtf_avg: 0.076: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 21.54it/s]
[{'key': 'rand_key_gUe52RvEJgwBu', 'text': 'rejected'}]
rtf_avg: 0.069: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 23.77it/s]
[{'key': 'rand_key_NO6n9JEC3HqdZ', 'text': 'rejected'}]
rtf_avg: 0.081: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 20.23it/s]
[{'key': 'rand_key_6J6afU1zT0YQO', 'text': 'rejected'}]
rtf_avg: 0.069: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 23.75it/s]
[{'key': 'rand_key_aNF03vpUuT3em', 'text': 'rejected'}]
rtf_avg: 0.180: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 22.65it/s]
[{'key': 'rand_key_6KopZ9jZICffu', 'text': 'rejected'}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions