File size: 2,489 Bytes
5d1961d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | // Transcribe a manifest with speech-core's NemotronMultilingualStt (the runtime we ship on-device),
// streaming 320 ms windows exactly as an app would.
//
// Usage: stt_eval <bundle_dir> <language> <manifest.csv> <provider_label>
// manifest rows: uid,wav_path,reference (no header)
// stdout rows: uid,provider,audio_s,wall_ms,transcript (speech-core bench CSV, '#' header)
#include "speech_core/audio/resampler.h"
#include "speech_core/audio/wav_io.h"
#include "speech_core/models/nemotron_multilingual_stt.h"
#include <chrono>
#include <cstdio>
#include <fstream>
#include <sstream>
#include <string>
int main(int argc, char** argv) {
if (argc != 5) {
std::fprintf(stderr, "usage: %s <bundle_dir> <language> <manifest.csv> <provider>\n", argv[0]);
return 2;
}
const std::string dir = argv[1];
speech_core::NemotronMultilingualStt stt(dir + "/encoder.onnx", dir + "/decoder.onnx", dir + "/joint.onnx",
dir + "/vocab.json", dir + "/languages.json",
/*hw_accel=*/false);
if (!stt.set_language(argv[2])) {
std::fprintf(stderr, "unknown language %s in languages.json\n", argv[2]);
return 2;
}
std::ifstream manifest(argv[3]);
std::string line;
std::printf("#uid,provider,audio_s,wall_ms,transcript\n");
while (std::getline(manifest, line)) {
std::stringstream row(line);
std::string uid, wav;
if (!std::getline(row, uid, ',') || !std::getline(row, wav, ',')) continue;
speech_core::WavData audio;
if (!speech_core::load_wav_mono_pcm16(wav, &audio)) {
std::fprintf(stderr, "skip %s: unreadable\n", uid.c_str());
continue;
}
auto samples = audio.sample_rate == 16000
? audio.samples
: speech_core::Resampler::resample(audio.samples.data(), audio.samples.size(), audio.sample_rate, 16000);
const auto t0 = std::chrono::steady_clock::now();
const auto result = stt.transcribe(samples.data(), samples.size(), 16000);
const double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
std::string text = result.text;
for (char& c : text) if (c == ',' || c == '\n') c = ' ';
std::printf("%s,%s,%.3f,%.1f,%s\n", uid.c_str(), argv[4], samples.size() / 16000.0, ms, text.c_str());
std::fflush(stdout);
}
return 0;
}
|