GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — NeMo-Speech.cpp/src/core/engine_registry.cpp at main · NVIDIA/NeMo-Speech.cpp Expand file tree/ Copy pathengine_registry.cppMore file actions 276 lines (252 loc) · 7.74 KB / Copy pathengine_registry.cppFile metadata and controls276 lines (252 loc) · 7.74 KB 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 #include "engine_registry.h" #ifdef NEMO_SPEECH_REGISTRY_SPEECHLM #include "salm_recognizer.h" #endif #include <stdexcept> #include <utility> #include "runtime.h" namespace nemo_speech { EngineRegistry::EngineRegistry(EngineRegistryConfig config) { #if defined(NEMO_SPEECH_REGISTRY_NMT) if (config.nmt && config.asr) ggml_runtime::keep_skinny_q8_weights_separate(); #else (void)config; #endif } #if defined(NEMO_SPEECH_REGISTRY_DIAR) std::shared_ptr<asr::Diarizer> EngineRegistry::load_diarization( int gpu, const std::string& model_path, asr::DiarGeometry geometry, asr::BatchingConfig batching) { auto engine = asr::Diarizer::load(gpu, model_path, std::move(geometry), std::move(batching)); std::lock_guard<std::mutex> lock(mutex_); diar_ = engine; diar_from_asr_ = false; return engine; } std::shared_ptr<asr::Diarizer> EngineRegistry::diarization() const { std::lock_guard<std::mutex> lock(mutex_); if (diar_) return diar_; throw std::runtime_error("diarization is not loaded"); } #endif #if defined(NEMO_SPEECH_REGISTRY_ASR) std::shared_ptr<asr::Recognizer> EngineRegistry::load_asr(asr::RecognizerConfig config) { asr::resolve_salm_encoder(config); std::shared_ptr<asr::Recognizer> engine; if (!config.salm.encoder_path.empty()) { #ifdef NEMO_SPEECH_REGISTRY_SPEECHLM auto backend = speechlm::make_salm_backend(config); engine = std::make_shared<asr::Recognizer>(std::move(config), std::move(backend)); #else throw std::invalid_argument("SALM requires NEMO_SPEECH_BUILD_SPEECHLM=ON"); #endif } else { engine = std::make_shared<asr::Recognizer>(std::move(config)); } std::lock_guard<std::mutex> lock(mutex_); #if defined(NEMO_SPEECH_REGISTRY_DIAR) if (diar_from_asr_) diar_.reset(); #endif asr_ = engine; #if defined(NEMO_SPEECH_REGISTRY_DIAR) if (engine->diar_model()) { auto model = std::shared_ptr<asr::DiarModel>(engine, engine->diar_model()); diar_ = std::make_shared<asr::Diarizer>( std::move(model), engine->config().diar.resolved_geometry()); diar_from_asr_ = true; } #endif rebuild_compositions_locked(); return engine; } std::shared_ptr<asr::Recognizer> EngineRegistry::asr() const { std::lock_guard<std::mutex> lock(mutex_); if (!asr_) throw std::runtime_error("ASR is not loaded"); return asr_; } #endif #if defined(NEMO_SPEECH_REGISTRY_TTS) std::shared_ptr<tts::Synthesizer> EngineRegistry::load_tts(tts::SynthesizerConfig config) { ggml_runtime::keep_cuda_graphs_resident(); auto engine = std::make_shared<tts::Synthesizer>(std::move(config)); std::lock_guard<std::mutex> lock(mutex_); tts_ = engine; rebuild_compositions_locked(); return engine; } std::shared_ptr<tts::Synthesizer> EngineRegistry::tts() const { std::lock_guard<std::mutex> lock(mutex_); if (!tts_) throw std::runtime_error("TTS is not loaded"); return tts_; } #endif #if defined(NEMO_SPEECH_REGISTRY_NMT) std::shared_ptr<nmt::Translator> EngineRegistry::load_nmt(nmt::TranslatorConfig config) { auto engine = std::make_shared<nmt::Translator>(std::move(config)); std::lock_guard<std::mutex> lock(mutex_); nmt_ = engine; rebuild_compositions_locked(); return engine; } std::shared_ptr<nmt::Translator> EngineRegistry::nmt() const { std::lock_guard<std::mutex> lock(mutex_); if (!nmt_) throw std::runtime_error("NMT is not loaded"); return nmt_; } #endif #if defined(NEMO_SPEECH_REGISTRY_SPEECH) std::shared_ptr<speech::SpeechTranslator> EngineRegistry::speech_translation() const { std::lock_guard<std::mutex> lock(mutex_); if (!speech_) throw std::runtime_error("speech translation requires loaded ASR and NMT engines"); return speech_; } bool EngineRegistry::has_speech_translation() const { std::lock_guard<std::mutex> lock(mutex_); return speech_ != nullptr; } #endif #if defined(NEMO_SPEECH_REGISTRY_S2S) std::shared_ptr<s2s::VoiceChat> EngineRegistry::load_voicechat(s2s::VoiceChatConfig config) { auto voicechat = std::make_shared<s2s::VoiceChat>(std::move(config)); std::lock_guard<std::mutex> lock(mutex_); voicechat_ = voicechat; return voicechat; } std::shared_ptr<s2s::VoiceChat> EngineRegistry::voicechat() const { std::lock_guard<std::mutex> lock(mutex_); if (!voicechat_) throw std::runtime_error("VoiceChat is not loaded"); return voicechat_; } #endif void EngineRegistry::rebuild_compositions_locked() { #if defined(NEMO_SPEECH_REGISTRY_SPEECH) speech_.reset(); if (asr_ && nmt_) { #if defined(NEMO_SPEECH_REGISTRY_TTS) speech_ = std::make_shared<speech::SpeechTranslator>(asr_, nmt_, tts_); #else speech_ = std::make_shared<speech::SpeechTranslator>(asr_, nmt_); #endif } #endif } void EngineRegistry::warmup(const WarmupOptions& options) { #if !defined(NEMO_SPEECH_REGISTRY_ASR) && !defined(NEMO_SPEECH_REGISTRY_TTS) && \ !defined(NEMO_SPEECH_REGISTRY_S2S) (void)options; #endif #if defined(NEMO_SPEECH_REGISTRY_ASR) std::shared_ptr<asr::Recognizer> recognizer; { std::lock_guard<std::mutex> lock(mutex_); recognizer = asr_; } if (recognizer && options.asr) recognizer->warmup(); #endif #if defined(NEMO_SPEECH_REGISTRY_TTS) std::shared_ptr<tts::Synthesizer> synthesizer; { std::lock_guard<std::mutex> lock(mutex_); synthesizer = tts_; } if (synthesizer && options.tts) synthesizer->warmup(options.tts_text, options.tts_steps); #endif #if defined(NEMO_SPEECH_REGISTRY_S2S) std::shared_ptr<s2s::VoiceChat> voicechat; { std::lock_guard<std::mutex> lock(mutex_); voicechat = voicechat_; } if (voicechat && options.s2s) voicechat->warmup(); #endif } void EngineRegistry::set_device_label(std::string label) { std::lock_guard<std::mutex> lock(mutex_); device_label_ = std::move(label); } std::string EngineRegistry::device_label() const { std::lock_guard<std::mutex> lock(mutex_); return device_label_; } std::vector<std::string> EngineRegistry::capabilities() const { std::lock_guard<std::mutex> lock(mutex_); std::vector<std::string> result; #if defined(NEMO_SPEECH_REGISTRY_ASR) if (asr_) result.emplace_back("asr"); #endif #if defined(NEMO_SPEECH_REGISTRY_DIAR) if (diar_) result.emplace_back("diarization"); #if defined(NEMO_SPEECH_REGISTRY_ASR) // A speech-LLM recognizer diarizes alone with its encoder's speaker branch. else if (asr_ && asr_->supports_offline_diarization()) result.emplace_back("diarization"); #endif #endif #if defined(NEMO_SPEECH_REGISTRY_TTS) if (tts_) result.emplace_back("tts"); #endif #if defined(NEMO_SPEECH_REGISTRY_NMT) if (nmt_) result.emplace_back("translation"); #endif #if defined(NEMO_SPEECH_REGISTRY_SPEECH) if (speech_) { result.emplace_back("speech-translation"); if (speech_->can_synthesize()) result.emplace_back("speech-to-speech"); } #endif #if defined(NEMO_SPEECH_REGISTRY_ASR) // Without the ASR + NMT composition, a speech-LLM recognizer translates speech itself // (POST /v1/audio/translations). bool composed = false; #if defined(NEMO_SPEECH_REGISTRY_SPEECH) composed = speech_ != nullptr; #endif if (!composed && asr_ && asr_->supports_translation()) result.emplace_back("speech-translation"); #endif #if defined(NEMO_SPEECH_REGISTRY_S2S) if (voicechat_) result.emplace_back("realtime-speech-to-speech"); #endif return result; } bool EngineRegistry::ready() const { return !capabilities().empty(); } } // namespace nemo_speech |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |