pull/2866/head
YangZhou 3 years ago
parent cf43a69966
commit 2f29a0a461

@ -43,16 +43,15 @@ U2Recognizer::U2Recognizer(const U2RecognizerResource& resource)
input_finished_ = false;
num_frames_ = 0;
result_.clear();
}
U2Recognizer::U2Recognizer(const U2RecognizerResource& resource,
std::shared_ptr<NnetBase>nnet)
std::shared_ptr<NnetBase> nnet)
: opts_(resource) {
BaseFloat am_scale = resource.acoustic_scale;
const FeaturePipelineOptions& feature_opts = resource.feature_pipeline_opts;
std::shared_ptr<FeaturePipeline> feature_pipeline(
new FeaturePipeline(feature_opts));
std::shared_ptr<FeaturePipeline> feature_pipeline =
std::make_shared<FeaturePipeline>(feature_opts);
nnet_producer_.reset(new NnetProducer(nnet, feature_pipeline));
decodable_.reset(new Decodable(nnet_producer_, am_scale));
@ -120,8 +119,8 @@ void U2Recognizer::RunDecoderSearchInternal() {
void U2Recognizer::Accept(const vector<BaseFloat>& waves) {
kaldi::Timer timer;
nnet_producer_->Accept(waves);
VLOG(1) << "feed waves cost: " << timer.Elapsed() << " sec. " << waves.size()
<< " samples.";
VLOG(1) << "feed waves cost: " << timer.Elapsed() << " sec. "
<< waves.size() << " samples.";
}
void U2Recognizer::Decode() {

@ -111,9 +111,9 @@ struct U2RecognizerResource {
class U2Recognizer {
public:
U2Recognizer(const U2RecognizerResource& resouce);
U2Recognizer(const U2RecognizerResource& resource,
std::shared_ptr<NnetBase>nnet);
explict U2Recognizer(const U2RecognizerResource& resouce);
explict U2Recognizer(const U2RecognizerResource& resource,
std::shared_ptr<NnetBase> nnet);
~U2Recognizer();
void InitDecoder();
void ResetContinuousDecoding();
@ -145,7 +145,7 @@ class U2Recognizer {
void AttentionRescoring();
private:
static void RunDecoderSearch(U2Recognizer *me);
static void RunDecoderSearch(U2Recognizer* me);
void RunDecoderSearchInternal();
void UpdateResult(bool finish = false);

@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "recognizer/u2_recognizer.h"
#include "common/base/thread_pool.h"
#include "common/utils/strings.h"
#include "common/utils/file_utils.h"
#include "common/utils/strings.h"
#include "decoder/param.h"
#include "frontend/wave-reader.h"
#include "nnet/u2_nnet.h"
#include "kaldi/util/table-types.h"
#include "recognizer/u2_recognizer.h"
#include "nnet/u2_nnet.h"
DEFINE_string(wav_rspecifier, "", "test feature rspecifier");
DEFINE_string(result_wspecifier, "", "test result wspecifier");
@ -60,8 +60,8 @@ void recognizer_func(const ppspeech::U2RecognizerResource& resource,
int chunk_sample_size = FLAGS_streaming_chunk * FLAGS_sample_rate;
if (wavlist.empty()) return;
std::shared_ptr<ppspeech::U2Recognizer> recognizer_ptr(
new ppspeech::U2Recognizer(resource, nnet));
std::shared_ptr<ppspeech::U2Recognizer> recognizer_ptr =
std::make_shared<ppspeech::U2Recognizer>(resource, nnet);
results->reserve(wavlist.size());
for (size_t idx = 0; idx < wavlist.size(); ++idx) {
@ -157,11 +157,16 @@ int main(int argc, char* argv[]) {
vector<vector<string>> uttlist;
vector<vector<string>> resultlist(njob);
vector<std::future<void>> futurelist;
std::thread threads[njob];
std::shared_ptr<ppspeech::U2Nnet> nnet(new ppspeech::U2Nnet(resource.model_opts));
std::shared_ptr<ppspeech::U2Nnet> nnet(
new ppspeech::U2Nnet(resource.model_opts));
SplitUtt(FLAGS_wav_rspecifier, &uttlist, &wavlist, njob);
for (size_t i = 0; i < njob; ++i) {
std::future<void> f = threadpool.enqueue(recognizer_func, resource, nnet->Clone(), wavlist[i], uttlist[i], &resultlist[i]);
std::future<void> f = threadpool.enqueue(recognizer_func,
resource,
nnet->Clone(),
wavlist[i],
uttlist[i],
&resultlist[i]);
futurelist.push_back(std::move(f));
}

Loading…
Cancel
Save