Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cpptflite/src/MelGenerateTF.cpp
1559 views
1
#include <iostream>
2
#include "MelGenerateTF.h"
3
4
MelGenData MelGenerateTF::infer(const std::vector<int32_t> inputIds)
5
{
6
7
MelGenData output;
8
9
int32_t idsLen = inputIds.size();
10
11
std::vector<std::vector<int32_t>> inputIndexsShape{ {1, idsLen}, {1}, {1}, {1}, {1} };
12
13
int32_t shapeI = 0;
14
for (auto index : inputIndexs)
15
{
16
interpreter->ResizeInputTensor(index, inputIndexsShape[shapeI]);
17
shapeI++;
18
}
19
20
TFLITE_MINIMAL_CHECK(interpreter->AllocateTensors() == kTfLiteOk);
21
22
int32_t* input_ids_ptr = interpreter->typed_tensor<int32_t>(inputIndexs[0]);
23
memcpy(input_ids_ptr, inputIds.data(), int_size * idsLen);
24
25
int32_t* speaker_ids_ptr = interpreter->typed_tensor<int32_t>(inputIndexs[1]);
26
memcpy(speaker_ids_ptr, _speakerId.data(), int_size);
27
28
float* speed_ratios_ptr = interpreter->typed_tensor<float>(inputIndexs[2]);
29
memcpy(speed_ratios_ptr, _speedRatio.data(), float_size);
30
31
float* speed_ratios2_ptr = interpreter->typed_tensor<float>(inputIndexs[3]);
32
memcpy(speed_ratios2_ptr, _f0Ratio.data(), float_size);
33
34
float* speed_ratios3_ptr = interpreter->typed_tensor<float>(inputIndexs[4]);
35
memcpy(speed_ratios3_ptr, _enegyRatio.data(), float_size);
36
37
TFLITE_MINIMAL_CHECK(interpreter->Invoke() == kTfLiteOk);
38
39
TfLiteTensor* melGenTensor = interpreter->tensor(ouptIndex);
40
41
for (int i=0; i<melGenTensor->dims->size; i++)
42
{
43
output.melShape.push_back(melGenTensor->dims->data[i]);
44
}
45
46
output.bytes = melGenTensor->bytes;
47
48
output.melData = interpreter->typed_tensor<float>(ouptIndex);
49
50
return output;
51
}
52