Add C++ runtime for vocos (#2014)

This commit is contained in:
Fangjun Kuang
2025-03-17 17:05:15 +08:00
committed by GitHub
parent 623cdc9eec
commit 0aacf02dd8
62 changed files with 558 additions and 162 deletions

View File

@@ -45,11 +45,21 @@ class HifiganVocoder::Impl {
Init(buf.data(), buf.size());
}
Ort::Value Run(Ort::Value mel) const {
std::vector<float> Run(Ort::Value mel) const {
auto out = sess_->Run({}, input_names_ptr_.data(), &mel, 1,
output_names_ptr_.data(), output_names_ptr_.size());
return std::move(out[0]);
std::vector<int64_t> audio_shape =
out[0].GetTensorTypeAndShapeInfo().GetShape();
int64_t total = 1;
// The output shape may be (1, 1, total) or (1, total) or (total,)
for (auto i : audio_shape) {
total *= i;
}
const float *p = out[0].GetTensorData<float>();
return {p, p + total};
}
private:
@@ -88,7 +98,7 @@ HifiganVocoder::HifiganVocoder(Manager *mgr, int32_t num_threads,
HifiganVocoder::~HifiganVocoder() = default;
Ort::Value HifiganVocoder::Run(Ort::Value mel) const {
std::vector<float> HifiganVocoder::Run(Ort::Value mel) const {
return impl_->Run(std::move(mel));
}