diff --git a/.gitattributes b/.gitattributes index 04a53b454822d2ddb58824e18bbea693c303b436..570f0b9741be1ffd4c9a8c8d2cd9c0abe2018479 100644 --- a/.gitattributes +++ b/.gitattributes @@ -34,3 +34,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text model/am_enc.axmodel filter=lfs diff=lfs merge=lfs -text +model/voc.axmodel filter=lfs diff=lfs merge=lfs -text +sdk/axrt/lib/libax_engine.so filter=lfs diff=lfs merge=lfs -text diff --git a/model/host_weights/pitch_blstm_w_hh_r.bin b/model/host_weights/pitch_blstm_w_hh_r.bin new file mode 100644 index 0000000000000000000000000000000000000000..2da4c70bfda3323997cbbc48e5900c51c943ec68 --- /dev/null +++ b/model/host_weights/pitch_blstm_w_hh_r.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bebfb3c4f3bf53dae74ea00dcee4cfd02f6ddd4e84a34eedeed6d065cc38738c +size 262144 diff --git a/model/host_weights/pitch_blstm_w_ih.bin b/model/host_weights/pitch_blstm_w_ih.bin new file mode 100644 index 0000000000000000000000000000000000000000..0bee2002cef6b833a56bc4f55f955a141df25d8e --- /dev/null +++ b/model/host_weights/pitch_blstm_w_ih.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ee8c96cf9a6cf7c46adad0b4307820e18c381bf798d79a5938099e7372012e6 +size 262144 diff --git a/model/host_weights/pitch_blstm_w_ih_r.bin b/model/host_weights/pitch_blstm_w_ih_r.bin new file mode 100644 index 0000000000000000000000000000000000000000..41ebf5282c9b4c5052abc5ea37f06953bb766341 --- /dev/null +++ b/model/host_weights/pitch_blstm_w_ih_r.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ca71682a007aa95d85dea93cbfa9a44194249e72f665bf05e439f8a52359285 +size 262144 diff --git a/model/host_weights/pitch_emb_b.bin b/model/host_weights/pitch_emb_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..a4d41f506c02f3b4b55a1b9aed5a485d830d9566 --- /dev/null +++ b/model/host_weights/pitch_emb_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c7550efbd238394fd6192fe94d0c504e3d987b4bf4f175555b36572f397f84d +size 128 diff --git a/model/host_weights/pitch_emb_w.bin b/model/host_weights/pitch_emb_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..8d955ffce1ba42304641441e30e8c036ad801d5d --- /dev/null +++ b/model/host_weights/pitch_emb_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccdb4861d33a3b4152718a2f3dd69769dfd1454b896fb2b124ad9790b437dc74 +size 1152 diff --git a/model/host_weights/pitch_fc_b.bin b/model/host_weights/pitch_fc_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..5c9ca129952df9c55c6d608a85054732108eff40 --- /dev/null +++ b/model/host_weights/pitch_fc_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4218e2eba8d5f8fac0b94773afe180c739466292a372f58ddca956ec62a07c52 +size 4 diff --git a/model/host_weights/pitch_fc_w.bin b/model/host_weights/pitch_fc_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..baee1fb62a87d567af0b2ef6ff42fb2b90b49040 --- /dev/null +++ b/model/host_weights/pitch_fc_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa457844509d05e9a484d5a51bdc81d1bf1c9475de0c77e4a113b9509c4ad9b7 +size 1024 diff --git a/model/host_weights/pitch_ffn0_b1.bin b/model/host_weights/pitch_ffn0_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..53b40fe5e9b2e89b919f98ed90fdf58a6f2edbc9 --- /dev/null +++ b/model/host_weights/pitch_ffn0_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7ac8cad868f6edb5250c33b968d555801d0f73b8821fb69befe459b9837053e +size 1024 diff --git a/model/host_weights/pitch_ffn0_b2.bin b/model/host_weights/pitch_ffn0_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..c30ec76e65777765c8e1e7545976f86790ed51a1 --- /dev/null +++ b/model/host_weights/pitch_ffn0_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:076a27c79e5ace2a3d47f9dd2e83e4ff6ea8872b3c2218f66c92b89b55f36560 +size 512 diff --git a/model/host_weights/pitch_ffn0_w1.bin b/model/host_weights/pitch_ffn0_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..effbe426f30c95f0a2444657f714e34f92bd550d --- /dev/null +++ b/model/host_weights/pitch_ffn0_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4207c41656057618298828dcad4ba4fe57cc08ea169675c81c84f7363a93139a +size 98304 diff --git a/model/host_weights/pitch_ffn0_w2.bin b/model/host_weights/pitch_ffn0_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..7650357abc86451e1a604199d82d121fb8b3c552 --- /dev/null +++ b/model/host_weights/pitch_ffn0_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59e0867d69bac5ed1e01f33a72439036ce61320b241b7b2da3f06cb8710ead7d +size 131072 diff --git a/model/host_weights/pitch_ffn1_b1.bin b/model/host_weights/pitch_ffn1_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..2839d3438546dffcf0ca1e09e83f2bf7236e7043 --- /dev/null +++ b/model/host_weights/pitch_ffn1_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:240d840ac84faf5b9cb8bd468e7addd7c2830376f0579892ba29f27e136e7279 +size 1024 diff --git a/model/host_weights/pitch_ffn1_b2.bin b/model/host_weights/pitch_ffn1_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..c30ec76e65777765c8e1e7545976f86790ed51a1 --- /dev/null +++ b/model/host_weights/pitch_ffn1_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:076a27c79e5ace2a3d47f9dd2e83e4ff6ea8872b3c2218f66c92b89b55f36560 +size 512 diff --git a/model/host_weights/pitch_ffn1_w1.bin b/model/host_weights/pitch_ffn1_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..118796f3499b0dec2df08a45c68c7b29a5622f01 --- /dev/null +++ b/model/host_weights/pitch_ffn1_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83ac13809722d52f0c095fc93cf22bfce943c84e98f1cf17d15d4fcc8eda42c8 +size 131072 diff --git a/model/host_weights/pitch_ffn1_w2.bin b/model/host_weights/pitch_ffn1_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..cd20d148686fc5e26e3e6f204ffbdd6d3fafdd80 --- /dev/null +++ b/model/host_weights/pitch_ffn1_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b03c73a54bf4dab5bb221cd76563ed608575e4d7f48fdf793954776c83ab3b5a +size 131072 diff --git a/model/host_weights/pitch_ffn2_b1.bin b/model/host_weights/pitch_ffn2_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..2e83b95c2f3270991ebcb273dbaf173c26d605a1 --- /dev/null +++ b/model/host_weights/pitch_ffn2_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a4018a6abe70f329996d08e7baa64821700ef5d130e182080d2ecae43484ce4 +size 1024 diff --git a/model/host_weights/pitch_ffn2_b2.bin b/model/host_weights/pitch_ffn2_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..c30ec76e65777765c8e1e7545976f86790ed51a1 --- /dev/null +++ b/model/host_weights/pitch_ffn2_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:076a27c79e5ace2a3d47f9dd2e83e4ff6ea8872b3c2218f66c92b89b55f36560 +size 512 diff --git a/model/host_weights/pitch_ffn2_w1.bin b/model/host_weights/pitch_ffn2_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..6459e1021ee98ca77895ad5641c6a6ea5917058f --- /dev/null +++ b/model/host_weights/pitch_ffn2_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f159f48f2840d6f81a37616ea9309dcd6ded8caed5d0f52cd7ab64fc1e44f9c +size 131072 diff --git a/model/host_weights/pitch_ffn2_w2.bin b/model/host_weights/pitch_ffn2_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..f07c444c9a4cd909f2b5cfdb64d79cf2e85ff62e --- /dev/null +++ b/model/host_weights/pitch_ffn2_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e05c2e254e8c724e411c9adf4e334f9d4636f741b062243581d2d17d77c48061 +size 131072 diff --git a/model/host_weights/pitch_mem0_conv.bin b/model/host_weights/pitch_mem0_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..7438bdaa0c88defea0bead66e539aec999f68aaa --- /dev/null +++ b/model/host_weights/pitch_mem0_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ad455d7234aea2fac97755b7c1a8a19e7f707a05d8666e4a4c4fc518a0013f0 +size 20992 diff --git a/model/host_weights/pitch_mem1_conv.bin b/model/host_weights/pitch_mem1_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..a09784d517ed450761a1c6d41e4ca1776cd380bf --- /dev/null +++ b/model/host_weights/pitch_mem1_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c580d3dae6f5f3eaf6a4b41bbd4596e44e74bfe3d50b78095f3cb803dea1a2c +size 20992 diff --git a/model/host_weights/pitch_mem2_conv.bin b/model/host_weights/pitch_mem2_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..6950ef538c50e4e233191b8d22b6627f4986e73e --- /dev/null +++ b/model/host_weights/pitch_mem2_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9adca3859e8dfc3a4b2b4c5c7a5f75bf7c49c094ffc482c20c70ac4d8d5d5d64 +size 20992 diff --git a/model/host_weights/pos_enc.bin b/model/host_weights/pos_enc.bin new file mode 100644 index 0000000000000000000000000000000000000000..7359ebdf4fd9ca58ba2e666e21aea0f3af7d1a40 --- /dev/null +++ b/model/host_weights/pos_enc.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df602d3e8496e6fad3fdbb72919833907cef886256fcfa1a822c5ff098bd565b +size 262144 diff --git a/model/host_weights/post_fc_b.bin b/model/host_weights/post_fc_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..f97c1cbc50d68be58346adc5a4811e6968d3eb87 --- /dev/null +++ b/model/host_weights/post_fc_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d5e5e2c3c535b656b2c872c9bdfc12c65533a465dc2c9585c4ba412c506ac51 +size 320 diff --git a/model/host_weights/post_fc_w.bin b/model/host_weights/post_fc_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..456196e4a87e7acb916124be1d9ac4debed767b1 --- /dev/null +++ b/model/host_weights/post_fc_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:09b8f19bce4a509698d4f99a6fb7f2fd3ab8c090de1513a6797a939d675fd6ac +size 40960 diff --git a/model/host_weights/post_ffn0_b1.bin b/model/host_weights/post_ffn0_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..bf37440d7c9371348496d95af5d23573e1497228 --- /dev/null +++ b/model/host_weights/post_ffn0_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef94d5e3f2a0e79c33ae2b96c96b9ebd5d383787c27ecd600eb38ddd77613a76 +size 2048 diff --git a/model/host_weights/post_ffn0_b2.bin b/model/host_weights/post_ffn0_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..abc8240e440587e9d4b59102163573492833ac8a --- /dev/null +++ b/model/host_weights/post_ffn0_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef +size 1024 diff --git a/model/host_weights/post_ffn0_w1.bin b/model/host_weights/post_ffn0_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..3539d811f524f7d9f810e8b0728f1a82fabe4280 --- /dev/null +++ b/model/host_weights/post_ffn0_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08bc3ace0492c871f5645149c2ffcd6915a5aaa85b71a0b2ff180d7f5819067f +size 163840 diff --git a/model/host_weights/post_ffn0_w2.bin b/model/host_weights/post_ffn0_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..1c2ee23ef092e41a0f1cc5a8f21e53e186adbd48 --- /dev/null +++ b/model/host_weights/post_ffn0_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea01a6bca54c04d30a365b8be5e2a411f5f3dd87cd266ce3ab5a11419f9c44a4 +size 524288 diff --git a/model/host_weights/post_ffn1_b1.bin b/model/host_weights/post_ffn1_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..1bf0470a4bce214ca37f62747cfedee0bb9e4df2 --- /dev/null +++ b/model/host_weights/post_ffn1_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f3bb236876a3d7c6bfbd8afa2ca7767d99a6c55fd0b93e237e2b6e9712dcd30 +size 2048 diff --git a/model/host_weights/post_ffn1_b2.bin b/model/host_weights/post_ffn1_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..abc8240e440587e9d4b59102163573492833ac8a --- /dev/null +++ b/model/host_weights/post_ffn1_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef +size 1024 diff --git a/model/host_weights/post_ffn1_w1.bin b/model/host_weights/post_ffn1_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..6b9540083a2900821e0207c00070d1eea4dc7c31 --- /dev/null +++ b/model/host_weights/post_ffn1_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0fa19de8424d4f3853f514cafb31b48d80f60512fb46e1b7e5601c9c9ab51a4 +size 524288 diff --git a/model/host_weights/post_ffn1_w2.bin b/model/host_weights/post_ffn1_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..21d52085951c30e11b2f7ebd90dc659b636e98c2 --- /dev/null +++ b/model/host_weights/post_ffn1_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0f2f562514dcea740253eeb253fab63283f3f9eacf2a8f5dbc2708a7665275a +size 524288 diff --git a/model/host_weights/post_ffn2_b1.bin b/model/host_weights/post_ffn2_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..34cb5729e32cdc5dc078bbfe05b489c3e32cee2f --- /dev/null +++ b/model/host_weights/post_ffn2_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa0ecc1f9c890ab39614146b7a23f506000395c38ac41f86d32fb3e1046a6ef7 +size 2048 diff --git a/model/host_weights/post_ffn2_b2.bin b/model/host_weights/post_ffn2_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..abc8240e440587e9d4b59102163573492833ac8a --- /dev/null +++ b/model/host_weights/post_ffn2_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef +size 1024 diff --git a/model/host_weights/post_ffn2_w1.bin b/model/host_weights/post_ffn2_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..a3a4a2506dc3dde8f2c05da1cce3e15b69d61958 --- /dev/null +++ b/model/host_weights/post_ffn2_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d543c4ada85df0414c8f1d7d2fde31304d980b21b61d37594a580909d2de0f0 +size 524288 diff --git a/model/host_weights/post_ffn2_w2.bin b/model/host_weights/post_ffn2_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..4ccb4d415472ffbb0fe8cb73783ef5ad62ce22bd --- /dev/null +++ b/model/host_weights/post_ffn2_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07fd20b73638f4ab0d1474c217232a9160551937050e4a0ee609f5a37344b502 +size 524288 diff --git a/model/host_weights/post_ffn3_b1.bin b/model/host_weights/post_ffn3_b1.bin new file mode 100644 index 0000000000000000000000000000000000000000..c26a5ec4a5e26069181ed85691addddc5b1cd70e --- /dev/null +++ b/model/host_weights/post_ffn3_b1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:145df1464e137352a9de4ea3f9f0d827e3e865e710a565b3382abfbd50b09bdd +size 2048 diff --git a/model/host_weights/post_ffn3_b2.bin b/model/host_weights/post_ffn3_b2.bin new file mode 100644 index 0000000000000000000000000000000000000000..abc8240e440587e9d4b59102163573492833ac8a --- /dev/null +++ b/model/host_weights/post_ffn3_b2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef +size 1024 diff --git a/model/host_weights/post_ffn3_w1.bin b/model/host_weights/post_ffn3_w1.bin new file mode 100644 index 0000000000000000000000000000000000000000..4ef4dd48de7da4c225281cc1c2e8d0160e00d2b7 --- /dev/null +++ b/model/host_weights/post_ffn3_w1.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e415f0903db09f50bc335e2fe6664366f1d0f3ca666abba59915f72d6e502878 +size 524288 diff --git a/model/host_weights/post_ffn3_w2.bin b/model/host_weights/post_ffn3_w2.bin new file mode 100644 index 0000000000000000000000000000000000000000..ee7d912d15fb14bac33a65bb8aed2fb5dcac227f --- /dev/null +++ b/model/host_weights/post_ffn3_w2.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fc6bec673b62b1a9410d73a0d4f7776da999023610605eaecdb13b32e8a7eb8 +size 524288 diff --git a/model/host_weights/post_lstm_b_hh.bin b/model/host_weights/post_lstm_b_hh.bin new file mode 100644 index 0000000000000000000000000000000000000000..aeb4b26e0a76410fa1d162730fe1882dd7a3314f --- /dev/null +++ b/model/host_weights/post_lstm_b_hh.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5a00aa9991ac8a5ee3109844d84a55583bd20572ad3ffcd42792f3c36b183ad +size 2048 diff --git a/model/host_weights/post_lstm_b_ih.bin b/model/host_weights/post_lstm_b_ih.bin new file mode 100644 index 0000000000000000000000000000000000000000..c0b0df5515ffdbd972790004fc16eb6732ca4ab4 --- /dev/null +++ b/model/host_weights/post_lstm_b_ih.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f2b8a6ccb1980785a8eb1c59328143f5a3cfad6450b2ee119ef113c89745133 +size 2048 diff --git a/model/host_weights/post_lstm_w_hh.bin b/model/host_weights/post_lstm_w_hh.bin new file mode 100644 index 0000000000000000000000000000000000000000..8c27d6ada71c9b5705f832c2f7cb68dcac3ac615 --- /dev/null +++ b/model/host_weights/post_lstm_w_hh.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:21e03c2d2c8557f992edb80f2745373bb840f0bac42e3a77127a702d32d192ac +size 262144 diff --git a/model/host_weights/post_lstm_w_ih.bin b/model/host_weights/post_lstm_w_ih.bin new file mode 100644 index 0000000000000000000000000000000000000000..064b238421ef73fbac311c1765a9a9b636fc4878 --- /dev/null +++ b/model/host_weights/post_lstm_w_ih.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:391ac2a71817eb8fc25ac37a80da9f3e7323c8c787d858c4164cef9e8a1be925 +size 524288 diff --git a/model/host_weights/post_mem0_conv.bin b/model/host_weights/post_mem0_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..8dd4f95cab78527cc18893733257134c519d9ad6 --- /dev/null +++ b/model/host_weights/post_mem0_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2da93a32b44f37d1d4c048d77eb68e99b2ed9f9ed07e5f4de247825fd4fe839 +size 41984 diff --git a/model/host_weights/post_mem1_conv.bin b/model/host_weights/post_mem1_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..01bc4606999e88ccc5bab84c4374a51976d6a56c --- /dev/null +++ b/model/host_weights/post_mem1_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31db5877bb42d6dc46c6c59050729683227df3bc6e6b3686ac1a6f7ebf5c987e +size 41984 diff --git a/model/host_weights/post_mem2_conv.bin b/model/host_weights/post_mem2_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..6c71f790f83c8acc6c6ea77271c9b553ca5a4867 --- /dev/null +++ b/model/host_weights/post_mem2_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f7981139bc8fe93723224843d50a58385dae5490af0d2f9666f2c6a16711ea6 +size 41984 diff --git a/model/host_weights/post_mem3_conv.bin b/model/host_weights/post_mem3_conv.bin new file mode 100644 index 0000000000000000000000000000000000000000..243e3d05d0071b454a9552e55f956ca7b84756ff --- /dev/null +++ b/model/host_weights/post_mem3_conv.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9270e32737a21eff05dd782734fcbd602c3010758dbb935dd1144995ccea8845 +size 41984 diff --git a/model/host_weights/pre0_b.bin b/model/host_weights/pre0_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..a05cbf864d38013a23cc25106135cfef498a2f73 --- /dev/null +++ b/model/host_weights/pre0_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d7b4ec4a5bed05fabc79e1e41b9d70d499933372a30cae392256061048f2f33 +size 1024 diff --git a/model/host_weights/pre0_w.bin b/model/host_weights/pre0_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..42e4795168bde9b66255829c52cfe925672339eb --- /dev/null +++ b/model/host_weights/pre0_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a28c96b1be71eaa2ea8956501858e561ce364a9ae1ae37a4872de74afcc65bde +size 81920 diff --git a/model/host_weights/pre1_b.bin b/model/host_weights/pre1_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..471743c6a69f8713a1054783f7a12e6edaa1e088 --- /dev/null +++ b/model/host_weights/pre1_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7137bc76dd9bbc1ee61044aad3eb7b1787740822f8e5f72da1a9ce42f5f6ea61 +size 1024 diff --git a/model/host_weights/pre1_w.bin b/model/host_weights/pre1_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..30526403aea25a59d5712c021915d8f098b2832a --- /dev/null +++ b/model/host_weights/pre1_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f870209232649fe16056f672d7b357b0ef8ad16b3d4d80fe50954450de37801 +size 262144 diff --git a/model/host_weights/pre2_b.bin b/model/host_weights/pre2_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..b9a4fad15345f949f72d6730a5903cc1d76d8838 --- /dev/null +++ b/model/host_weights/pre2_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36731f703efd9f5034634b0f1b3863f5e05a67871691af5f27d3231c0103bdce +size 512 diff --git a/model/host_weights/pre2_w.bin b/model/host_weights/pre2_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..ef0e68fc202f8003ef8abbf535568610dd9d6421 --- /dev/null +++ b/model/host_weights/pre2_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ef732efe39bf0135197e69076574921afae57a2322f797d3316e29a82b4de1c +size 131072 diff --git a/model/host_weights/proj_b.bin b/model/host_weights/proj_b.bin new file mode 100644 index 0000000000000000000000000000000000000000..55dc419f276b7ae82ae78a91bd087f691cd35cdf --- /dev/null +++ b/model/host_weights/proj_b.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de61d4d7ae812e7ba88143af6a5ba896efbc755db14f15eda8061d1d8c868d89 +size 512 diff --git a/model/host_weights/proj_w.bin b/model/host_weights/proj_w.bin new file mode 100644 index 0000000000000000000000000000000000000000..1930e67926a7c107c4d8dd7dfade142e4ecfa9b3 --- /dev/null +++ b/model/host_weights/proj_w.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff830595077d2e4f92e3f553fc98bd86c5328693f87867446c8f3fff700da5cb +size 147456 diff --git a/model/host_weights/spk_emb.bin b/model/host_weights/spk_emb.bin new file mode 100644 index 0000000000000000000000000000000000000000..c3b14ca5962bfd3883161d5134cc4ff65edb3fd5 --- /dev/null +++ b/model/host_weights/spk_emb.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00c92c44e4f6a019bde0728277180caf636baae94e076c3011573654f51c74b6 +size 1152 diff --git a/model/host_weights/sy_emb.bin b/model/host_weights/sy_emb.bin new file mode 100644 index 0000000000000000000000000000000000000000..4c6ff7352c2f2187e8fd365f403c07b54eefe96a --- /dev/null +++ b/model/host_weights/sy_emb.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28a08f9d6a0c00b301598dbbe4bf040a90077fd924a967cf3322efd1faa4a5ec +size 301056 diff --git a/model/host_weights/syll_emb.bin b/model/host_weights/syll_emb.bin new file mode 100644 index 0000000000000000000000000000000000000000..865c16c627ec8bdf4bbaf7d02a8f844e8dedd7d6 --- /dev/null +++ b/model/host_weights/syll_emb.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9dec2d8247596c55a72b3275ae36b8df662628c0c4d5870ff78bef32ec7db0ba +size 16384 diff --git a/model/host_weights/tone_emb.bin b/model/host_weights/tone_emb.bin new file mode 100644 index 0000000000000000000000000000000000000000..216caeadbda4de554b155105711fccf2e440a6b5 --- /dev/null +++ b/model/host_weights/tone_emb.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0b115995bb3b47898c7dab5b9ec98a5ef51f8fe8b5007c9b2ff691e8c7521b6 +size 20480 diff --git a/model/host_weights/ws_emb.bin b/model/host_weights/ws_emb.bin new file mode 100644 index 0000000000000000000000000000000000000000..d53af5f2e2c9341afeb55eb5adec4f3b1ad2e49e --- /dev/null +++ b/model/host_weights/ws_emb.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29261bff3e0707e6314c129bfd59433988fd666d52e5b23e1d4b500d63559a4a +size 16384 diff --git a/model/resource/PinYin/PhoneSet.xml b/model/resource/PinYin/PhoneSet.xml new file mode 100644 index 0000000000000000000000000000000000000000..4e685e21c2b5fdfee44d6316bc89fa6f59745427 --- /dev/null +++ b/model/resource/PinYin/PhoneSet.xml @@ -0,0 +1,1263 @@ + + + + 0 + a_c + vowel + final + voiced + low + open + + + 1 + ai_c + vowel + final + voiced + low + open + + + 2 + an_c + vowel + final + voiced + low + open + + + 3 + ang_c + vowel + final + voiced + low + open + + + 4 + ao_c + vowel + final + voiced + low + open + + + 5 + b_c + vowel + initial + unvoiced + low + open + + + 6 + c_c + vowel + initial + unvoiced + low + open + + + 7 + ch_c + vowel + initial + unvoiced + low + open + + + 8 + d_c + vowel + initial + unvoiced + low + open + + + 9 + e_c + vowel + final + voiced + low + open + + + 10 + ei_c + vowel + final + voiced + low + open + + + 11 + en_c + vowel + final + voiced + low + open + + + 12 + eng_c + vowel + final + voiced + doublelips + stop + + + 13 + er_c + vowel + final + voiced + doublelips + stop + + + 14 + f_c + vowel + initial + unvoiced + doublelips + stop + + + 15 + g_c + vowel + initial + unvoiced + fronttongue + affricative + + + 16 + h_c + vowel + initial + unvoiced + backtongue + affricative + + + 17 + i_c + vowel + final + voiced + backtongue + affricative + + + 18 + ia_c + vowel + final + voiced + fronttongue + affricative + + + 19 + ian_c + vowel + final + voiced + centraltongue + stop + + + 20 + iang_c + vowel + final + voiced + centraltongue + stop + + + 21 + iao_c + vowel + final + voiced + centraltongue + stop + + + 22 + ie_c + vowel + final + voiced + middle + open + + + 23 + ih_c + vowel + final + voiced + middle + open + + + 24 + ii_c + vowel + final + voiced + middle + open + + + 25 + in_c + vowel + final + voiced + middle + open + + + 26 + ing_c + vowel + final + voiced + middle + open + + + 27 + io_c + vowel + final + voiced + middle + open + + + 28 + iong_c + vowel + final + voiced + middle + open + + + 29 + iou_c + vowel + final + voiced + middle + open + + + 30 + j_c + vowel + initial + unvoiced + middle + open + + + 31 + k_c + vowel + initial + unvoiced + middle + open + + + 32 + l_c + vowel + initial + voiced + middle + open + + + 33 + m_c + vowel + initial + voiced + middle + open + + + 34 + n_c + vowel + initial + voiced + middle + open + + + 35 + o_c + vowel + final + voiced + middle + open + + + 36 + ong_c + vowel + final + voiced + middle + open + + + 37 + ou_c + vowel + final + voiced + middle + open + + + 38 + p_c + vowel + initial + unvoiced + liptooth + fricative + + + 39 + q_c + vowel + initial + unvoiced + liptooth + fricative + + + 40 + r_c + vowel + initial + voiced + velar + stop + + + 41 + s_c + vowel + initial + unvoiced + low + open + + + 42 + sh_c + vowel + initial + unvoiced + middle + open + + + 43 + t_c + vowel + initial + unvoiced + middle + open + + + 44 + u_c + vowel + final + voiced + velar + stop + + + 45 + ua_c + vowel + final + voiced + velar + fricative + + + 46 + uai_c + vowel + final + voiced + velar + fricative + + + 47 + uan_c + vowel + final + voiced + high + close + + + 48 + uang_c + vowel + final + voiced + high + close + + + 49 + uei_c + vowel + final + voiced + high + close + + + 50 + uen_c + vowel + final + voiced + high + open + + + 51 + ueng_c + vowel + final + voiced + high + open + + + 52 + uo_c + vowel + final + voiced + high + open + + + 53 + v_c + vowel + final + voiced + high + open + + + 54 + van_c + vowel + final + voiced + high + open + + + 55 + ve_c + vowel + final + voiced + high + open + + + 56 + vn_c + vowel + final + voiced + high + open + + + 57 + xx_c + vowel + initial + unvoiced + high + close + + + 58 + z_c + vowel + initial + unvoiced + high + close + + + 59 + zh_c + vowel + initial + unvoiced + high + close + + + 60 + w_c + consonant + initial + unvoiced + high + close + + + 61 + y_c + consonant + initial + unvoiced + high + close + + + 62 + ga + consonant + initial + voiced + centraltongue + lateral + + + 63 + ge + consonant + initial + voiced + centraltongue + lateral + + + 64 + go + consonant + initial + voiced + centraltongue + lateral + + + 65 + aa + vowel + final + voiced + fronttongue + affricative + + + 66 + ae + vowel + final + voiced + fronttongue + affricative + + + 67 + ah + vowel + final + voiced + fronttongue + affricative + + + 68 + ao + vowel + final + voiced + fronttongue + affricative + + + 69 + aw + vowel + final + voiced + fronttongue + affricative + + + 70 + ay + vowel + final + voiced + fronttongue + affricative + + + 71 + b + consonant + initial + unvoiced + doublelips + stop + + + 72 + ch + consonant + initial + unvoiced + backtongue + affricative + + + 73 + d + consonant + initial + unvoiced + centraltongue + stop + + + 74 + dh + consonant + initial + unvoiced + fronttongue + affricative + + + 75 + eh + vowel + final + voiced + fronttongue + affricative + + + 76 + er + vowel + final + voiced + fronttongue + affricative + + + 77 + ey + vowel + final + voiced + fronttongue + affricative + + + 78 + f + consonant + initial + unvoiced + liptooth + fricative + + + 79 + g + consonant + initial + unvoiced + velar + stop + + + 80 + hh + consonant + initial + unvoiced + fronttongue + affricative + + + 81 + ih + vowel + final + voiced + fronttongue + affricative + + + 82 + iy + vowel + final + voiced + fronttongue + affricative + + + 83 + jh + consonant + initial + unvoiced + fronttongue + affricative + + + 84 + k + consonant + initial + unvoiced + velar + stop + + + 85 + l + consonant + initial + voiced + centraltongue + lateral + + + 86 + m + consonant + initial + voiced + doublelips + nasal + + + 87 + n + consonant + initial + voiced + centraltongue + nasal + + + 88 + ng + consonant + final + voiced + fronttongue + affricative + + + 89 + ow + vowel + final + voiced + fronttongue + affricative + + + 90 + oy + vowel + final + voiced + fronttongue + affricative + + + 91 + p + consonant + initial + unvoiced + doublelips + stop + + + 92 + r + consonant + initial + voiced + backtongue + fricative + + + 93 + s + consonant + initial + unvoiced + fronttongue + fricative + + + 94 + sh + consonant + initial + unvoiced + backtongue + fricative + + + 95 + t + consonant + initial + unvoiced + centraltongue + stop + + + 96 + th + consonant + initial + unvoiced + fronttongue + affricative + + + 97 + uh + vowel + final + voiced + fronttongue + affricative + + + 98 + uw + vowel + final + voiced + fronttongue + affricative + + + 99 + v + consonant + initial + unvoiced + fronttongue + affricative + + + 100 + w + consonant + initial + unvoiced + fronttongue + affricative + + + 101 + y + consonant + final + voiced + fronttongue + affricative + + + 102 + z + consonant + initial + unvoiced + fronttongue + affricative + + + 103 + zh + consonant + initial + unvoiced + backtongue + affricative + + + 104 + air_c + vowel + final + voiced + low + open + + + 105 + angr_c + vowel + final + voiced + low + open + + + 106 + anr_c + vowel + final + voiced + low + open + + + 107 + aor_c + vowel + final + voiced + low + open + + + 108 + ar_c + vowel + final + voiced + low + open + + + 109 + eir_c + vowel + final + voiced + low + open + + + 110 + engr_c + vowel + final + voiced + doublelips + stop + + + 111 + enr_c + vowel + final + voiced + low + open + + + 112 + iangr_c + vowel + final + voiced + centraltongue + stop + + + 113 + ianr_c + vowel + final + voiced + centraltongue + stop + + + 114 + iaor_c + vowel + final + voiced + centraltongue + stop + + + 115 + iar_c + vowel + final + voiced + fronttongue + affricative + + + 116 + ier_c + vowel + final + voiced + middle + open + + + 117 + ihr_c + vowel + final + voiced + middle + open + + + 118 + iir_c + vowel + final + voiced + middle + open + + + 119 + ingr_c + vowel + final + voiced + middle + open + + + 120 + inr_c + vowel + final + voiced + middle + open + + + 121 + iongr_c + vowel + final + voiced + middle + open + + + 122 + iour_c + vowel + final + voiced + middle + open + + + 123 + ir_c + vowel + final + voiced + backtongue + affricative + + + 124 + ongr_c + vowel + final + voiced + middle + open + + + 125 + or_c + vowel + final + voiced + middle + open + + + 126 + our_c + vowel + final + voiced + middle + open + + + 127 + uair_c + vowel + final + voiced + velar + fricative + + + 128 + uangr_c + vowel + final + voiced + high + close + + + 129 + uanr_c + vowel + final + voiced + high + close + + + 130 + uar_c + vowel + final + voiced + velar + fricative + + + 131 + ueir_c + vowel + final + voiced + high + close + + + 132 + uenr_c + vowel + final + voiced + high + open + + + 133 + uor_c + vowel + final + voiced + high + open + + + 134 + ur_c + vowel + final + voiced + velar + stop + + + 135 + vanr_c + vowel + final + voiced + high + open + + + 136 + ver_c + vowel + final + voiced + high + open + + + 137 + vnr_c + vowel + final + voiced + high + open + + + 138 + vr_c + vowel + final + voiced + high + open + + + 146 + pau + consonant + initial + unvoiced + high + close + + diff --git a/model/resource/PinYin/tonelist.txt b/model/resource/PinYin/tonelist.txt new file mode 100644 index 0000000000000000000000000000000000000000..7741d23307af10cba518e3d15b5892db25b67e78 --- /dev/null +++ b/model/resource/PinYin/tonelist.txt @@ -0,0 +1,7 @@ +1 + +4 +2 +3 +5 +0 diff --git a/model/voc.axmodel b/model/voc.axmodel new file mode 100644 index 0000000000000000000000000000000000000000..511f1ec7b7806acce8fe70645d106d2b1c3f004d --- /dev/null +++ b/model/voc.axmodel @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55108d50ae7b2c4c4dc40b5f7ed84156e0a61dcd7822763cb70f7f3e0317e2dc +size 7044670 diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba24d790ce72b4234381a3d0f6e93acfac7efa75 --- /dev/null +++ b/sdk/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.15) +project(kantts_sdk LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(include ${AX_RUNTIME_ROOT}/include) +link_directories(${AX_RUNTIME_ROOT}/lib) + +add_library(kantts_tts STATIC + src/ax_engine.cpp + src/kantts.cpp +) +target_include_directories(kantts_tts PUBLIC include) +target_link_libraries(kantts_tts PRIVATE ax_engine ax_sys pthread) + +add_executable(kantts_tts_example src/main.cpp) +target_link_libraries(kantts_tts_example PRIVATE kantts_tts ax_engine ax_sys) diff --git a/sdk/axrt/include/ax_base_type.h b/sdk/axrt/include/ax_base_type.h new file mode 100644 index 0000000000000000000000000000000000000000..3d32b72f142d89e2ba72d76e445904e0345cd257 --- /dev/null +++ b/sdk/axrt/include/ax_base_type.h @@ -0,0 +1,41 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_BASE_TYPE_H_ +#define _AX_BASE_TYPE_H_ + +/* types of variables typedef */ +typedef unsigned long long int AX_U64; +typedef unsigned int AX_U32; +typedef unsigned short AX_U16; +typedef unsigned char AX_U8; +typedef long long int AX_S64; +typedef int AX_S32; +typedef short AX_S16; +typedef signed char AX_S8; +typedef char AX_CHAR; +typedef long AX_LONG; +typedef unsigned long AX_ULONG; +typedef unsigned long AX_ADDR; +typedef float AX_F32; +typedef double AX_F64; +typedef void AX_VOID; +typedef unsigned int AX_SIZE_T; + +typedef enum { + AX_FALSE = 0, + AX_TRUE = 1, +} AX_BOOL; + +#ifndef AX_NULL + #define AX_NULL 0 +#endif + +#endif //_AX_BASE_TYPE_H_ diff --git a/sdk/axrt/include/ax_buffer_tool.h b/sdk/axrt/include/ax_buffer_tool.h new file mode 100644 index 0000000000000000000000000000000000000000..6978aca392c75d912dbd8777f77fda022d70a4c0 --- /dev/null +++ b/sdk/axrt/include/ax_buffer_tool.h @@ -0,0 +1,277 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_BUFFER_TOOL_H_ +#define _AX_BUFFER_TOOL_H_ + +#include "ax_base_type.h" +#include "ax_global_type.h" + +#ifdef __cplusplus +extern "C" { +#endif /* End of #ifdef __cplusplus */ + +#define AX_COMM_ALIGN(value, n) (((value) + (n) - 1) & ~((n) - 1)) + +static __inline AX_U32 AX_VIN_GetImgBufferSize(AX_U32 uHeight, AX_U32 uWidth, AX_IMG_FORMAT_E eImageFormat, + AX_FRAME_COMPRESS_INFO_T *pstCompressInfo, AX_U32 uAlignSize) +{ + AX_U32 uWidthBeat = 0; + AX_U32 uBufSize = 0; + AX_U32 uPixBits = 0; + AX_BOOL bFormatYuv = AX_TRUE; + + switch (eImageFormat) { + case AX_FORMAT_BAYER_RAW_8BPP: + uPixBits = 8; + break; + case AX_FORMAT_BAYER_RAW_10BPP: + uPixBits = 10; + break; + case AX_FORMAT_BAYER_RAW_12BPP: + uPixBits = 12; + break; + case AX_FORMAT_BAYER_RAW_14BPP: + uPixBits = 14; + break; + case AX_FORMAT_BAYER_RAW_16BPP: + uPixBits = 16; + break; + case AX_FORMAT_YUV400: + case AX_FORMAT_YUV420_PLANAR: + case AX_FORMAT_YUV420_PLANAR_VU: + case AX_FORMAT_YUV420_SEMIPLANAR: + case AX_FORMAT_YUV420_SEMIPLANAR_VU: + case AX_FORMAT_YUV422_PLANAR: + case AX_FORMAT_YUV422_PLANAR_VU: + case AX_FORMAT_YUV422_SEMIPLANAR: + case AX_FORMAT_YUV422_SEMIPLANAR_VU: + case AX_FORMAT_YUV422_INTERLEAVED_YUVY: + case AX_FORMAT_YUV422_INTERLEAVED_YUYV: + case AX_FORMAT_YUV422_INTERLEAVED_UYVY: + case AX_FORMAT_YUV422_INTERLEAVED_VYUY: + case AX_FORMAT_YUV444_PLANAR: + case AX_FORMAT_YUV444_PLANAR_VU: + case AX_FORMAT_YUV444_SEMIPLANAR: + case AX_FORMAT_YUV444_SEMIPLANAR_VU: + case AX_FORMAT_YUV444_PACKED: + uPixBits = 8; + break; + case AX_FORMAT_YUV400_10BIT: + case AX_FORMAT_YUV420_PLANAR_10BIT_UV_PACKED_4Y5B: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P101010: + case AX_FORMAT_YUV444_PACKED_10BIT_P101010: + uPixBits = 10; + break; + case AX_FORMAT_YUV420_PLANAR_10BIT_I010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P016: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_I016: + case AX_FORMAT_YUV444_PACKED_10BIT_P010: + uPixBits = 16; + break; + default: + uPixBits = 8; + break; + } + if (((uWidth * uPixBits) % 128) != 0) { + uWidthBeat = ((uWidth * uPixBits) / 128) + 1; + } else { + uWidthBeat = (uWidth * uPixBits) / 128 ; + } + + if (uAlignSize != 0) { + uWidthBeat = ((uWidthBeat * 16 * uAlignSize) + uAlignSize - 1) / uAlignSize; + uWidthBeat = uWidthBeat / 16; + } else { + uWidthBeat = ((uWidthBeat * 16 * 128) + 127) / 128; + uWidthBeat = uWidthBeat / 16; + } + + // calc dma buffer size + switch (eImageFormat) { + case AX_FORMAT_BAYER_RAW_8BPP: + case AX_FORMAT_BAYER_RAW_10BPP: + case AX_FORMAT_BAYER_RAW_12BPP: + case AX_FORMAT_BAYER_RAW_14BPP: + case AX_FORMAT_BAYER_RAW_16BPP: + uBufSize = uWidthBeat * 16 * uHeight; + bFormatYuv = AX_FALSE; + break; + case AX_FORMAT_YUV400: + case AX_FORMAT_YUV400_10BIT: + uBufSize = uWidthBeat * 16 * uHeight; + break; + case AX_FORMAT_YUV420_PLANAR: + case AX_FORMAT_YUV420_PLANAR_VU: + case AX_FORMAT_YUV420_SEMIPLANAR: + case AX_FORMAT_YUV420_SEMIPLANAR_VU: + case AX_FORMAT_YUV420_PLANAR_10BIT_UV_PACKED_4Y5B: + case AX_FORMAT_YUV420_PLANAR_10BIT_I010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P101010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P016: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_I016: + uBufSize = uWidthBeat * 16 * uHeight * 3 / 2; + break; + case AX_FORMAT_YUV422_PLANAR: + case AX_FORMAT_YUV422_PLANAR_VU: + case AX_FORMAT_YUV422_SEMIPLANAR: + case AX_FORMAT_YUV422_SEMIPLANAR_VU: + case AX_FORMAT_YUV422_INTERLEAVED_YUVY: + case AX_FORMAT_YUV422_INTERLEAVED_YUYV: + case AX_FORMAT_YUV422_INTERLEAVED_UYVY: + case AX_FORMAT_YUV422_INTERLEAVED_VYUY: + uBufSize = uWidthBeat * 16 * uHeight * 2; + break; + case AX_FORMAT_YUV444_PLANAR: + case AX_FORMAT_YUV444_PLANAR_VU: + case AX_FORMAT_YUV444_SEMIPLANAR: + case AX_FORMAT_YUV444_SEMIPLANAR_VU: + case AX_FORMAT_YUV444_PACKED: + case AX_FORMAT_YUV444_PACKED_10BIT_P010: + case AX_FORMAT_YUV444_PACKED_10BIT_P101010: + uBufSize = uWidthBeat * 16 * uHeight * 3; + break; + default: + uBufSize = uWidthBeat * 16 * uHeight * 3 / 2; + break; + } + + if (pstCompressInfo != AX_NULL) { + if (pstCompressInfo->enCompressMode == AX_COMPRESS_MODE_LOSSLESS) { + if (bFormatYuv == AX_TRUE) { + uBufSize += uHeight * 96; /* add the header buf for compress data */ + } else { + uBufSize += uHeight * 32; /* add the header buf for compress data */ + } + } else if (pstCompressInfo->enCompressMode == AX_COMPRESS_MODE_LOSSY) { + if (bFormatYuv == AX_TRUE) { + if ((0 != pstCompressInfo->u32CompressLevel) && (10 >= pstCompressInfo->u32CompressLevel)) { + if (8 == uPixBits) { + if (pstCompressInfo->u32CompressLevel <= 8) { + uBufSize = uBufSize * pstCompressInfo->u32CompressLevel * 0.125; + } + } else if (10 == uPixBits) { + uBufSize = uBufSize * pstCompressInfo->u32CompressLevel * 0.1; + } else { + //do nothing + } + } + } + } else { + //without fbc + } + } + + return uBufSize; +} + + +static __inline AX_U32 AX_VDEC_GetPicBufferSize(AX_U32 uWidth, AX_U32 uHeight, AX_IMG_FORMAT_E eOutputFormat, + AX_FRAME_COMPRESS_INFO_T *pstCompressInfo, AX_U32 uAlignSize, + AX_PAYLOAD_TYPE_E enType) +{ + AX_U32 picSizeInMbs = 0; + AX_U32 picSize = 0; + AX_U32 dmvMemSize = 0; + AX_U32 refBuffSize = 0; + AX_U32 uPixBits = 8; + AX_U32 uBufSize = 0; + AX_U32 uHeightAlign = 0; + AX_U32 uWidthAlign = 0; + + + // picSizeInMbs = (AX_COMM_ALIGN(uHeight, 16) >> 4) * (AX_COMM_ALIGN(uWidth, 16) >> 4); + if ((PT_H264 == enType) || (PT_H265 == enType)) { + switch (eOutputFormat) { + case AX_FORMAT_YUV400: + case AX_FORMAT_YUV420_PLANAR: + case AX_FORMAT_YUV420_PLANAR_VU: + case AX_FORMAT_YUV420_SEMIPLANAR: + case AX_FORMAT_YUV420_SEMIPLANAR_VU: + case AX_FORMAT_YUV422_PLANAR: + case AX_FORMAT_YUV422_PLANAR_VU: + case AX_FORMAT_YUV422_SEMIPLANAR: + case AX_FORMAT_YUV422_SEMIPLANAR_VU: + case AX_FORMAT_YUV422_INTERLEAVED_YUVY: + case AX_FORMAT_YUV422_INTERLEAVED_YUYV: + case AX_FORMAT_YUV422_INTERLEAVED_UYVY: + case AX_FORMAT_YUV422_INTERLEAVED_VYUY: + case AX_FORMAT_YUV444_PLANAR: + case AX_FORMAT_YUV444_PLANAR_VU: + case AX_FORMAT_YUV444_SEMIPLANAR: + case AX_FORMAT_YUV444_SEMIPLANAR_VU: + case AX_FORMAT_YUV444_PACKED: + uPixBits = 8; + break; + case AX_FORMAT_YUV400_10BIT: + case AX_FORMAT_YUV420_PLANAR_10BIT_UV_PACKED_4Y5B: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P101010: + case AX_FORMAT_YUV444_PACKED_10BIT_P101010: + uPixBits = 10; + break; + case AX_FORMAT_YUV420_PLANAR_10BIT_I010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P010: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P016: + case AX_FORMAT_YUV420_SEMIPLANAR_10BIT_I016: + case AX_FORMAT_YUV444_PACKED_10BIT_P010: + uPixBits = 16; + break; + default: + uPixBits = 8; + break; + } + + uHeightAlign = AX_COMM_ALIGN(uHeight, 64); // TBD ... + uWidthAlign = AX_COMM_ALIGN(uWidth, uAlignSize); + picSize = (uHeightAlign * uWidthAlign * 3) >> 1; // TBD ... + + /* buffer size of dpb pic = picSize + dir_mv_size + tbl_size */ + dmvMemSize = picSizeInMbs * 64; + refBuffSize = picSize + dmvMemSize + 32; + } else if ((PT_JPEG == enType) || (PT_MJPEG == enType)) { + picSize = (AX_COMM_ALIGN(uHeight, 16) * AX_COMM_ALIGN(uWidth, 16) * 3) >> 1; + refBuffSize = picSize; + } else { + refBuffSize = -1; + } + + if (pstCompressInfo != AX_NULL) { + if (pstCompressInfo->enCompressMode == AX_COMPRESS_MODE_LOSSLESS) { + refBuffSize = -1; // AX650 VDEC unsupport fbc lossless mode + } else if (pstCompressInfo->enCompressMode == AX_COMPRESS_MODE_LOSSY) { + if ((0 != pstCompressInfo->u32CompressLevel) && (10 >= pstCompressInfo->u32CompressLevel)) { + if (8 == uPixBits) { + if (pstCompressInfo->u32CompressLevel <= 8) { + uBufSize = uBufSize * pstCompressInfo->u32CompressLevel * 0.125; + } + } else if (10 == uPixBits) { + uBufSize = uBufSize * pstCompressInfo->u32CompressLevel * 0.1; + } else { + //do nothing + } + } + } else { + //without fbc + } + } + + + return refBuffSize; +} + + + +#ifdef __cplusplus +} +#endif /* End of #ifdef __cplusplus */ + +#endif //_AX_BUFFER_TOOL_H_ diff --git a/sdk/axrt/include/ax_engine_api.h b/sdk/axrt/include/ax_engine_api.h new file mode 100644 index 0000000000000000000000000000000000000000..ff25a860aa9f30d2173ac69719c6f0560fc600d2 --- /dev/null +++ b/sdk/axrt/include/ax_engine_api.h @@ -0,0 +1,58 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +DLLEXPORT const AX_CHAR* AX_ENGINE_GetVersion(AX_VOID); + +DLLEXPORT AX_VOID AX_ENGINE_NPUReset(AX_VOID); + +DLLEXPORT AX_S32 AX_ENGINE_Init(AX_ENGINE_NPU_ATTR_T* pNpuAttr); +DLLEXPORT AX_S32 AX_ENGINE_GetVNPUAttr(AX_ENGINE_NPU_ATTR_T* pNpuAttr); +DLLEXPORT AX_S32 AX_ENGINE_Deinit(AX_VOID); + +DLLEXPORT AX_S32 AX_ENGINE_GetModelType(const AX_VOID* pData, AX_U32 nDataSize, AX_ENGINE_MODEL_TYPE_T* pModelType); + +DLLEXPORT AX_S32 AX_ENGINE_CreateHandle(AX_ENGINE_HANDLE *pHandle, const AX_VOID *pData, AX_U32 nDataSize); +DLLEXPORT AX_S32 AX_ENGINE_CreateHandleV2(AX_ENGINE_HANDLE* pHandle, const AX_VOID* pData, AX_U32 nDataSize, AX_ENGINE_HANDLE_EXTRA_T* pExtraParam); +DLLEXPORT AX_S32 AX_ENGINE_DestroyHandle(AX_ENGINE_HANDLE nHandle); + +DLLEXPORT AX_S32 AX_ENGINE_GetIOInfo(AX_ENGINE_HANDLE nHandle, AX_ENGINE_IO_INFO_T** pIO); +DLLEXPORT AX_S32 AX_ENGINE_GetGroupIOInfoCount(AX_ENGINE_HANDLE nHandle, AX_U32* pCount); +DLLEXPORT AX_S32 AX_ENGINE_GetGroupIOInfo(AX_ENGINE_HANDLE nHandle, AX_U32 nIndex, AX_ENGINE_IO_INFO_T** pIO); + +DLLEXPORT AX_S32 AX_ENGINE_GetHandleModelType(AX_ENGINE_HANDLE nHandle, AX_ENGINE_MODEL_TYPE_T* pModelType); + +DLLEXPORT AX_S32 AX_ENGINE_CreateContext(AX_ENGINE_HANDLE handle); +DLLEXPORT AX_S32 AX_ENGINE_CreateContextV2(AX_ENGINE_HANDLE nHandle, AX_ENGINE_CONTEXT_T* pContext); + +DLLEXPORT AX_S32 AX_ENGINE_RunSync(AX_ENGINE_HANDLE handle, AX_ENGINE_IO_T* pIO); +DLLEXPORT AX_S32 AX_ENGINE_RunSyncV2(AX_ENGINE_HANDLE handle, AX_ENGINE_CONTEXT_T context, AX_ENGINE_IO_T* pIO); +DLLEXPORT AX_S32 AX_ENGINE_RunGroupIOSync(AX_ENGINE_HANDLE handle, AX_ENGINE_CONTEXT_T context, AX_U32 nIndex, AX_ENGINE_IO_T* pIO); + +DLLEXPORT AX_S32 AX_ENGINE_SetAffinity(AX_ENGINE_HANDLE nHandle, AX_ENGINE_NPU_SET_T nNpuSet); +DLLEXPORT AX_S32 AX_ENGINE_GetAffinity(AX_ENGINE_HANDLE nHandle, AX_ENGINE_NPU_SET_T* pNpuSet); + +DLLEXPORT AX_S32 AX_ENGINE_GetCMMUsage(AX_ENGINE_HANDLE nHandle, AX_ENGINE_CMM_INFO* pCMMInfo); + +DLLEXPORT const AX_CHAR* AX_ENGINE_GetModelToolsVersion(AX_ENGINE_HANDLE nHandle); + +DLLEXPORT AX_S32 AX_ENGINE_GetEncModelType(const AX_VOID *pData, AX_U32 nDataSize, AX_ENGINE_CIPHER_KEY_T *pKey, AX_ENGINE_MODEL_TYPE_T *pModelType); + + +#ifdef __cplusplus +} +#endif diff --git a/sdk/axrt/include/ax_engine_type.h b/sdk/axrt/include/ax_engine_type.h new file mode 100644 index 0000000000000000000000000000000000000000..14e4811275c48f76ccf720573b6e45ba49e0eb30 --- /dev/null +++ b/sdk/axrt/include/ax_engine_type.h @@ -0,0 +1,233 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined __GNUC__ +#define DLLEXPORT __attribute((visibility("default"))) +#elif defined(_MSC_VER) +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif + +#if defined __GNUC__ +#define DEPRECATED_BEFORE +#define DEPRECATED_AFTER __attribute__((deprecated)) +#elif defined(_MSC_VER) +#pragma deprecated() +#define DEPRECATED_BEFORE __declspec(deprecated) +#define DEPRECATED_AFTER +#else +#define DEPRECATED_BEFORE +#define DEPRECATED_AFTER +#endif + +#include + +typedef AX_U32 AX_KERNEL_HANDLE; +typedef AX_VOID* AX_ENGINE_HANDLE; +typedef AX_VOID* AX_ENGINE_CONTEXT_T; +typedef AX_VOID* AX_ENGINE_EXECUTION_CONTEXT; +typedef AX_U32 AX_ENGINE_NPU_SET_T; + + +typedef enum _AX_ENGINE_TENSOR_LAYOUT_E +{ + AX_ENGINE_TENSOR_LAYOUT_UNKNOWN = 0, + AX_ENGINE_TENSOR_LAYOUT_NHWC = 1, + AX_ENGINE_TENSOR_LAYOUT_NCHW = 2, +} AX_ENGINE_TENSOR_LAYOUT_T; + +typedef enum +{ + AX_ENGINE_MT_PHYSICAL = 0, + AX_ENGINE_MT_VIRTUAL = 1, + AX_ENGINE_MT_OCM = 2, +} AX_ENGINE_MEMORY_TYPE_T; + +typedef enum +{ + AX_ENGINE_DT_UNKNOWN = 0, + AX_ENGINE_DT_UINT8 = 1, + AX_ENGINE_DT_UINT16 = 2, + AX_ENGINE_DT_FLOAT32 = 3, + AX_ENGINE_DT_SINT16 = 4, + AX_ENGINE_DT_SINT8 = 5, + AX_ENGINE_DT_SINT32 = 6, + AX_ENGINE_DT_UINT32 = 7, + AX_ENGINE_DT_FLOAT64 = 8, + AX_ENGINE_DT_BFLOAT16 = 9, + AX_ENGINE_DT_UINT10_PACKED = 100, + AX_ENGINE_DT_UINT12_PACKED = 101, + AX_ENGINE_DT_UINT14_PACKED = 102, + AX_ENGINE_DT_UINT16_PACKED = 103, +} AX_ENGINE_DATA_TYPE_T; + +typedef enum +{ + AX_ENGINE_CS_FEATUREMAP = 0, + AX_ENGINE_CS_RAW8 = 12, + AX_ENGINE_CS_RAW10 = 1, + AX_ENGINE_CS_RAW12 = 2, + AX_ENGINE_CS_RAW14 = 11, + AX_ENGINE_CS_RAW16 = 3, + AX_ENGINE_CS_NV12 = 4, + AX_ENGINE_CS_NV21 = 5, + AX_ENGINE_CS_RGB = 6, + AX_ENGINE_CS_BGR = 7, + AX_ENGINE_CS_RGBA = 8, + AX_ENGINE_CS_GRAY = 9, + AX_ENGINE_CS_YUV444 = 10, +} AX_ENGINE_COLOR_SPACE_T; + +typedef enum { + AX_ENGINE_VIRTUAL_NPU_DISABLE = 0, // virtual_npu disable + AX_ENGINE_VIRTUAL_NPU_STD = 1, + AX_ENGINE_VIRTUAL_NPU_BIG_LITTLE = 2, + AX_ENGINE_VIRTUAL_NPU_LITTLE_BIG = 3, + AX_ENGINE_VIRTUAL_NPU_BUTT = 4, +} AX_ENGINE_NPU_MODE_T; + +typedef enum { + AX_ENGINE_MODEL_TYPE0 = 0, + AX_ENGINE_MODEL_TYPE1 = 1, + AX_ENGINE_MODEL_TYPE2 = 2, + AX_ENGINE_MODEL_TYPE_BUTT = 3, +} AX_ENGINE_MODEL_TYPE_T; + +typedef struct { + AX_ENGINE_NPU_MODE_T eHardMode; + AX_U32 reserve[8]; +} AX_ENGINE_NPU_ATTR_T; + +typedef struct _AX_ENGINE_IOMETA_EX_T +{ + AX_ENGINE_COLOR_SPACE_T eColorSpace; + AX_U64 u64Reserved[18]; +} AX_ENGINE_IOMETA_EX_T; + +typedef struct _AX_ENGINE_IOMETA_T +{ + AX_CHAR *pName; + AX_S32 *pShape; // YUV will be treated as 1-ch data + AX_U8 nShapeSize; // dimension of shape + AX_ENGINE_TENSOR_LAYOUT_T eLayout; + AX_ENGINE_MEMORY_TYPE_T eMemoryType; + AX_ENGINE_DATA_TYPE_T eDataType; + AX_ENGINE_IOMETA_EX_T* pExtraMeta; + AX_U32 nSize; + /*! + * `nQuantizationValue` is the total amount of possible values + * in quantization part of a data represented in `Q` method + * eg. for U4Q12 data, nQuantizationValue = 2**12 = 4096 + */ + AX_U32 nQuantizationValue; + /*! + * when pStride is NULL, there is not stride limit + * + * when pStride is not NULL, it holds the number of elements in stride + * of each dimension, the size of `pStride` always equal to `nShapeSize` + * eg. index[0:3] shape[n,c,h,w] stride[chw,hw,w,1] + * eg. index[0:3] shape[n,h,w,c] stride[hwc,wc,c,1] + */ + AX_S32 *pStride; +#if defined(__aarch64__) || defined(__x86_64__) + AX_U64 u64Reserved[9]; +#elif defined(__arm__) + AX_U64 u64Reserved[11]; +#endif +} AX_ENGINE_IOMETA_T; + +typedef struct _AX_ENGINE_IO_INFO_T +{ + AX_ENGINE_IOMETA_T *pInputs; + AX_U32 nInputSize; + AX_ENGINE_IOMETA_T *pOutputs; + AX_U32 nOutputSize; + AX_U32 nMaxBatchSize; // 0 for unlimited + AX_BOOL bDynamicBatchSize; // if true, any batch size <= nMaxBatchSize is supported +#if defined(__aarch64__) || defined(__x86_64__) + AX_U64 u64Reserved[11]; +#elif defined(__arm__) + AX_U64 u64Reserved[13]; +#endif +} AX_ENGINE_IO_INFO_T; + +typedef struct _AX_ENGINE_IO_BUFFER_T +{ + AX_U64 phyAddr; + AX_VOID *pVirAddr; + AX_U32 nSize; // total size of memory + /*! + * pStride holds the bytes of each dimension + * set pStride to NULL to disable stride function + * + * `nStrideSize` should be equal to `nShapeSize` + * eg. index[0:3] shape[n,c,h,w] stride[chw,hw,w,1] + * eg. index[0:3] shape[n,h,w,c] stride[hwc,wc,c,1] + */ + AX_S32 *pStride; + AX_U8 nStrideSize; +#if defined(__aarch64__) || defined(__x86_64__) + AX_U64 u64Reserved[11]; +#elif defined(__arm__) + AX_U64 u64Reserved[13]; +#endif +} AX_ENGINE_IO_BUFFER_T; + +typedef struct _AX_ENGINE_IO_SETTING_T +{ + AX_U32 nWbtIndex; + AX_U64 u64Reserved[7]; +}AX_ENGINE_IO_SETTING_T; + +typedef struct _AX_ENGINE_IO_T +{ + AX_ENGINE_IO_BUFFER_T *pInputs; + AX_U32 nInputSize; + AX_ENGINE_IO_BUFFER_T *pOutputs; + AX_U32 nOutputSize; + AX_U32 nBatchSize; // 0 for auto detection + AX_ENGINE_IO_SETTING_T *pIoSetting; + AX_U32 nParallelRun; // 0 disable parallel run +#if defined(__aarch64__) || defined(__x86_64__) + AX_U64 u64Reserved[10]; +#elif defined(__arm__) + AX_U64 u64Reserved[12]; +#endif +} AX_ENGINE_IO_T; + +typedef struct { + AX_ENGINE_NPU_SET_T nNpuSet; + AX_S8 *pName; + AX_VOID *pKey; + AX_U32 reserve[6]; +} AX_ENGINE_HANDLE_EXTRA_T; + +typedef struct _AX_ENGINE_CMM_INFO +{ + AX_U32 nCMMSize; +} AX_ENGINE_CMM_INFO; + +typedef struct { + AX_U8 *pPek; + AX_U32 nPekSize; + AX_U8 *pAdk; + AX_U32 nAdkSize; +} AX_ENGINE_CIPHER_KEY_T; + +#ifdef __cplusplus +} +#endif diff --git a/sdk/axrt/include/ax_global_type.h b/sdk/axrt/include/ax_global_type.h new file mode 100644 index 0000000000000000000000000000000000000000..98b68cbe290469ca5521182b7255ab1ebf6031de --- /dev/null +++ b/sdk/axrt/include/ax_global_type.h @@ -0,0 +1,476 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_GLOBAL_TYPE_H_ +#define _AX_GLOBAL_TYPE_H_ +#include "ax_base_type.h" + +#define DEF_ALL_MOD_GRP_MAX (164) +#define DEF_ALL_MOD_CHN_MAX (128) +#define AX_LINK_DEST_MAXNUM (4) +#define AX_MAX_COLOR_COMPONENT (3) /* VENC support Y/U/V three planes come from external input */ +#define AX_MAX_COMPRESS_LOSSY_LEVEL (10) +#define AX_INVALID_ID (-1U) + +#ifndef AX_SUCCESS +#define AX_SUCCESS (0) +#endif + +/* don't change this */ +typedef enum { + SYS_LOG_MIN = -1, + SYS_LOG_EMERGENCY = 0, + SYS_LOG_ALERT = 1, + SYS_LOG_CRITICAL = 2, + SYS_LOG_ERROR = 3, + SYS_LOG_WARN = 4, + SYS_LOG_NOTICE = 5, + SYS_LOG_INFO = 6, + SYS_LOG_DEBUG = 7, + SYS_LOG_MAX +} AX_LOG_LEVEL_E; + +typedef enum { + SYS_LOG_TARGET_MIN = 0, + SYS_LOG_TARGET_STDERR = 1, + SYS_LOG_TARGET_SYSLOG = 2, + SYS_LOG_TARGET_NULL = 3, + SYS_LOG_TARGET_MAX +} AX_LOG_TARGET_E; + + +typedef enum +{ + PT_PCMU = 0, + PT_1016 = 1, + PT_G721 = 2, + PT_GSM = 3, + PT_G723 = 4, + PT_DVI4_8K = 5, + PT_DVI4_16K = 6, + PT_LPC = 7, + PT_PCMA = 8, + PT_G722 = 9, + PT_S16BE_STEREO = 10, + PT_S16BE_MONO = 11, + PT_QCELP = 12, + PT_CN = 13, + PT_MPEGAUDIO = 14, + PT_G728 = 15, + PT_DVI4_3 = 16, + PT_DVI4_4 = 17, + PT_G729 = 18, + PT_G711A = 19, + PT_G711U = 20, + PT_G726 = 21, + PT_G729A = 22, + PT_LPCM = 23, + PT_CelB = 25, + PT_JPEG = 26, + PT_CUSM = 27, + PT_NV = 28, + PT_PICW = 29, + PT_CPV = 30, + PT_H261 = 31, + PT_MPEGVIDEO = 32, + PT_MPEG2TS = 33, + PT_H263 = 34, + PT_SPEG = 35, + PT_MPEG2VIDEO = 36, + PT_AAC = 37, + PT_WMA9STD = 38, + PT_HEAAC = 39, + PT_PCM_VOICE = 40, + PT_PCM_AUDIO = 41, + PT_AACLC = 42, + PT_MP3 = 43, + PT_ADPCMA = 49, + PT_AEC = 50, + PT_X_LD = 95, + PT_H264 = 96, + PT_D_GSM_HR = 200, + PT_D_GSM_EFR = 201, + PT_D_L8 = 202, + PT_D_RED = 203, + PT_D_VDVI = 204, + PT_D_BT656 = 220, + PT_D_H263_1998 = 221, + PT_D_MP1S = 222, + PT_D_MP2P = 223, + PT_D_BMPEG = 224, + PT_MP4VIDEO = 230, + PT_MP4AUDIO = 237, + PT_VC1 = 238, + PT_JVC_ASF = 255, + PT_D_AVI = 256, + PT_DIVX3 = 257, + PT_AVS = 258, + PT_REAL8 = 259, + PT_REAL9 = 260, + PT_VP6 = 261, + PT_VP6F = 262, + PT_VP6A = 263, + PT_SORENSON = 264, + PT_H265 = 265, + PT_VP8 = 266, + PT_MVC = 267, + PT_PNG = 268, + PT_AVS2 = 269, + PT_VP7 = 270, + PT_VP9 = 271, + PT_AMR = 1001, + PT_MJPEG = 1002, + PT_AMRWB = 1003, + PT_PRORES = 1006, + PT_OPUS = 1007, + PT_BUTT +} AX_PAYLOAD_TYPE_E; + +typedef enum { + AX_VSCAN_FORMAT_RASTER = 0, /* video raster scan mode */ + AX_VSCAN_FORMAT_BUTT +} AX_VSCAN_FORMAT_E; + +typedef enum +{ + AX_COMPRESS_MODE_NONE = 0, /* no compress */ + AX_COMPRESS_MODE_LOSSLESS, + AX_COMPRESS_MODE_LOSSY, + AX_COMPRESS_MODE_BUTT +} AX_COMPRESS_MODE_E; + +typedef struct axFRAME_COMPRESS_INFO_T { + AX_COMPRESS_MODE_E enCompressMode; + AX_U32 u32CompressLevel; +} AX_FRAME_COMPRESS_INFO_T; + +typedef enum axDYNAMIC_RANGE_E +{ + AX_DYNAMIC_RANGE_SDR8 = 0, + AX_DYNAMIC_RANGE_SDR10, + AX_DYNAMIC_RANGE_HDR10, + AX_DYNAMIC_RANGE_HLG, + AX_DYNAMIC_RANGE_SLF, + AX_DYNAMIC_RANGE_XDR, + AX_DYNAMIC_RANGE_BUTT +} AX_DYNAMIC_RANGE_E; + +typedef enum axCOLOR_GAMUT_E +{ + AX_COLOR_GAMUT_BT601 = 0, + AX_COLOR_GAMUT_BT709, + AX_COLOR_GAMUT_BT2020, + AX_COLOR_GAMUT_USER, + AX_COLOR_GAMUT_BUTT +} AX_COLOR_GAMUT_E; + +typedef enum +{ + AX_FORMAT_INVALID = -1, + + /* YUV400 8 bit */ + AX_FORMAT_YUV400 = 0x0, /* Y... */ + + /* YUV420 8 bit */ + AX_FORMAT_YUV420_PLANAR = 0x1, /* YYYY... UUUU... VVVV... I420/YU12 */ + AX_FORMAT_YUV420_PLANAR_VU = 0x2, /* YYYY... VVVV... UUUU... YV12 */ + AX_FORMAT_YUV420_SEMIPLANAR = 0x3, /* YYYY... UVUVUV... NV12 */ + AX_FORMAT_YUV420_SEMIPLANAR_VU = 0x4, /* YYYY... VUVUVU... NV21 */ + + /* YUV422 8 bit */ + AX_FORMAT_YUV422_PLANAR = 0x8, /* YYYY... UUUU... VVVV... I422 */ + AX_FORMAT_YUV422_PLANAR_VU = 0x9, /* YYYY... VVVV... UUUU... YV16 */ + AX_FORMAT_YUV422_SEMIPLANAR = 0xA, /* YYYY... UVUVUV... NV61 */ + AX_FORMAT_YUV422_SEMIPLANAR_VU = 0xB, /* YYYY... VUVUVU... NV16 */ + AX_FORMAT_YUV422_INTERLEAVED_YUVY = 0xC, /* YUVYYUVY... YUVY */ + AX_FORMAT_YUV422_INTERLEAVED_YUYV = 0xD, /* YUYVYUYV... YUYV */ + AX_FORMAT_YUV422_INTERLEAVED_UYVY = 0xE, /* UYVYUYVY... UYVY */ + AX_FORMAT_YUV422_INTERLEAVED_VYUY = 0xF, /* VYUYVYUY... VYUY */ + AX_FORMAT_YUV422_INTERLEAVED_YVYU = 0x10, /* VYUYVYUY... YVYU */ + + /* YUV444 8 bit */ + AX_FORMAT_YUV444_PLANAR = 0x14, /* YYYY... UUUU... VVVV... I444 */ + AX_FORMAT_YUV444_PLANAR_VU = 0x15, /* YYYY... VVVV... UUUU... YV24 */ + AX_FORMAT_YUV444_SEMIPLANAR = 0x16, /* YYYY... UVUVUV... NV24 */ + AX_FORMAT_YUV444_SEMIPLANAR_VU = 0x17, /* YYYY... VUVUVU... NV42 */ + AX_FORMAT_YUV444_PACKED = 0x18, /* YUV YUV YUV ... */ + + /* YUV 10 bit */ + AX_FORMAT_YUV400_10BIT = 0x20, + AX_FORMAT_YUV420_PLANAR_10BIT_UV_PACKED_4Y5B = 0x24, /* YYYY... UUUU... VVVV... , 4 Y pixels in 5 bytes, UV packed */ + AX_FORMAT_YUV420_PLANAR_10BIT_I010 = 0x25, /* 16 bit pixel, low 10bits valid, high 6 bits invalid */ + AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P101010 = 0x28, /* YYYY... UVUVUV... , Y/U/V 4 pixels in 5 bytes */ + AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P010 = 0x2A, /* 16 bit pixel, high 10bits valid, low 6 bits invalid */ + AX_FORMAT_YUV420_SEMIPLANAR_10BIT_P016 = 0x2C, /* 16 bit pixel, low 10bits valid, high 6 bits invalid */ + AX_FORMAT_YUV420_SEMIPLANAR_10BIT_I016 = 0x2E, /* 16 bit pixel, high 10bits valid, low 6 bits invalid */ + AX_FORMAT_YUV420_SEMIPLANAR_10BIT_12P16B = 0x2F, /* 12 pixels in 16bytes, low 120bits valid, high 8 bits invalid */ + AX_FORMAT_YUV444_PACKED_10BIT_P010 = 0x30, /* YUV YUV YUV ... , 16 bit pixel, high 10bits valid, low 6 bits invalid */ + AX_FORMAT_YUV444_PACKED_10BIT_P101010 = 0x32, /* YUV YUV YUV ... , 4 pixels storage in 5 bytes */ + + /* BAYER RAW */ + AX_FORMAT_BAYER_RAW_8BPP = 0x80, + AX_FORMAT_BAYER_RAW_10BPP = 0x81, + AX_FORMAT_BAYER_RAW_12BPP = 0x82, + AX_FORMAT_BAYER_RAW_14BPP = 0x83, + AX_FORMAT_BAYER_RAW_16BPP = 0x84, + + /* RGB Format */ + AX_FORMAT_RGB565 = 0xA0, + AX_FORMAT_RGB888 = 0xA1, /* RGB888 24bpp */ + AX_FORMAT_KRGB444 = 0xA2, /* RGB444 16bpp */ + AX_FORMAT_KRGB555 = 0xA3, /* RGB555 16bpp */ + AX_FORMAT_KRGB888 = 0xA4, /* RGB888 32bpp */ + AX_FORMAT_BGR888 = 0xA5, + AX_FORMAT_BGR565 = 0xA6, + + AX_FORMAT_ARGB4444 = 0xC5, /* ARGB4444 */ + AX_FORMAT_ARGB1555 = 0xC6, /* ARGB1555 */ + AX_FORMAT_ARGB8888 = 0xC7, /* ARGB8888 */ + AX_FORMAT_ARGB8565 = 0xC8, /* ARGB8565 */ + AX_FORMAT_RGBA8888 = 0xC9, + AX_FORMAT_RGBA5551 = 0xCA, + AX_FORMAT_RGBA4444 = 0xCB, + + AX_FORMAT_BITMAP = 0xD0, + + AX_FORMAT_MAX +} AX_IMG_FORMAT_E; + + +typedef struct axVIDEO_FRAME_T { + AX_U32 u32Width; + AX_U32 u32Height; + AX_IMG_FORMAT_E enImgFormat; + AX_VSCAN_FORMAT_E enVscanFormat; + AX_FRAME_COMPRESS_INFO_T stCompressInfo; + AX_DYNAMIC_RANGE_E stDynamicRange; + AX_COLOR_GAMUT_E stColorGamut; + + AX_U32 u32PicStride[AX_MAX_COLOR_COMPONENT]; + AX_U32 u32ExtStride[AX_MAX_COLOR_COMPONENT]; + + AX_U64 u64PhyAddr[AX_MAX_COLOR_COMPONENT]; /* frame physics address*/ + AX_U64 u64VirAddr[AX_MAX_COLOR_COMPONENT]; /* frame virtual address*/ + AX_U64 u64ExtPhyAddr[AX_MAX_COLOR_COMPONENT]; + AX_U64 u64ExtVirAddr[AX_MAX_COLOR_COMPONENT]; + AX_U32 u32HeaderSize[AX_MAX_COLOR_COMPONENT]; /* frame header size*/ + AX_U32 u32BlkId[AX_MAX_COLOR_COMPONENT]; + + AX_S16 s16CropX; + AX_S16 s16CropY; + AX_S16 s16CropWidth; + AX_S16 s16CropHeight; + + AX_U32 u32TimeRef; + AX_U64 u64PTS; /* Payload TimeStamp */ + AX_U64 u64SeqNum; /* input frame sequence number */ + AX_U64 u64UserData; /* Reserved for user, sdk do not use */ + + AX_U64 u64PrivateData; /* SDK reserved, user do not use */ + AX_U32 u32FrameFlag; /* FRAME_FLAG_E, can be OR operation. */ + + AX_U32 u32FrameSize; /* FRAME Size, for isp raw and yuv. */ +} AX_VIDEO_FRAME_T; + +typedef enum +{ + AX_ID_MIN = 0x00, + AX_ID_ISP = 0x01, + AX_ID_CE = 0x02, + AX_ID_VO = 0x03, + AX_ID_VDSP = 0x04, + AX_ID_EFUSE = 0x05, + AX_ID_NPU = 0x06, + AX_ID_VENC = 0x07, + AX_ID_VDEC = 0x08, + AX_ID_JENC = 0x09, + AX_ID_JDEC = 0x0a, + AX_ID_SYS = 0x0b, + AX_ID_AENC = 0x0c, + AX_ID_IVPS = 0x0d, + AX_ID_MIPI = 0x0e, + AX_ID_ADEC = 0x0f, + AX_ID_DMA = 0x10, + AX_ID_VIN = 0x11, + AX_ID_USER = 0x12, + AX_ID_IVES = 0x13, + AX_ID_SKEL = 0x14, + AX_ID_IVE = 0x15, + AX_ID_3A = 0X19, + AX_ID_AI = 0X20, + AX_ID_AO = 0X21, + /* reserve */ + AX_ID_RESERVE = 0x22, + AX_ID_BUTT, +} AX_MOD_ID_E; + +typedef enum +{ + AX_UNLINK_MODE = 0, + AX_LINK_MODE = 1, +} AX_LINK_MODE_E; + +typedef enum axAUDIO_BIT_WIDTH_E { + AX_AUDIO_BIT_WIDTH_8 = 0, /* 8bit width */ + AX_AUDIO_BIT_WIDTH_16 = 1, /* 16bit width*/ + AX_AUDIO_BIT_WIDTH_24 = 2, /* 24bit width*/ + AX_AUDIO_BIT_WIDTH_32 = 3, /* 32bit width*/ + AX_AUDIO_BIT_WIDTH_BUTT, +} AX_AUDIO_BIT_WIDTH_E; + +typedef enum axAUDIO_SOUND_MODE_E { + AX_AUDIO_SOUND_MODE_MONO = 0, /*mono*/ + AX_AUDIO_SOUND_MODE_STEREO = 1, /*stereo*/ + AX_AUDIO_SOUND_MODE_BUTT +} AX_AUDIO_SOUND_MODE_E; + +typedef struct axAUDIO_FRAME_T { + AX_AUDIO_BIT_WIDTH_E enBitwidth; /*audio frame bitwidth*/ + AX_AUDIO_SOUND_MODE_E enSoundmode; /*audio frame momo or stereo mode*/ + AX_U8 *u64VirAddr; + AX_U64 u64PhyAddr; + AX_U64 u64TimeStamp; /*audio frame timestamp*/ + AX_U32 u32Seq; /*audio frame seq*/ + AX_U32 u32Len; /*data lenth in frame*/ + AX_U32 u32PoolId[2]; + AX_BOOL bEof; + AX_U32 u32BlkId; +} AX_AUDIO_FRAME_T; + +typedef struct axAUDIO_FRAME_INFO_T { + AX_AUDIO_FRAME_T stAFrame; + AX_MOD_ID_E enModId; + AX_BOOL bEndOfStream; +} AX_AUDIO_FRAME_INFO_T; + +typedef struct axVIDEO_FRAME_INFO_T { + AX_VIDEO_FRAME_T stVFrame; + AX_MOD_ID_E enModId; + AX_BOOL bEndOfStream; +} AX_VIDEO_FRAME_INFO_T; + + +typedef enum { + AX_NOTIFY_EVENT_SLEEP = 0, + AX_NOTIFY_EVENT_WAKEUP = 1, + AX_NOTIFY_EVENT_MAX +} AX_NOTIFY_EVENT_E; + +typedef enum { + AX_SYS_CLK_HIGH_MODE = 0, + AX_SYS_CLK_HIGH_HOTBALANCE_MODE = 1, + AX_SYS_CLK_MID_MODE = 2, + AX_SYS_CLK_MID_HOTBALANCE_MODE = 3, + AX_SYS_CLK_MAX_MODE = 4, +} AX_SYS_CLK_LEVEL_E; + +typedef enum { + AX_CPU_CLK_ID = 0, + AX_BUS_CLK_ID = 1, + AX_NPU_CLK_ID = 2, + AX_ISP_CLK_ID = 3, + AX_MM_CLK_ID = 4, + AX_VPU_CLK_ID = 5, + AX_SYS_CLK_MAX_ID = 6, +} AX_SYS_CLK_ID_E; + +typedef struct axMOD_INFO_T { + AX_MOD_ID_E enModId; + AX_S32 s32GrpId; + AX_S32 s32ChnId; +} AX_MOD_INFO_T; + +typedef struct axLINK_DEST_S{ + AX_U32 u32DestNum; + AX_MOD_INFO_T astDestMod[AX_LINK_DEST_MAXNUM]; +} AX_LINK_DEST_T; + + +typedef enum { + AX_MEMORY_SOURCE_CMM = 0, + AX_MEMORY_SOURCE_POOL = 1, + AX_MEMORY_SOURCE_OS = 2, + AX_MEMORY_SOURCE_BUTT, +} AX_MEMORY_SOURCE_E; + +typedef struct { + AX_U64 u64PhyAddr; + AX_VOID *pVirAddr; +} AX_MEMORY_ADDR_T; + +/* OSD attribute extend */ +typedef struct axOSD_BMP_ATTR_T { + AX_U16 u16Alpha; + AX_IMG_FORMAT_E enRgbFormat; + + AX_U8 *pBitmap; /* pointer to OSD template */ + AX_U64 u64PhyAddr; /* physical address of OSD template */ + AX_U32 u32BmpWidth; /* template width */ + AX_U32 u32BmpHeight; /* template height */ + + AX_U32 u32DstXoffset; /* where to overlay, x0 */ + AX_U32 u32DstYoffset; /* where to overlay, y0 */ + + /* the below variables are only for bitmap-1 format */ + AX_U32 u32Color; /* RW; range: [0, 0xffffff]; color RGB888; 0xRRGGBB */ + AX_BOOL bColorInv; /* RW; range: [0, 1]; whether use background color or not */ + AX_U32 u32ColorInv; /* RW; range: [0, 0xffffff]; inverse color RGB888; 0xRRGGBB */ + AX_U32 u32ColorInvThr; /* RW; range: [0, 0xffffff]; threshold of color difference with background; 0xRRGGBB */ +} AX_OSD_BMP_ATTR_T; + + +typedef enum { + AX_ERR_INVALID_MODID = 0x01, /* invalid module id */ + AX_ERR_INVALID_DEVID = 0x02, /* invalid device id */ + AX_ERR_INVALID_GRPID = 0x03, /* invalid group id */ + AX_ERR_INVALID_CHNID = 0x04, /* invalid channel id */ + AX_ERR_INVALID_PIPEID = 0x05, /* invalid pipe id */ + AX_ERR_INVALID_STITCHGRPID = 0x06, /* invalid stitch group id */ + /*reserved*/ + AX_ERR_ILLEGAL_PARAM = 0x0A, /* at lease one input value is out of range */ + AX_ERR_NULL_PTR = 0x0B, /* at lease one input pointer is null */ + AX_ERR_BAD_ADDR = 0x0C, /* at lease one input address is invalid */ + /*reserved*/ + AX_ERR_SYS_NOTREADY = 0x10, /* a driver is required but not loaded */ + AX_ERR_BUSY = 0x11, /* a resource is busy, probably locked by other users */ + AX_ERR_NOT_INIT = 0x12, /* module is not initialized */ + AX_ERR_NOT_CONFIG = 0x13, /* module is not configured */ + AX_ERR_NOT_SUPPORT = 0x14, /* requested function is not supported on this platform */ + AX_ERR_NOT_PERM = 0x15, /* requested operation is not permitted in this state */ + AX_ERR_EXIST = 0x16, /* target object already exists */ + AX_ERR_UNEXIST = 0x17, /* target object does not exist */ + AX_ERR_NOMEM = 0x18, /* failed to allocate memory from heap */ + AX_ERR_NOBUF = 0x19, /* failed to borrow buffer from pool */ + AX_ERR_NOT_MATCH = 0x1A, /* inconsistent parameter configuration between interfaces */ + /*reserved*/ + AX_ERR_BUF_EMPTY = 0x20, /* buffer contains no data */ + AX_ERR_BUF_FULL = 0x21, /* buffer contains fresh data */ + AX_ERR_QUEUE_EMPTY = 0x22, /* failed to read as queue is empty */ + AX_ERR_QUEUE_FULL = 0x23, /* failed to write as queue is full */ + /*reserved*/ + AX_ERR_TIMED_OUT = 0x27, /* operation timeout */ + AX_ERR_FLOW_END = 0x28, /* END signal detected in data stream, processing terminated */ + AX_ERR_UNKNOWN = 0x29, /* unexpected failure, please contact manufacturer support */ + /*reserved*/ + + AX_ERR_BUTT = 0x7F, /* maxium code, private error code of all modules + ** must be greater than it */ +} AX_ERR_CODE_E; + +/****************************************************************************** +|----------------------------------------------------------------| +|| FIXED | MOD_ID | SUB_MODULE_ID | ERR_ID | +|----------------------------------------------------------------| +|<--8bits----><----8bits---><-----8bits---><------8bits------->| +******************************************************************************/ +#define AX_DEF_ERR( module, sub_module, errid) \ + ((AX_S32)( (0x80000000L) | ((module) << 16 ) | ((sub_module)<<8) | (errid) )) + +#endif //_AX_GLOBAL_TYPE_H_ diff --git a/sdk/axrt/include/ax_pool_type.h b/sdk/axrt/include/ax_pool_type.h new file mode 100644 index 0000000000000000000000000000000000000000..5a6eb17c53069acc4eed7e07e243a587fb6c19ca --- /dev/null +++ b/sdk/axrt/include/ax_pool_type.h @@ -0,0 +1,70 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_POOL_TYPE_H_ +#define _AX_POOL_TYPE_H_ +#include "ax_global_type.h" +#include "ax_base_type.h" + +#define AX_INVALID_POOLID (-1U) +#define AX_INVALID_BLOCKID (0) + +#define AX_MAX_POOLS 1024 +#define AX_MAX_COMM_POOLS 64 +#define AX_MAX_BLKS_PER_POOL 1024 + +#define AX_MAX_PARTITION_NAME_LEN 32 +#define AX_MAX_PARTITION_COUNT 16 + +/* error code define */ +#define AX_ERR_POOL_ILLEGAL_PARAM AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_ILLEGAL_PARAM) //0x800B010A +#define AX_ERR_POOL_NULL_PTR AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_NULL_PTR) //0x800B010B +#define AX_ERR_POOL_NOTREADY AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_SYS_NOTREADY) //0x800B0110 +#define AX_ERR_POOL_BUSY AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_BUSY) //0x800B0111 +#define AX_ERR_POOL_NOT_SUPPORT AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_NOT_SUPPORT) //0x800B0114 +#define AX_ERR_POOL_NOT_PERM AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_NOT_PERM) //0x800B0115 +#define AX_ERR_POOL_UNEXIST AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_UNEXIST) //0x800B0117 +#define AX_ERR_POOL_NOMEM AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_NOMEM) //0x800B0118 +#define AX_ERR_POOL_UNKNOWN AX_DEF_ERR(AX_ID_SYS, 0x01, AX_ERR_UNKNOWN) //0x800B0129 +#define AX_ERR_POOL_MMAP_FAIL AX_DEF_ERR(AX_ID_SYS, 0x01, 0x80) //0x800B0180 +#define AX_ERR_POOL_MUNMAP_FAIL AX_DEF_ERR(AX_ID_SYS, 0x01, 0x81) //0x800B0181 +#define AX_ERR_POOL_BLKFREE_FAIL AX_DEF_ERR(AX_ID_SYS, 0x01, 0x82) //0x800B0182 + + +typedef AX_U32 AX_POOL; +typedef AX_U32 AX_BLK; + +typedef enum { + POOL_CACHE_MODE_NONCACHE = 0, + POOL_CACHE_MODE_CACHED = 1, + POOL_CACHE_MODE_BUTT +} AX_POOL_CACHE_MODE_E; + +typedef enum { + POOL_SOURCE_COMMON = 0, + POOL_SOURCE_PRIVATE = 1, + POOL_SOURCE_USER = 2, + POOL_SOURCE_BUTT +} AX_POOL_SOURCE_E; + +typedef struct { + AX_U64 MetaSize; + AX_U64 BlkSize; + AX_U32 BlkCnt; /* range:(0,256] */ + AX_BOOL IsMergeMode; /* logically merged with common pool, make common pool bigger*/ + AX_POOL_CACHE_MODE_E CacheMode; + AX_S8 PartitionName[AX_MAX_PARTITION_NAME_LEN]; +} AX_POOL_CONFIG_T; + +typedef struct { + AX_POOL_CONFIG_T CommPool[AX_MAX_COMM_POOLS]; +} AX_POOL_FLOORPLAN_T; + +#endif //_AX_POOL_TYPE_H_ diff --git a/sdk/axrt/include/ax_sys_api.h b/sdk/axrt/include/ax_sys_api.h new file mode 100644 index 0000000000000000000000000000000000000000..36a9d1661797b4630ef1ceefc69801824cb5ce6c --- /dev/null +++ b/sdk/axrt/include/ax_sys_api.h @@ -0,0 +1,126 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_SYS_API_ +#define _AX_SYS_API_ +#include "ax_global_type.h" +#include "ax_base_type.h" +#include "ax_pool_type.h" + +/* flags */ +#define AX_MEM_CACHED (1 << 1) /* alloc mem is cached */ +#define AX_MEM_NONCACHED (1 << 2) /* alloc mem is not cached */ + +typedef struct { + AX_U64 PhysAddr; + AX_U32 SizeKB; + AX_S8 Name[AX_MAX_PARTITION_NAME_LEN]; +} AX_PARTITION_INFO_T; + +typedef struct { + AX_U32 PartitionCnt;/* range:1~AX_MAX_PARTITION_COUNT */ + AX_PARTITION_INFO_T PartitionInfo[AX_MAX_PARTITION_COUNT]; +} AX_CMM_PARTITION_INFO_T; + +/* error code define */ +#define AX_ERR_CMM_ILLEGAL_PARAM AX_DEF_ERR(AX_ID_SYS, 0x00, AX_ERR_ILLEGAL_PARAM) //0x800B000A +#define AX_ERR_CMM_NULL_PTR AX_DEF_ERR(AX_ID_SYS, 0x00, AX_ERR_NULL_PTR) //0x800B000B +#define AX_ERR_CMM_NOTREADY AX_DEF_ERR(AX_ID_SYS, 0x00, AX_ERR_SYS_NOTREADY) //0x800B0010 +#define AX_ERR_CMM_NOMEM AX_DEF_ERR(AX_ID_SYS, 0x00, AX_ERR_NOMEM) //0x800B0018 +#define AX_ERR_CMM_UNKNOWN AX_DEF_ERR(AX_ID_SYS, 0x00, AX_ERR_UNKNOWN) //0x800B0029 +#define AX_ERR_CMM_MMAP_FAIL AX_DEF_ERR(AX_ID_SYS, 0x00, 0x80) //0x800B0080 +#define AX_ERR_CMM_MUNMAP_FAIL AX_DEF_ERR(AX_ID_SYS, 0x00, 0x81) //0x800B0081 +#define AX_ERR_CMM_FREE_FAIL AX_DEF_ERR(AX_ID_SYS, 0x00, 0x82) //0x800B0082 + +#define AX_ERR_PTS_ILLEGAL_PARAM AX_DEF_ERR(AX_ID_SYS, 0x02, AX_ERR_ILLEGAL_PARAM) //0x800B020A +#define AX_ERR_PTS_NULL_PTR AX_DEF_ERR(AX_ID_SYS, 0x02, AX_ERR_NULL_PTR) //0x800B020B +#define AX_ERR_PTS_NOTREADY AX_DEF_ERR(AX_ID_SYS, 0x02, AX_ERR_SYS_NOTREADY) //0x800B0210 +#define AX_ERR_PTS_NOT_PERM AX_DEF_ERR(AX_ID_SYS, 0x02, AX_ERR_NOT_PERM) //0x800B0215 +#define AX_ERR_PTS_UNKNOWN AX_DEF_ERR(AX_ID_SYS, 0x02, AX_ERR_UNKNOWN) //0x800B0229 + +#define AX_ERR_LINK_ILLEGAL_PARAM AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_ILLEGAL_PARAM) //0x800B030A +#define AX_ERR_LINK_NULL_PTR AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_NULL_PTR) //0x800B030B +#define AX_ERR_LINK_NOTREADY AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_SYS_NOTREADY) //0x800B0310 +#define AX_ERR_LINK_NOT_SUPPORT AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_NOT_SUPPORT) //0x800B0314 +#define AX_ERR_LINK_NOT_PERM AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_NOT_PERM) //0x800B0315 +#define AX_ERR_LINK_UNEXIST AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_UNEXIST) //0x800B0317 +#define AX_ERR_LINK_UNKNOWN AX_DEF_ERR(AX_ID_SYS, 0x03, AX_ERR_UNKNOWN) //0x800B0329 +#define AX_ERR_LINK_TABLE_FULL AX_DEF_ERR(AX_ID_SYS, 0x03, 0x80) //0x800B0380 +#define AX_ERR_LINK_TABLE_EMPTY AX_DEF_ERR(AX_ID_SYS, 0x03, 0x81) //0x800B0381 + + + +#ifdef __cplusplus +extern "C" +{ +#endif + +AX_S32 AX_SYS_Init(AX_VOID); +AX_S32 AX_SYS_Deinit(AX_VOID); + +/* CMM API */ +AX_S32 AX_SYS_MemAlloc(AX_U64 *phyaddr, AX_VOID **pviraddr, AX_U32 size, AX_U32 align, const AX_S8 *token); +AX_S32 AX_SYS_MemAllocCached(AX_U64 *phyaddr, AX_VOID **pviraddr, AX_U32 size, AX_U32 align, const AX_S8 *token); +AX_S32 AX_SYS_MemFree(AX_U64 phyaddr, AX_VOID *pviraddr); +AX_VOID *AX_SYS_Mmap(AX_U64 phyaddr, AX_U32 size); +AX_VOID *AX_SYS_MmapCache(AX_U64 phyaddr, AX_U32 size); +AX_VOID *AX_SYS_MmapFast(AX_U64 phyaddr, AX_U32 size); +AX_VOID *AX_SYS_MmapCacheFast(AX_U64 phyaddr, AX_U32 size); +AX_S32 AX_SYS_Munmap(AX_VOID *pviraddr, AX_U32 size); +AX_S32 AX_SYS_MflushCache(AX_U64 phyaddr, AX_VOID *pviraddr, AX_U32 size); +AX_S32 AX_SYS_MinvalidateCache(AX_U64 phyaddr, AX_VOID *pviraddr, AX_U32 size); +AX_S32 AX_SYS_MemGetBlockInfoByPhy(AX_U64 phyaddr, AX_S32 *pmemType, AX_VOID **pviraddr, AX_U32 *pblockSize); +AX_S32 AX_SYS_MemGetBlockInfoByVirt(AX_VOID *pviraddr, AX_U64 *phyaddr, AX_S32 *pmemType); +AX_S32 AX_SYS_MemGetPartitionInfo(AX_CMM_PARTITION_INFO_T *pCmmPartitionInfo); +AX_S32 AX_SYS_MemSetConfig(const AX_MOD_INFO_T *pModInfo, const AX_S8 *pPartitionName); +AX_S32 AX_SYS_MemGetConfig(const AX_MOD_INFO_T *pModInfo, AX_S8 *pPartitionName); + +/* LINK API*/ +AX_S32 AX_SYS_Link(const AX_MOD_INFO_T *pSrc, const AX_MOD_INFO_T *pDest); +AX_S32 AX_SYS_UnLink(const AX_MOD_INFO_T *pSrc, const AX_MOD_INFO_T *pDest); +AX_S32 AX_SYS_GetLinkByDest(const AX_MOD_INFO_T *pDest, AX_MOD_INFO_T *pSrc); +AX_S32 AX_SYS_GetLinkBySrc(const AX_MOD_INFO_T *pSrc, AX_LINK_DEST_T *pLinkDest); + +/* POOL API */ +AX_S32 AX_POOL_SetConfig(const AX_POOL_FLOORPLAN_T *pPoolFloorPlan); +AX_S32 AX_POOL_GetConfig (AX_POOL_FLOORPLAN_T *pPoolFloorPlan); +AX_S32 AX_POOL_Init(AX_VOID); +AX_S32 AX_POOL_Exit(AX_VOID); +AX_POOL AX_POOL_CreatePool(AX_POOL_CONFIG_T *pPoolConfig); +AX_S32 AX_POOL_DestroyPool(AX_POOL PoolId); +AX_BLK AX_POOL_GetBlock(AX_POOL PoolId, AX_U64 BlkSize, const AX_S8 *pPartitionName); +AX_S32 AX_POOL_ReleaseBlock(AX_BLK BlockId); +AX_BLK AX_POOL_PhysAddr2Handle(AX_U64 PhysAddr); +AX_U64 AX_POOL_Handle2PhysAddr(AX_BLK BlockId); +AX_U64 AX_POOL_Handle2MetaPhysAddr(AX_BLK BlockId); +AX_POOL AX_POOL_Handle2PoolId(AX_BLK BlockId); +AX_U64 AX_POOL_Handle2BlkSize(AX_BLK BlockId); +AX_S32 AX_POOL_MmapPool(AX_POOL PoolId); +AX_S32 AX_POOL_MunmapPool(AX_POOL PoolId); +AX_VOID *AX_POOL_GetBlockVirAddr(AX_BLK BlockId); +AX_VOID *AX_POOL_GetMetaVirAddr(AX_BLK BlockId); +AX_S32 AX_POOL_IncreaseRefCnt(AX_BLK BlockId); +AX_S32 AX_POOL_DecreaseRefCnt(AX_BLK BlockId); + +/* PTS API */ +AX_S32 AX_SYS_GetCurPTS(AX_U64 *pu64CurPTS); +AX_S32 AX_SYS_InitPTSBase(AX_U64 u64PTSBase); +AX_S32 AX_SYS_SyncPTS(AX_U64 u64PTSBase); + +/* LOG API */ +AX_S32 AX_SYS_SetLogLevel(AX_LOG_LEVEL_E target); +AX_S32 AX_SYS_SetLogTarget(AX_LOG_TARGET_E target); +AX_S32 AX_SYS_EnableTimestamp(AX_BOOL enable); + +#ifdef __cplusplus +} +#endif + +#endif //_AX_SYS_API_ diff --git a/sdk/axrt/include/ax_sys_log.h b/sdk/axrt/include/ax_sys_log.h new file mode 100644 index 0000000000000000000000000000000000000000..f1ce6f2f2719ec3df1e27bc0a295328a724c5e16 --- /dev/null +++ b/sdk/axrt/include/ax_sys_log.h @@ -0,0 +1,77 @@ +/************************************************************************************************** + * + * Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved. + * + * This source file is the property of Axera Semiconductor Co., Ltd. and + * may not be copied or distributed in any isomorphic form without the prior + * written consent of Axera Semiconductor Co., Ltd. + * + **************************************************************************************************/ + +#ifndef _AX_SYS_LOG_H_ +#define _AX_SYS_LOG_H_ +#include "ax_base_type.h" +#include "ax_global_type.h" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* + LOG_EMERG system is unusable + LOG_ALERT action must be taken immediately + LOG_CRIT critical conditions + LOG_ERR error conditions + LOG_WARNING warning conditions + LOG_NOTICE normal, but significant, condition + LOG_INFO informational message + LOG_DEBUG debug-level message +*/ + +AX_VOID AX_SYS_LogOpen(); +AX_VOID AX_SYS_LogClose(); +AX_VOID AX_SYS_LogPrint(AX_S32 level, AX_CHAR const *pFormat, ...); +AX_VOID AX_SYS_LogOutput(AX_LOG_TARGET_E target, AX_LOG_LEVEL_E level, AX_CHAR const *format, va_list vlist); +AX_VOID AX_SYS_LogPrint_Ex(AX_S32 level, AX_CHAR const *tag, int id, AX_CHAR const *pFormat, ...); +AX_VOID AX_SYS_LogOutput_Ex(AX_LOG_TARGET_E target, AX_LOG_LEVEL_E level, AX_CHAR const *tag, int id, AX_CHAR const *format, va_list vlist); + +#ifdef __cplusplus +} +#endif + +#define MACRO_BLACK "\033[1;30;30m" +#define MACRO_RED "\033[1;30;31m" +#define MACRO_GREEN "\033[1;30;32m" +#define MACRO_YELLOW "\033[1;30;33m" +#define MACRO_BLUE "\033[1;30;34m" +#define MACRO_PURPLE "\033[1;30;35m" +#define MACRO_WHITE "\033[1;30;37m" +#define MACRO_END "\033[0m" + +#define AX_MSYS_LOG_TAG "MSYS" + +#define AX_LOG_ERR(fmt,...) \ + AX_SYS_LogPrint(SYS_LOG_ERROR, MACRO_RED"[E][%32s][%4d]: "fmt MACRO_END, __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_WARN(fmt,...) \ + AX_SYS_LogPrint(SYS_LOG_WARN, MACRO_BLUE"[W][%32s][%4d]: "fmt MACRO_END, __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_INFO(fmt,...) \ + AX_SYS_LogPrint(SYS_LOG_INFO, MACRO_GREEN"[I][%32s][%4d]: "fmt MACRO_END, __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_DBG(fmt,...) \ + AX_SYS_LogPrint(SYS_LOG_DEBUG, MACRO_WHITE"[D][%32s][%4d]: "fmt MACRO_END, __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_NOTICE(fmt,...) \ + AX_SYS_LogPrint(SYS_LOG_NOTICE, MACRO_PURPLE"[N][%32s][%4d]: "fmt MACRO_END, __FUNCTION__, __LINE__, ##__VA_ARGS__); + +#define AX_LOG_ERR_EX(tag,id,fmt,...) \ + AX_SYS_LogPrint_Ex(SYS_LOG_ERROR, tag, id, MACRO_RED"[E][%32s][%4d]: "fmt MACRO_END , __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_WARN_EX(tag,id,fmt,...) \ + AX_SYS_LogPrint_Ex(SYS_LOG_WARN, tag, id, MACRO_BLUE"[W][%32s][%4d]: "fmt MACRO_END , __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_INFO_EX(tag,id,fmt,...) \ + AX_SYS_LogPrint_Ex(SYS_LOG_INFO, tag, id, MACRO_GREEN"[I][%32s][%4d]: "fmt MACRO_END , __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_DBG_EX(tag,id,fmt,...) \ + AX_SYS_LogPrint_Ex(SYS_LOG_DEBUG, tag, id, MACRO_WHITE"[D][%32s][%4d]: "fmt MACRO_END , __FUNCTION__, __LINE__, ##__VA_ARGS__); +#define AX_LOG_NOTICE_EX(tag,id,fmt,...) \ + AX_SYS_LogPrint_Ex(SYS_LOG_NOTICE, tag, id, MACRO_PURPLE"[N][%32s][%4d]: "fmt MACRO_END , __FUNCTION__, __LINE__, ##__VA_ARGS__); + +#endif //_AX_SYS_LOG_H_ diff --git a/sdk/axrt/lib/libax_engine.so b/sdk/axrt/lib/libax_engine.so new file mode 100644 index 0000000000000000000000000000000000000000..57089545dbf2226d274567367e60238bef051658 --- /dev/null +++ b/sdk/axrt/lib/libax_engine.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e246dec9aa1727164178db7e2494a182fe112b245a954b267db829aba8fd0d8 +size 268816 diff --git a/sdk/axrt/lib/libax_sys.so b/sdk/axrt/lib/libax_sys.so new file mode 100644 index 0000000000000000000000000000000000000000..7685c596691b69e8212c9fbf635f8cd0ae73bd57 Binary files /dev/null and b/sdk/axrt/lib/libax_sys.so differ diff --git a/sdk/build.sh b/sdk/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..863936fa554d990886f13d88ed5dd7e833cd2963 --- /dev/null +++ b/sdk/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# AX650 板端编译:kantts_tts +set -e +cd "$(dirname "$0")" +g++ -O3 -march=native -ffast-math -std=c++17 \ + -I include -I axrt/include \ + src/ax_engine.cpp src/kantts.cpp src/main.cpp \ + -L axrt/lib -lax_engine -lax_sys -lpthread \ + -o kantts_tts +echo "[build] OK: $(pwd)/kantts_tts" diff --git a/sdk/include/ax_engine.hpp b/sdk/include/ax_engine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ce5bd772761993a3bdf5b01633d604b318185234 --- /dev/null +++ b/sdk/include/ax_engine.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace kantts { + +// AXMODEL 推理会话(AXEngine C API,多输入/多输出,按张量名存取字节缓冲区)。 +class ModelSession { +public: + explicit ModelSession(const std::string& model_path); + ~ModelSession(); + ModelSession(const ModelSession&) = delete; + ModelSession& operator=(const ModelSession&) = delete; + + void SetInput(const std::string& name, const void* data, size_t bytes); + void Run(); + size_t OutputBytes(const std::string& name) const; + void GetOutput(const std::string& name, void* out, size_t bytes) const; + std::vector OutputShape(const std::string& name) const; + +private: + struct Impl; + Impl* impl_; +}; + +// 全局 AX 运行时初始化(进程内一次)。 +void AxRuntimeInit(); +void AxRuntimeDeinit(); + +} // namespace kantts diff --git a/sdk/include/kantts.hpp b/sdk/include/kantts.hpp new file mode 100644 index 0000000000000000000000000000000000000000..abf37a2e8dbf893f1a2d420d32670bf5c289f95b --- /dev/null +++ b/sdk/include/kantts.hpp @@ -0,0 +1,72 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace kantts { + +class ModelSession; +class EncOrt; + +// 权重容器:读 models/host_weights/manifest.json + *.bin。 +class Weights { +public: + void Load(const std::string& dir); + const std::vector& Get(const std::string& name) const; + const std::vector& Shape(const std::string& name) const; + bool Has(const std::string& name) const { return data_.count(name) != 0; } + +private: + std::map> data_; + std::map> shapes_; +}; + +// 前端:符号串 → am_enc 输入(对齐 KanTtsLinguisticUnit)。 +class Frontend { +public: + explicit Frontend(const std::string& resource_dir, const std::string& am_config); + // symbols: ttsfrd gen_tacotron_symbols 输出(如 "{b_c$tone3$...} {...}") + // 输出 4 个 int32 数组(ling/emo/spk 各 pad 到 128)+ 真实长度。 + struct EncInput { + std::vector ling; // 1*128*4 + std::vector emo; // 1*128 + std::vector spk; // 1*128 + std::vector len; // 1 + int T; + }; + EncInput Encode(const std::string& symbol_seq); + +private: + void BuildVocab(); + std::vector phones_; + std::vector tones_; + std::vector syllable_flags_; + std::vector word_segments_; + std::vector emotion_types_; + std::vector speakers_; +}; + +// 完整 TTS 管线。 +class KanttsPipeline { +public: + KanttsPipeline(const std::string& model_dir, const std::string& resource_dir, + const std::string& am_config); + ~KanttsPipeline(); + + // symbols 列表(每句一个)→ 16kHz float32 波形(PCM 幅度)。 + std::vector SynthesizeSymbols(const std::vector& symbols); + +private: + std::unique_ptr enc_, voc_; + Weights w_; + std::unique_ptr frontend_; +}; + +// host 管线(供内部/测试使用) +std::vector HostPredictors(const Weights& w, const std::vector& text_hid, + const std::vector& spk_hid, + const std::vector& emo_hid, int T); + +} // namespace kantts diff --git a/sdk/src/ax_engine.cpp b/sdk/src/ax_engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd97563317635c3baef4b7077dc0ea701bf00cb0 --- /dev/null +++ b/sdk/src/ax_engine.cpp @@ -0,0 +1,132 @@ +#include "ax_engine.hpp" + +#include +#include + +#include +#include +#include + +namespace kantts { + +namespace { + +std::vector ReadBinary(const std::string& path) { + std::ifstream f(path, std::ios::binary); + if (!f) throw std::runtime_error("cannot open " + path); + return std::vector(std::istreambuf_iterator(f), std::istreambuf_iterator()); +} + +void Check(int ret, const char* msg) { + if (ret != 0) throw std::runtime_error(msg); +} + +int g_refcount = 0; + +} // namespace + +void AxRuntimeInit() { + if (g_refcount++ > 0) return; + Check(AX_SYS_Init(), "AX_SYS_Init failed"); + AX_ENGINE_NPU_ATTR_T attr; + std::memset(&attr, 0, sizeof(attr)); + attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; + Check(AX_ENGINE_Init(&attr), "AX_ENGINE_Init failed"); +} + +void AxRuntimeDeinit() { + if (--g_refcount > 0) return; + AX_ENGINE_Deinit(); + AX_SYS_Deinit(); +} + +struct ModelSession::Impl { + AX_ENGINE_HANDLE handle = nullptr; + AX_ENGINE_CONTEXT_T context = nullptr; + AX_ENGINE_IO_INFO_T* info = nullptr; + AX_ENGINE_IO_T io {}; + std::vector inputs; + std::vector outputs; + std::vector model; + std::map input_index; + std::map output_index; + + explicit Impl(const std::string& path) : model(ReadBinary(path)) { + AX_ENGINE_HANDLE_EXTRA_T extra; + std::memset(&extra, 0, sizeof(extra)); + Check(AX_ENGINE_CreateHandleV2(&handle, model.data(), + static_cast(model.size()), &extra), + "AX_ENGINE_CreateHandleV2 failed"); + Check(AX_ENGINE_CreateContextV2(handle, &context), "AX_ENGINE_CreateContextV2 failed"); + Check(AX_ENGINE_GetIOInfo(handle, &info), "AX_ENGINE_GetIOInfo failed"); + inputs.resize(info->nInputSize); + outputs.resize(info->nOutputSize); + io.pInputs = inputs.data(); + io.nInputSize = info->nInputSize; + io.pOutputs = outputs.data(); + io.nOutputSize = info->nOutputSize; + for (AX_U32 i = 0; i < info->nInputSize; ++i) { + std::memset(&inputs[i], 0, sizeof(inputs[i])); + inputs[i].nSize = info->pInputs[i].nSize; + Check(AX_SYS_MemAllocCached(&inputs[i].phyAddr, &inputs[i].pVirAddr, + inputs[i].nSize, 128, (AX_S8*)"kantts_in"), + "input alloc failed"); + input_index[info->pInputs[i].pName] = i; + } + for (AX_U32 i = 0; i < info->nOutputSize; ++i) { + std::memset(&outputs[i], 0, sizeof(outputs[i])); + outputs[i].nSize = info->pOutputs[i].nSize; + Check(AX_SYS_MemAllocCached(&outputs[i].phyAddr, &outputs[i].pVirAddr, + outputs[i].nSize, 128, (AX_S8*)"kantts_out"), + "output alloc failed"); + output_index[info->pOutputs[i].pName] = i; + } + } + + ~Impl() { + for (auto& x : inputs) if (x.phyAddr) AX_SYS_MemFree(x.phyAddr, x.pVirAddr); + for (auto& x : outputs) if (x.phyAddr) AX_SYS_MemFree(x.phyAddr, x.pVirAddr); + if (handle) AX_ENGINE_DestroyHandle(handle); + } +}; + +ModelSession::ModelSession(const std::string& model_path) : impl_(new Impl(model_path)) {} +ModelSession::~ModelSession() { delete impl_; } + +void ModelSession::SetInput(const std::string& name, const void* data, size_t bytes) { + auto it = impl_->input_index.find(name); + if (it == impl_->input_index.end()) throw std::runtime_error("no input named " + name); + auto& buf = impl_->inputs[it->second]; + if (bytes > buf.nSize) throw std::runtime_error("input too large " + name); + std::memcpy(buf.pVirAddr, data, bytes); +} + +void ModelSession::Run() { + Check(AX_ENGINE_RunSyncV2(impl_->handle, impl_->context, &impl_->io), + "AX_ENGINE_RunSyncV2 failed"); +} + +size_t ModelSession::OutputBytes(const std::string& name) const { + auto it = impl_->output_index.find(name); + if (it == impl_->output_index.end()) throw std::runtime_error("no output named " + name); + return impl_->outputs[it->second].nSize; +} + +void ModelSession::GetOutput(const std::string& name, void* out, size_t bytes) const { + auto it = impl_->output_index.find(name); + if (it == impl_->output_index.end()) throw std::runtime_error("no output named " + name); + auto& buf = impl_->outputs[it->second]; + if (bytes > buf.nSize) bytes = buf.nSize; + std::memcpy(out, buf.pVirAddr, bytes); +} + +std::vector ModelSession::OutputShape(const std::string& name) const { + auto it = impl_->output_index.find(name); + if (it == impl_->output_index.end()) throw std::runtime_error("no output named " + name); + auto& t = impl_->info->pOutputs[it->second]; + std::vector shape(t.nShapeSize); + for (AX_U32 i = 0; i < t.nShapeSize; ++i) shape[i] = t.pShape[i]; + return shape; +} + +} // namespace kantts diff --git a/sdk/src/kantts.cpp b/sdk/src/kantts.cpp new file mode 100644 index 0000000000000000000000000000000000000000..108fa0744d04045e6a219c6013496779bd8ecd26 --- /dev/null +++ b/sdk/src/kantts.cpp @@ -0,0 +1,871 @@ +#include "kantts.hpp" + +#include "ax_engine.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace kantts { +namespace { + +std::vector LoadBin(const std::string& path) { + std::ifstream f(path, std::ios::binary); + if (!f) throw std::runtime_error("cannot open " + path); + std::vector bytes((std::istreambuf_iterator(f)), std::istreambuf_iterator()); + if (bytes.size() % 4 != 0) throw std::runtime_error("bad bin size " + path); + std::vector out(bytes.size() / 4); + std::memcpy(out.data(), bytes.data(), bytes.size()); + return out; +} + +void Matmul(const std::vector& x, const std::vector& w, const std::vector& b, + int n, int in_d, int out_d, std::vector& y) { + y.assign(n * out_d, 0.0f); + for (int i = 0; i < n; ++i) { + const float* xp = x.data() + i * in_d; + for (int o = 0; o < out_d; ++o) { + float acc = b.empty() ? 0.0f : b[o]; + const float* wp = w.data() + o * in_d; + int k = 0; + float32x4_t v = vdupq_n_f32(0.0f); + for (; k + 4 <= in_d; k += 4) + v = vfmaq_f32(v, vld1q_f32(xp + k), vld1q_f32(wp + k)); + acc += vaddvq_f32(v); + for (; k < in_d; ++k) acc += xp[k] * wp[k]; + y[i * out_d + o] = acc; + } + } +} + +void Matmul(const float* x, const float* w, const float* b, int n, int in_d, int out_d, + std::vector& y) { + y.assign(n * out_d, 0.0f); + for (int i = 0; i < n; ++i) { + const float* xp = x + i * in_d; + for (int o = 0; o < out_d; ++o) { + float acc = b ? b[o] : 0.0f; + const float* wp = w + o * in_d; + int k = 0; + float32x4_t v = vdupq_n_f32(0.0f); + for (; k + 4 <= in_d; k += 4) + v = vfmaq_f32(v, vld1q_f32(xp + k), vld1q_f32(wp + k)); + acc += vaddvq_f32(v); + for (; k < in_d; ++k) acc += xp[k] * wp[k]; + y[i * out_d + o] = acc; + } + } +} + +void LayerNorm(const std::vector& x, const std::vector& g, + const std::vector& b, int n, int d, std::vector& y) { + y.resize(n * d); + for (int i = 0; i < n; ++i) { + float mean = 0, var = 0; + for (int k = 0; k < d; ++k) mean += x[i * d + k]; + mean /= d; + for (int k = 0; k < d; ++k) var += (x[i * d + k] - mean) * (x[i * d + k] - mean); + var /= d; + float inv = 1.0f / std::sqrt(var + 1e-6f); + for (int k = 0; k < d; ++k) y[i * d + k] = (x[i * d + k] - mean) * inv * g[k] + b[k]; + } +} + +void LayerNorm(const float* x, const float* g, const float* b, int n, int d, + std::vector& y) { + y.resize(n * d); + for (int i = 0; i < n; ++i) { + float mean = 0, var = 0; + for (int k = 0; k < d; ++k) mean += x[i * d + k]; + mean /= d; + for (int k = 0; k < d; ++k) var += (x[i * d + k] - mean) * (x[i * d + k] - mean); + var /= d; + float inv = 1.0f / std::sqrt(var + 1e-6f); + for (int k = 0; k < d; ++k) y[i * d + k] = (x[i * d + k] - mean) * inv * g[k] + b[k]; + } +} + +void Conv1dSame(const std::vector& x, const std::vector& wgt, + const std::vector& bias, int T, int C, int O, int K, + std::vector& y) { + int pad = (K - 1) / 2; + y.assign(T * O, 0.0f); + for (int t = 0; t < T; ++t) + for (int o = 0; o < O; ++o) { + float acc = bias.empty() ? 0.0f : bias[o]; + for (int k = 0; k < K; ++k) { + int tt = t - pad + k; + if (tt < 0 || tt >= T) continue; + for (int c = 0; c < C; ++c) + acc += x[tt * C + c] * wgt[(o * C + c) * K + k]; + } + y[t * O + o] = acc; + } +} + +void DepthwiseShift(const std::vector& x, const std::vector& wgt, + int T, int C, int K, int lp, int rp, std::vector& y) { + y.assign(T * C, 0.0f); + for (int c = 0; c < C; ++c) + for (int t = 0; t < T; ++t) { + float acc = 0; + for (int k = 0; k < K; ++k) { + int tt = t - lp + k; + if (tt < 0 || tt >= T) continue; + acc += x[tt * C + c] * wgt[c * K + k]; + } + y[t * C + c] = acc; + } +} + +void LstmCell(const std::vector& x, const std::vector& w_ih, + const std::vector& w_hh, const std::vector& b_ih, + const std::vector& b_hh, std::vector& h, std::vector& c, + int units) { + std::vector gates(4 * units, 0.0f); + for (int g = 0; g < 4 * units; ++g) { + float acc = b_ih[g] + b_hh[g]; + for (int k = 0; k < (int)x.size(); ++k) acc += x[k] * w_ih[g * x.size() + k]; + for (int k = 0; k < units; ++k) acc += h[k] * w_hh[g * units + k]; + gates[g] = acc; + } + auto sig = [](float v) { return 1.0f / (1.0f + std::exp(-v)); }; + for (int u = 0; u < units; ++u) { + float i = sig(gates[u]); + float f = sig(gates[units + u]); + float g = std::tanh(gates[2 * units + u]); + float o = sig(gates[3 * units + u]); + c[u] = f * c[u] + i * g; + h[u] = o * std::tanh(c[u]); + } +} + +void Blstm(const std::vector& x, const Weights& w, const std::string& pre, + int T, int in_d, int units, std::vector& y) { + const auto& wih = w.Get(pre + "_blstm_w_ih"); + const auto& whh = w.Get(pre + "_blstm_w_hh"); + const auto& bih = w.Get(pre + "_blstm_b_ih"); + const auto& bhh = w.Get(pre + "_blstm_b_hh"); + const auto& wihr = w.Get(pre + "_blstm_w_ih_r"); + const auto& whhr = w.Get(pre + "_blstm_w_hh_r"); + const auto& bihr = w.Get(pre + "_blstm_b_ih_r"); + const auto& bhhr = w.Get(pre + "_blstm_b_hh_r"); + std::vector hf(units, 0), cf(units, 0), hb(units, 0), cb(units, 0); + y.assign(T * 2 * units, 0.0f); + std::vector xi(in_d); + for (int t = 0; t < T; ++t) { + std::copy(x.begin() + t * in_d, x.begin() + (t + 1) * in_d, xi.begin()); + LstmCell(xi, wih, whh, bih, bhh, hf, cf, units); + std::copy(hf.begin(), hf.end(), y.begin() + t * 2 * units); + } + for (int t = T - 1; t >= 0; --t) { + std::copy(x.begin() + t * in_d, x.begin() + (t + 1) * in_d, xi.begin()); + LstmCell(xi, wihr, whhr, bihr, bhhr, hb, cb, units); + std::copy(hb.begin(), hb.end(), y.begin() + t * 2 * units + units); + } +} + +std::vector FsmnEncoder(const std::vector& x, const Weights& w, + const std::string& pre, int T, int C, const std::vector& shift) { + std::vector cur = x; + int layers = 0; + while (w.Has(pre + "_ffn" + std::to_string(layers) + "_w1")) ++layers; + for (int i = 0; i < layers; ++i) { + int mid = (int)w.Shape(pre + "_ffn" + std::to_string(i) + "_w1")[0]; + std::vector c1; + Conv1dSame(cur, w.Get(pre + "_ffn" + std::to_string(i) + "_w1"), + w.Get(pre + "_ffn" + std::to_string(i) + "_b1"), T, C, mid, 1, c1); + for (auto& v : c1) v = std::max(v, 0.0f); + int out_c = (int)w.Shape(pre + "_ffn" + std::to_string(i) + "_w2")[0]; + std::vector c2; + Conv1dSame(c1, w.Get(pre + "_ffn" + std::to_string(i) + "_w2"), + w.Get(pre + "_ffn" + std::to_string(i) + "_b2"), T, mid, out_c, 1, c2); + int fsize = (int)w.Shape(pre + "_mem" + std::to_string(i) + "_conv")[2]; + int sh = shift.empty() ? 0 : shift[i]; + int lp = (fsize - 1) / 2 + (sh > 0 ? sh : 0); + int rp = (fsize - 1) / 2 - (sh > 0 ? sh : 0); + std::vector mem; + DepthwiseShift(c2, w.Get(pre + "_mem" + std::to_string(i) + "_conv"), T, out_c, fsize, + lp, rp, mem); + for (int t = 0; t < T; ++t) + for (int c = 0; c < out_c; ++c) mem[t * out_c + c] += c2[t * out_c + c]; + if (out_c == C) + for (int t = 0; t < T; ++t) + for (int c = 0; c < out_c; ++c) mem[t * out_c + c] += cur[t * C + c]; + cur = mem; + C = out_c; + } + return cur; +} + +std::vector VarFsmnRnnPredictor(const std::vector& x, const Weights& w, + const std::string& pre, int T, int in_d) { + std::vector h = FsmnEncoder(x, w, pre, T, in_d, {0, 0, 0}); + std::vector bh; + Blstm(h, w, pre, T, 128, 128, bh); + std::vector out(T); + const auto& fw = w.Get(pre + "_fc_w"); + const auto& fb = w.Get(pre + "_fc_b"); + for (int t = 0; t < T; ++t) { + float acc = fb[0]; + for (int k = 0; k < 256; ++k) acc += bh[t * 256 + k] * fw[0 * 256 + k]; + out[t] = acc; + } + return out; +} + +std::vector DurationAr(const std::vector& cond, const Weights& w, int T, int in_d) { + std::vector h0(128, 0), c0(128, 0), h1(128, 0), c1(128, 0); + std::vector x(1, 0.0f), out(T); + const auto& p0w = w.Get("dur_pre0_w"); + const auto& p0b = w.Get("dur_pre0_b"); + const auto& p1w = w.Get("dur_pre1_w"); + const auto& p1b = w.Get("dur_pre1_b"); + const auto& fw = w.Get("dur_fc_w"); + const auto& fb = w.Get("dur_fc_b"); + std::vector inp, tmp; + for (int t = 0; t < T; ++t) { + Matmul(x, p0w, p0b, 1, 1, 128, inp); + for (auto& v : inp) v = std::max(v, 0.0f); + Matmul(inp, p1w, p1b, 1, 128, 128, tmp); + for (auto& v : tmp) v = std::max(v, 0.0f); + std::vector xin(tmp); + xin.insert(xin.end(), cond.begin() + t * in_d, cond.begin() + (t + 1) * in_d); + LstmCell(xin, w.Get("dur_lstm_w_ih0"), w.Get("dur_lstm_w_hh0"), w.Get("dur_lstm_b_ih0"), + w.Get("dur_lstm_b_hh0"), h0, c0, 128); + LstmCell(h0, w.Get("dur_lstm_w_ih1"), w.Get("dur_lstm_w_hh1"), w.Get("dur_lstm_b_ih1"), + w.Get("dur_lstm_b_hh1"), h1, c1, 128); + float acc = fb[0]; + for (int k = 0; k < 128; ++k) acc += h1[k] * fw[0 * 128 + k]; + x[0] = std::max(acc, 0.0f); + out[t] = x[0]; + } + return out; +} + +} // namespace + +void Weights::Load(const std::string& dir) { + std::ifstream f(dir + "/manifest.json"); + if (!f) throw std::runtime_error("missing weights manifest"); + std::stringstream ss; + ss << f.rdbuf(); + std::string text = ss.str(); + std::regex entry_re("\"([A-Za-z0-9_]+)\"\\s*:\\s*\\[([0-9,\\s]*)\\]"); + for (std::sregex_iterator it(text.begin(), text.end(), entry_re), end; it != end; ++it) { + std::string name = it->str(1); + std::vector shape; + std::stringstream dims(it->str(2)); + std::string d; + while (std::getline(dims, d, ',')) { + d.erase(std::remove_if(d.begin(), d.end(), ::isspace), d.end()); + if (!d.empty()) shape.push_back(std::stoll(d)); + } + data_[name] = LoadBin(dir + "/" + name + ".bin"); + shapes_[name] = shape; + } +} + +const std::vector& Weights::Get(const std::string& name) const { + auto it = data_.find(name); + if (it == data_.end()) throw std::runtime_error("missing weight " + name); + return it->second; +} + +const std::vector& Weights::Shape(const std::string& name) const { + auto it = shapes_.find(name); + if (it == shapes_.end()) throw std::runtime_error("missing shape " + name); + return it->second; +} + +Frontend::Frontend(const std::string& resource_dir, const std::string& am_config) { + // phones from PhoneSet.xml + std::ifstream pf(resource_dir + "/PinYin/PhoneSet.xml"); + if (!pf) throw std::runtime_error("cannot open PhoneSet.xml"); + std::string xml((std::istreambuf_iterator(pf)), std::istreambuf_iterator()); + std::regex name_re("([^<]+)"); + for (std::sregex_iterator it(xml.begin(), xml.end(), name_re), end; it != end; ++it) + phones_.push_back("@" + it->str(1)); + // 官方 parse_phoneset 在 PhoneSet.xml 音素后追加 #1..#4(静音/停顿标记) + for (int i = 1; i <= 4; ++i) phones_.push_back("@#" + std::to_string(i)); + std::ifstream tf(resource_dir + "/PinYin/tonelist.txt"); + std::string line; + while (std::getline(tf, line)) { + line.erase(std::remove_if(line.begin(), line.end(), ::isspace), line.end()); + tones_.push_back(line.empty() ? "tone_none" : "tone" + line); + } + syllable_flags_ = {"s_begin", "s_end", "s_none", "s_both", "s_middle"}; + word_segments_ = {"word_begin", "word_end", "word_middle", "word_both", "word_none"}; + emotion_types_ = { + "emotion_none", "emotion_neutral", "emotion_angry", "emotion_disgust", "emotion_fear", + "emotion_happy", "emotion_sad", "emotion_surprise", "emotion_calm", "emotion_gentle", + "emotion_relax", "emotion_lyrical", "emotion_serious", "emotion_disgruntled", + "emotion_satisfied", "emotion_disappointed", "emotion_excited", "emotion_anxiety", + "emotion_jealousy", "emotion_hate", "emotion_pity", "emotion_pleasure", "emotion_arousal", + "emotion_dominance", "emotion_placeholder1", "emotion_placeholder2", "emotion_placeholder3", + "emotion_placeholder4", "emotion_placeholder5", "emotion_placeholder6", + "emotion_placeholder7", "emotion_placeholder8", "emotion_placeholder9"}; + std::ifstream cf(am_config); + while (std::getline(cf, line)) { + if (line.find("speaker_list") != std::string::npos) { + auto pos = line.find(':'); + std::string list = line.substr(pos + 1); + std::stringstream ls(list); + std::string s; + while (std::getline(ls, s, ',')) { + s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end()); + if (!s.empty()) speakers_.push_back(s); + } + break; + } + } +} + +static std::vector MakeVocab(const std::vector& items) { + std::vector v; // list("") == [],无前导空串 + v.insert(v.end(), items.begin(), items.end()); + v.push_back("_"); + v.push_back("~"); + v.push_back("@[MASK]"); + return v; +} + +static void EncodeCategory(const std::vector& vocab, + const std::vector& parts, std::vector& ids) { + for (const auto& p : parts) { + auto it = std::find(vocab.begin(), vocab.end(), p); + ids.push_back(it == vocab.end() ? 0 : (int)(it - vocab.begin())); + } + auto eit = std::find(vocab.begin(), vocab.end(), "~"); + ids.push_back((int)(eit - vocab.begin())); +} + +static void EncodeSy(const std::vector& vocab, + const std::vector& parts, std::vector& ids) { + for (const auto& p : parts) { + std::string key = "@" + p; // 原版按 ARPAbet 处理:{x} → "@x" + auto it = std::find(vocab.begin(), vocab.end(), key); + if (it != vocab.end()) ids.push_back((int)(it - vocab.begin())); + } + auto eit = std::find(vocab.begin(), vocab.end(), "~"); + ids.push_back((int)(eit - vocab.begin())); +} + +Frontend::EncInput Frontend::Encode(const std::string& symbol_seq) { + auto sy_v = MakeVocab(phones_); + auto tone_v = MakeVocab(tones_); + auto syll_v = MakeVocab(syllable_flags_); + auto ws_v = MakeVocab(word_segments_); + auto emo_v = MakeVocab(emotion_types_); + auto spk_v = MakeVocab(speakers_); + std::vector tokens; + { + std::stringstream ss(symbol_seq); + std::string t; + while (ss >> t) tokens.push_back(t); + } + std::vector> parts(6); + for (const auto& t : tokens) { + std::string inner = t; + if (!inner.empty() && inner.front() == '{') inner.erase(inner.begin()); + if (!inner.empty() && inner.back() == '}') inner.pop_back(); + std::stringstream ps(inner); + std::string p; + int idx = 0; + while (std::getline(ps, p, '$') && idx < 6) parts[idx++].push_back(p); + } + std::vector sy, tone, syll, ws, emo, spk; + EncodeSy(sy_v, parts[0], sy); + EncodeCategory(tone_v, parts[1], tone); + EncodeCategory(syll_v, parts[2], syll); + EncodeCategory(ws_v, parts[3], ws); + EncodeCategory(emo_v, parts[4], emo); + EncodeCategory(spk_v, parts[5], spk); + int T = (int)sy.size() - 1; // 去掉末尾 ~ + const int MT = 128; + EncInput out; + out.ling.assign(MT * 4, 0); + out.emo.assign(MT, 0); + out.spk.assign(MT, 0); + for (int i = 0; i < T; ++i) { + out.ling[i * 4 + 0] = sy[i]; + out.ling[i * 4 + 1] = tone[i]; + out.ling[i * 4 + 2] = syll[i]; + out.ling[i * 4 + 3] = ws[i]; + out.emo[i] = emo[i]; + out.spk[i] = spk[i]; + } + out.len = {T}; + out.T = T; + return out; +} + +namespace { + +// build_memory:text/spk/emo (T,32) → memory (M,160) + lr_len + durations +void BuildMemory(const std::vector& text_hid, const std::vector& spk_hid, + const std::vector& emo_hid, const Weights& w, int T, + std::vector& memory, int& lr_len, std::vector& durations) { + std::vector var_in(T * 96); + for (int t = 0; t < T; ++t) + for (int c = 0; c < 32; ++c) { + var_in[t * 96 + c] = text_hid[t * 32 + c]; + var_in[t * 96 + 32 + c] = spk_hid[t * 32 + c]; + var_in[t * 96 + 64 + c] = emo_hid[t * 32 + c]; + } + auto pitch = VarFsmnRnnPredictor(var_in, w, "pitch", T, 96); + auto energy = VarFsmnRnnPredictor(var_in, w, "energy", T, 96); + if (std::getenv("KANTTS_DUMP_ENC")) { + { + std::ofstream f("/tmp/kt/enc_pitch.bin", std::ios::binary); + f.write((const char*)pitch.data(), pitch.size() * 4); + } + { + std::ofstream f("/tmp/kt/enc_energy.bin", std::ios::binary); + f.write((const char*)energy.data(), energy.size() * 4); + } + } + std::vector pe, ee; + Conv1dSame(pitch, w.Get("pitch_emb_w"), w.Get("pitch_emb_b"), T, 1, 32, 9, pe); + Conv1dSame(energy, w.Get("energy_emb_w"), w.Get("energy_emb_b"), T, 1, 32, 9, ee); + std::vector aug(T * 32); + for (int t = 0; t < T * 32; ++t) aug[t] = text_hid[t] + pe[t] + ee[t]; + if (std::getenv("KANTTS_DUMP_ENC")) { + std::ofstream f("/tmp/kt/enc_aug.bin", std::ios::binary); + f.write((const char*)aug.data(), aug.size() * 4); + } + std::vector cond(T * 96); + for (int t = 0; t < T; ++t) + for (int c = 0; c < 32; ++c) { + cond[t * 96 + c] = aug[t * 32 + c]; + cond[t * 96 + 32 + c] = spk_hid[t * 32 + c]; + cond[t * 96 + 64 + c] = emo_hid[t * 32 + c]; + } + auto log_dur = DurationAr(cond, w, T, 96); + if (std::getenv("KANTTS_DUMP_ENC")) { + std::ofstream f("/tmp/kt/enc_logdur.bin", std::ios::binary); + f.write((const char*)log_dur.data(), log_dur.size() * 4); + } + durations.resize(T); + int sum = 0; + std::vector reps(T); + for (int t = 0; t < T; ++t) { + durations[t] = std::exp(log_dur[t]) - 1.0f; + reps[t] = (int)(durations[t] + 0.5f); + sum += reps[t]; + } + int pad = 3 - sum % 3; + if (pad == 3) pad = 0; + int P = sum + pad; + // LR text/spk/emo + auto expand = [&](const std::vector& src, std::vector& dst) { + dst.assign(P * 32, 0.0f); + int pos = 0; + for (int t = 0; t < T; ++t) + for (int r = 0; r < reps[t]; ++r) { + std::copy(src.begin() + t * 32, src.begin() + (t + 1) * 32, + dst.begin() + (pos++) * 32); + } + }; + std::vector lr_text, lr_emo, lr_spk; + expand(aug, lr_text); + expand(emo_hid, lr_emo); + expand(spk_hid, lr_spk); + // dur position encoder + std::vector rc(T + 1, 0); + for (int t = 0; t < T; ++t) rc[t + 1] = rc[t] + reps[t]; + std::vector lr_pos(P * 32, 0.0f); + for (int p = 0; p < P; ++p) { + int ph = 0; + for (int t = 0; t < T; ++t) + if (rc[t] <= p && p < rc[t + 1]) { ph = p - rc[t] + 1; break; } + for (int c = 0; c < 32; ++c) { + float inv = std::pow(10000.0f, 2.0f * (c / 2) / 32.0f); + float v = ph / inv; + lr_pos[p * 32 + c] = (c % 2 == 0) ? std::sin(v) : std::cos(v); + } + } + for (int i = 0; i < P * 32; ++i) lr_text[i] += lr_pos[i]; + int M = P / 3; + memory.assign(M * 160, 0.0f); + for (int m = 0; m < M; ++m) { + for (int c = 0; c < 96; ++c) memory[m * 160 + c] = lr_text[m * 96 + c]; + for (int c = 0; c < 32; ++c) { + memory[m * 160 + 96 + c] = lr_spk[m * 96 + c]; + memory[m * 160 + 128 + c] = lr_emo[m * 96 + c]; + } + } + lr_len = sum; +} + +// PNCA 单步解码(host) +struct Decoder { + struct LW { + const float* ln_w; const float* ln_b; + const float* xqkv_w; const float* xqkv_b; + const float* hkv_w; const float* hkv_b; + const float* fcx_w; const float* fcx_b; + const float* fch_w; const float* fch_b; + const float* pln_w; const float* pln_b; + const float* p1_w; const float* p1_b; + const float* p2_w; const float* p2_b; + } lw[12]; + const float* pre0_w; const float* pre0_b; + const float* pre1_w; const float* pre1_b; + const float* pre2_w; const float* pre2_b; + const float* proj_w; const float* proj_b; + const float* ln_w; const float* ln_b; + const float* out_w; const float* out_b; + int M; + std::vector hk[12], hv[12]; + + explicit Decoder(const Weights& w) : M(0) { + auto P = [&](const char* n) { return w.Get(n).data(); }; + pre0_w = P("pre0_w"); pre0_b = P("pre0_b"); + pre1_w = P("pre1_w"); pre1_b = P("pre1_b"); + pre2_w = P("pre2_w"); pre2_b = P("pre2_b"); + proj_w = P("proj_w"); proj_b = P("proj_b"); + ln_w = P("ln_w"); ln_b = P("ln_b"); + out_w = P("out_w"); out_b = P("out_b"); + for (int li = 0; li < 12; ++li) { + std::string p = "l" + std::to_string(li) + "_"; + lw[li].ln_w = w.Get(p + "ln_w").data(); lw[li].ln_b = w.Get(p + "ln_b").data(); + lw[li].xqkv_w = w.Get(p + "xqkv_w").data(); lw[li].xqkv_b = w.Get(p + "xqkv_b").data(); + lw[li].hkv_w = w.Get(p + "hkv_w").data(); lw[li].hkv_b = w.Get(p + "hkv_b").data(); + lw[li].fcx_w = w.Get(p + "fcx_w").data(); lw[li].fcx_b = w.Get(p + "fcx_b").data(); + lw[li].fch_w = w.Get(p + "fch_w").data(); lw[li].fch_b = w.Get(p + "fch_b").data(); + lw[li].pln_w = w.Get(p + "pln_w").data(); lw[li].pln_b = w.Get(p + "pln_b").data(); + lw[li].p1_w = w.Get(p + "p1_w").data(); lw[li].p1_b = w.Get(p + "p1_b").data(); + lw[li].p2_w = w.Get(p + "p2_w").data(); lw[li].p2_b = w.Get(p + "p2_b").data(); + } + } + + void Prepare(const std::vector& memory) { + M = (int)memory.size() / 160; + std::vector mem_p(270 * 160, 0.0f); + std::copy(memory.begin(), memory.end(), mem_p.begin()); + for (int li = 0; li < 12; ++li) { + std::vector hkv(270 * 256); + Matmul(mem_p.data(), lw[li].hkv_w, lw[li].hkv_b, 270, 160, 256, hkv); + hk[li].assign(8 * 270 * 16, 0.0f); + hv[li].assign(8 * 270 * 16, 0.0f); + for (int m = 0; m < 270; ++m) + for (int h = 0; h < 8; ++h) + for (int d = 0; d < 16; ++d) { + hk[li][(h * 270 + m) * 16 + d] = hkv[(m * 2 + 0) * 128 + h * 16 + d]; + hv[li][(h * 270 + m) * 16 + d] = hkv[(m * 2 + 1) * 128 + h * 16 + d]; + } + } + } + + void Step(const std::vector& frame, const std::vector& mem_step, + std::vector& xk, std::vector& xv, int s, int xb, + std::vector& out) { + std::vector x(256); + for (int o = 0; o < 256; ++o) { + float acc = pre0_b[o]; + for (int k = 0; k < 80; ++k) acc += frame[k] * pre0_w[o * 80 + k]; + x[o] = std::max(acc, 0.0f); + } + std::vector x1(256); + for (int o = 0; o < 256; ++o) { + float acc = pre1_b[o]; + for (int k = 0; k < 256; ++k) acc += x[k] * pre1_w[o * 256 + k]; + x1[o] = std::max(acc, 0.0f); + } + x = std::move(x1); + std::vector x2(128); + for (int o = 0; o < 128; ++o) { + float acc = pre2_b[o]; + for (int k = 0; k < 256; ++k) acc += x[k] * pre2_w[o * 256 + k]; + x2[o] = acc; + } + x = std::move(x2); + x.resize(128); + x.insert(x.begin(), mem_step.begin(), mem_step.end()); // (1,288) + std::vector xp(128); + for (int o = 0; o < 128; ++o) { + float acc = proj_b[o]; + for (int k = 0; k < 288; ++k) acc += x[k] * proj_w[o * 288 + k]; + xp[o] = acc * std::sqrt(128.0f); + } + x = std::move(xp); + int xs0 = std::max(s - xb, 0); + int he = std::min(s + xb + 1, M); + std::vector xmask(270, -1e9f), hmask(270, -1e9f); + for (int m = xs0; m <= s; ++m) xmask[m] = 0.0f; + for (int m = s; m < he; ++m) hmask[m] = 0.0f; + for (int li = 0; li < 12; ++li) { + std::vector residual = x; + std::vector lnx; + LayerNorm(x.data(), lw[li].ln_w, lw[li].ln_b, 1, 128, lnx); + std::vector qkv; + Matmul(lnx.data(), lw[li].xqkv_w, lw[li].xqkv_b, 1, 128, 384, qkv); + auto qp = [&](int off) { + std::vector q(8 * 16); + for (int h = 0; h < 8; ++h) + for (int d = 0; d < 16; ++d) q[h * 16 + d] = qkv[off + h * 16 + d]; + return q; + }; + std::vector q = qp(0), k = qp(128), v = qp(256); + // 原位写入本步 kv(等价参考实现的 append),注意力直接读状态 + for (int h = 0; h < 8; ++h) + for (int d = 0; d < 16; ++d) { + xk[(li * 8 + h) * 270 * 16 + s * 16 + d] = k[h * 16 + d]; + xv[(li * 8 + h) * 270 * 16 + s * 16 + d] = v[h * 16 + d]; + } + // x attention + std::vector wx(8 * 270), ox(128, 0.0f); + for (int h = 0; h < 8; ++h) { + float mx = -1e30f; + for (int m = xs0; m <= s; ++m) { + float acc = 0; + for (int d = 0; d < 16; ++d) + acc += q[h * 16 + d] * xk[(li * 8 + h) * 270 * 16 + m * 16 + d]; + wx[h * 270 + m] = acc / 4.0f; + mx = std::max(mx, wx[h * 270 + m]); + } + float sum = 0; + for (int m = xs0; m <= s; ++m) { + wx[h * 270 + m] = std::exp(wx[h * 270 + m] - mx); + sum += wx[h * 270 + m]; + } + for (int d = 0; d < 16; ++d) { + float acc = 0; + for (int m = xs0; m <= s; ++m) + acc += wx[h * 270 + m] / sum * xv[(li * 8 + h) * 270 * 16 + m * 16 + d]; + ox[h * 16 + d] = acc; + } + } + std::vector oxl; + Matmul(ox.data(), lw[li].fcx_w, lw[li].fcx_b, 1, 128, 128, oxl); + // h attention(band 上限截到有效 memory 行数) + std::vector oh(128, 0.0f); + for (int h = 0; h < 8; ++h) { + float mx = -1e30f; + std::vector wh(270); + for (int m = s; m < he; ++m) { + float acc = 0; + for (int d = 0; d < 16; ++d) + acc += q[h * 16 + d] * hk[li][(h * 270 + m) * 16 + d]; + wh[m] = acc / 4.0f; + mx = std::max(mx, wh[m]); + } + float sum = 0; + for (int m = s; m < he; ++m) { + wh[m] = std::exp(wh[m] - mx); + sum += wh[m]; + } + for (int d = 0; d < 16; ++d) { + float acc = 0; + for (int m = s; m < he; ++m) + acc += wh[m] / sum * hv[li][(h * 270 + m) * 16 + d]; + oh[h * 16 + d] = acc; + } + } + std::vector ohl; + Matmul(oh.data(), lw[li].fch_w, lw[li].fch_b, 1, 128, 128, ohl); + for (int c = 0; c < 128; ++c) x[c] = oxl[c] + ohl[c] + residual[c]; + // pos_ffn(conv k=1,p1 输出 1024 维) + LayerNorm(x.data(), lw[li].pln_w, lw[li].pln_b, 1, 128, lnx); + std::vector px(1024); + for (int o = 0; o < 1024; ++o) { + float acc = lw[li].p1_b[o]; + for (int k = 0; k < 128; ++k) acc += lnx[k] * lw[li].p1_w[o * 128 + k]; + px[o] = std::max(acc, 0.0f); + } + for (int o = 0; o < 128; ++o) { + float acc = lw[li].p2_b[o]; + for (int k = 0; k < 1024; ++k) acc += px[k] * lw[li].p2_w[o * 1024 + k]; + x[o] = acc + x[o]; + } + } + LayerNorm(x.data(), ln_w, ln_b, 1, 128, x); + Matmul(x.data(), out_w, out_b, 1, 128, 240, out); + } +}; + + +std::vector Postnet(const std::vector& dec, const Weights& w, int T) { + std::vector x = FsmnEncoder(dec, w, "post", T, 80, {17, 17, 17, 17}); + std::vector h(128, 0), c(128, 0), out(T * 128); + std::vector xi(256); + for (int t = 0; t < T; ++t) { + std::copy(x.begin() + t * 256, x.begin() + (t + 1) * 256, xi.begin()); + LstmCell(xi, w.Get("post_lstm_w_ih"), w.Get("post_lstm_w_hh"), w.Get("post_lstm_b_ih"), + w.Get("post_lstm_b_hh"), h, c, 128); + std::copy(h.begin(), h.end(), out.begin() + t * 128); + } + std::vector res(T * 80); + Matmul(out, w.Get("post_fc_w"), w.Get("post_fc_b"), T, 128, 80, res); + for (int i = 0; i < T * 80; ++i) res[i] += dec[i]; + return res; +} + +} // namespace + +KanttsPipeline::KanttsPipeline(const std::string& model_dir, const std::string& resource_dir, + const std::string& am_config) + : enc_(new ModelSession(model_dir + "/am_enc.axmodel")), + voc_(new ModelSession(model_dir + "/voc.axmodel")), + frontend_(new Frontend(resource_dir, am_config)) { + w_.Load(model_dir + "/host_weights"); + std::fprintf(stderr, "[stage] weights loaded\n"); +} + +KanttsPipeline::~KanttsPipeline() = default; + +std::vector KanttsPipeline::SynthesizeSymbols( + const std::vector& symbols) { + std::vector audio; + for (const auto& sym : symbols) { + auto in = frontend_->Encode(sym); + auto t_stage = std::chrono::steady_clock::now(); + std::fprintf(stderr, "[stage] encoded T=%d\n", in.T); + int T = in.T; + constexpr int MT = 128, D = 512, U = 32; + const float* sy_w = w_.Get("sy_emb").data(); // (147,512) + const float* tone_w = w_.Get("tone_emb").data(); // (10,512) + const float* syll_w = w_.Get("syll_emb").data(); // (8,512) + const float* ws_w = w_.Get("ws_emb").data(); // (8,512) + const float* spk_w = w_.Get("spk_emb").data(); // (9,32) + const float* emo_w = w_.Get("emo_emb").data(); // (36,32) + const float* pos = w_.Get("pos_enc").data(); // (128,512) + std::vector x_emb(MT * D, 0.0f), attn_mask(MT, 0.0f), mask_f(MT, 0.0f); + for (int t = 0; t < MT; ++t) { + bool valid = t < T; + mask_f[t] = valid ? 1.0f : 0.0f; + attn_mask[t] = valid ? 0.0f : -3e4f; + if (!valid) continue; + const int* l = &in.ling[t * 4]; + for (int c = 0; c < D; ++c) { + float v = sy_w[l[0] * D + c] + tone_w[l[1] * D + c] + + syll_w[l[2] * D + c] + ws_w[l[3] * D + c]; + x_emb[t * D + c] = v * std::sqrt(128.0f) + pos[t * D + c]; + } + } + std::vector text_hid(MT * U), spk_hid(MT * U), emo_hid(MT * U); + for (int t = 0; t < MT; ++t) { + int s = in.spk[t], e = in.emo[t]; + for (int c = 0; c < U; ++c) { + spk_hid[t * U + c] = spk_w[s * U + c]; + emo_hid[t * U + c] = emo_w[e * U + c]; + } + } + enc_->SetInput("x_emb", x_emb.data(), x_emb.size() * 4); + enc_->SetInput("attn_mask", attn_mask.data(), attn_mask.size() * 4); + enc_->SetInput("mask_f", mask_f.data(), mask_f.size() * 4); + enc_->Run(); + std::vector th_all(MT * U); + enc_->GetOutput("output", th_all.data(), th_all.size() * 4); + text_hid.assign(th_all.begin(), th_all.end()); + text_hid.resize(T * U); + spk_hid.resize(T * U); + emo_hid.resize(T * U); + std::fprintf(stderr, "[timing] enc %.0fms\n", std::chrono::duration(std::chrono::steady_clock::now()-t_stage).count()); + t_stage = std::chrono::steady_clock::now(); + if (std::getenv("KANTTS_DUMP_ENC")) { + std::ofstream f("/tmp/kt/enc_text.bin", std::ios::binary); + f.write((const char*)text_hid.data(), text_hid.size() * 4); + std::ofstream f2("/tmp/kt/enc_spk.bin", std::ios::binary); + f2.write((const char*)spk_hid.data(), spk_hid.size() * 4); + std::ofstream f3("/tmp/kt/enc_emo.bin", std::ios::binary); + f3.write((const char*)emo_hid.data(), emo_hid.size() * 4); + std::ofstream f4("/tmp/kt/enc_ling.bin", std::ios::binary); + f4.write((const char*)in.ling.data(), in.ling.size() * 4); + } + std::vector memory; + int lr_len = 0; + std::vector durations; + const char* test_mem = std::getenv("KANTTS_TEST_MEM"); + if (test_mem) { + std::ifstream mf(test_mem, std::ios::binary); + std::vector mb((std::istreambuf_iterator(mf)), {}); + memory.resize(mb.size() / 4); + std::memcpy(memory.data(), mb.data(), mb.size()); + lr_len = (int)memory.size() / 160 * 3; + durations.assign(22, 5.0f); + const char* test_dur = std::getenv("KANTTS_TEST_DUR"); + if (test_dur) { + std::ifstream df(test_dur, std::ios::binary); + std::vector db((std::istreambuf_iterator(df)), {}); + durations.resize(db.size() / 4); + std::memcpy(durations.data(), db.data(), db.size()); + } + std::fprintf(stderr, "[dbg] 使用参考 memory(%d 行)\n", (int)memory.size() / 160); + } else { + BuildMemory(text_hid, spk_hid, emo_hid, w_, T, memory, lr_len, durations); + } + int M = (int)memory.size() / 160; + std::fprintf(stderr, "[stage] memory M=%d lr_len=%d\n", M, lr_len); + if (std::getenv("KANTTS_DUMP_ENC")) { + std::ofstream f("/tmp/kt/full_mem.bin", std::ios::binary); + f.write((const char*)memory.data(), memory.size() * 4); + std::ofstream f2("/tmp/kt/full_dur.bin", std::ios::binary); + f2.write((const char*)durations.data(), durations.size() * 4); + } + int x_band = (int)(*std::max_element(durations.begin(), durations.end()) / 3.0f + 0.5f); + std::fprintf(stderr, "[stage] x_band=%d\n", x_band); + Decoder dec(w_); + dec.Prepare(memory); + std::fprintf(stderr, "[timing] host(预测+memory) %.0fms\n", std::chrono::duration(std::chrono::steady_clock::now()-t_stage).count()); + t_stage = std::chrono::steady_clock::now(); + std::vector xk(12 * 8 * 270 * 16, 0.0f), xv(12 * 8 * 270 * 16, 0.0f); + std::vector frame(80, 0.0f), out; + std::vector dec_all(M * 3 * 80); + double dec_sum = 0; + for (int s = 0; s < M; ++s) { + std::vector mem_step(memory.begin() + s * 160, memory.begin() + (s + 1) * 160); + dec.Step(frame, mem_step, xk, xv, s, x_band, out); + std::copy(out.begin(), out.begin() + 240, dec_all.begin() + s * 240); + std::copy(out.begin() + 160, out.begin() + 240, frame.begin()); + } + for (size_t i = 0; i < dec_all.size(); ++i) dec_sum += dec_all[i] * dec_all[i]; + std::fprintf(stderr, "[dbg] dec rms=%.4f\n", std::sqrt(dec_sum / dec_all.size())); + std::fprintf(stderr, "[timing] decode %d 步 %.0fms\n", M, std::chrono::duration(std::chrono::steady_clock::now()-t_stage).count()); + t_stage = std::chrono::steady_clock::now(); + std::vector mel = Postnet(dec_all, w_, M * 3); + std::fprintf(stderr, "[timing] postnet %.0fms\n", std::chrono::duration(std::chrono::steady_clock::now()-t_stage).count()); + t_stage = std::chrono::steady_clock::now(); + double mel_sum = 0; + for (size_t i = 0; i < mel.size(); ++i) mel_sum += mel[i] * mel[i]; + std::fprintf(stderr, "[dbg] mel rms=%.4f\n", std::sqrt(mel_sum / mel.size())); + if (std::getenv("KANTTS_DUMP_ENC")) { + std::ofstream f("/tmp/kt/full_mel.bin", std::ios::binary); + f.write((const char*)mel.data(), mel.size() * 4); + } + // voc 帧数 = memory 完整帧数(sum 非 3 倍数时 lr_len < M*3,需包含 pad 帧) + mel.resize(M * 3 * 80); + // voc 分块 + const int C = 200, O = 40; + int Tf = M * 3; + for (int start = 0; start < Tf; start += C) { + auto t_v = std::chrono::steady_clock::now(); + int end = std::min(start + C, Tf); + int cs = std::max(0, start - O); + std::vector chunk(80 * C, 0.0f); + for (int t = cs; t < end; ++t) + for (int c = 0; c < 80; ++c) chunk[c * C + (t - cs)] = mel[t * 80 + c]; + voc_->SetInput("mel", chunk.data(), chunk.size() * 4); + voc_->Run(); + std::fprintf(stderr, "[timing] voc chunk %.0fms\n", std::chrono::duration(std::chrono::steady_clock::now()-t_v).count()); + std::vector wav(C * 200); + voc_->GetOutput("wav", wav.data(), wav.size() * 4); + int keep0 = (start - cs) * 200; + int keepn = (end - start) * 200; + audio.insert(audio.end(), wav.begin() + keep0, wav.begin() + keep0 + keepn); + } + } + // 句末拼接静音,避免尾音被听不清(0.3s @ 16k) + audio.insert(audio.end(), 4800, 0.0f); + std::fprintf(stderr, "[dbg] audio samples=%zu\n", audio.size()); + return audio; +} + +} // namespace kantts diff --git a/sdk/src/main.cpp b/sdk/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..00230b8192d67fcd15e1586737e9faf1690966aa --- /dev/null +++ b/sdk/src/main.cpp @@ -0,0 +1,78 @@ +#include "ax_engine.hpp" +#include "kantts.hpp" + +#include +#include +#include +#include +#include +#include +#include + +using namespace kantts; + +static void WriteWav(const std::string& path, const std::vector& audio, int sr = 16000) { + std::vector pcm(audio.size()); + for (size_t i = 0; i < audio.size(); ++i) { + float v = audio[i]; + if (v > 1.0f) v = 1.0f; + if (v < -1.0f) v = -1.0f; + pcm[i] = (int16_t)(v * 32767.0f); + } + std::ofstream f(path, std::ios::binary); + auto wr = [&](const void* p, size_t n) { f.write((const char*)p, n); }; + uint32_t data = pcm.size() * 2; + uint32_t rate = sr; + uint16_t ch = 1, bits = 16; + wr("RIFF", 4); + uint32_t riff_size = 36 + data; + wr(&riff_size, 4); + wr("WAVEfmt ", 8); + uint32_t hdr = 16; + uint16_t fmt = 1; + wr(&hdr, 4); + wr(&fmt, 2); + wr(&ch, 2); + wr(&rate, 4); + uint32_t bps = rate * ch * bits / 8; + wr(&bps, 4); + uint16_t ba = ch * bits / 8; + wr(&ba, 2); + wr(&bits, 2); + wr("data", 4); + wr(&data, 4); + wr(pcm.data(), pcm.size() * 2); +} + +int main(int argc, char** argv) { + if (argc < 4) { + std::fprintf(stderr, + "用法: kantts_tts \n" + "symbols.txt: 每行一个 ttsfrd gen_tacotron_symbols 输出(见 tools/text_to_symbols.py)\n"); + return 1; + } + try { + AxRuntimeInit(); + KanttsPipeline pipe(argv[1], argv[2], std::string(argv[1]) + "/am_config.yaml"); + std::ifstream sf(argv[3]); + std::vector symbols; + std::string line; + while (std::getline(sf, line)) { + auto tab = line.find('\t'); + symbols.push_back(tab == std::string::npos ? line : line.substr(tab + 1)); + } + auto t0 = std::chrono::steady_clock::now(); + auto audio = pipe.SynthesizeSymbols(symbols); + auto t1 = std::chrono::steady_clock::now(); + WriteWav(argv[4], audio); + double sec = std::chrono::duration(t1 - t0).count(); + double dur = audio.size() / 16000.0; + std::printf("输出 %s(%.2fs 音频,合成 %.2fs,RTF=%.2f)\n", argv[4], dur, sec, + dur > 0 ? sec / dur : 0); + AxRuntimeDeinit(); + } catch (const std::exception& e) { + std::fprintf(stderr, "错误: %s\n", e.what()); + return 1; + } + return 0; +} diff --git a/sdk/tools/text_to_symbols.py b/sdk/tools/text_to_symbols.py new file mode 100644 index 0000000000000000000000000000000000000000..9eda89baecbf1dd6b786caefb1050ca0b1eb9764 --- /dev/null +++ b/sdk/tools/text_to_symbols.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +"""主机侧前端工具:中文文本 → 符号序列文件(供板端 kantts_tts 使用)。 +依赖 ttsfrd(x86 Python3.10 可用);板端无需此工具。 +""" +import sys + +import ttsfrd + + +def main(): + resource_dir = sys.argv[1] + text = sys.argv[2] + out = sys.argv[3] + fe = ttsfrd.TtsFrontendEngine() + assert fe.initialize(resource_dir) + fe.set_lang_type("zh-cn") + res = fe.gen_tacotron_symbols(text.strip()) + open(out, "w", encoding="utf-8").write(res) + print(f"{out}: {len(res.strip().splitlines())} 句") + + +if __name__ == "__main__": + main()