MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / compute

Function compute

plugins/wasi_nn/wasinn_piper.cpp:373–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373Expect<WASINN::ErrNo> compute(WASINN::WasiNNEnvironment &Env,
374 uint32_t ContextId) noexcept {
375 auto &CxtRef = Env.NNContext[ContextId].get<Context>();
376 auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>();
377
378 if (!CxtRef.Line) {
379 spdlog::error("[WASI-NN] Piper backend: Input is not set."sv);
380 return WASINN::ErrNo::InvalidArgument;
381 }
382
383 std::string TextToSpeak = CxtRef.Line.value();
384
385 if (GraphRef.Config->JsonInput) {
386 simdjson::dom::parser Parser;
387 simdjson::dom::element Doc;
388 simdjson::padded_string const PaddedInput(TextToSpeak);
389
390 if (Parser.parse(PaddedInput).get(Doc) != simdjson::SUCCESS) {
391 spdlog::error("[WASI-NN] Piper backend: Failed to parse JSON input."sv);
392 return WASINN::ErrNo::InvalidArgument;
393 }
394
395 simdjson::dom::object JsonObj;
396 if (Doc.get(JsonObj) != simdjson::SUCCESS) {
397 spdlog::error("[WASI-NN] Piper backend: JSON input is not an object."sv);
398 return WASINN::ErrNo::InvalidArgument;
399 }
400
401 std::string_view TmpText;
402 if (JsonObj["text"].get(TmpText) != simdjson::SUCCESS) {
403 spdlog::error(
404 "[WASI-NN] Piper backend: JSON input must contain 'text' field."sv);
405 return WASINN::ErrNo::InvalidArgument;
406 }
407 TextToSpeak = std::string(TmpText);
408
409 SynthesisConfig NewConfig;
410 if (parseSynthesisConfig(NewConfig, JsonObj) == WASINN::ErrNo::Success) {
411 CxtRef.JsonInputSynthesisConfig =
412 std::make_unique<std::optional<SynthesisConfig>>(NewConfig);
413 }
414 }
415
416 piper_synthesize_options Options =
417 piper_default_synthesize_options(GraphRef.Synth.get());
418 updatePiperOptions(GraphRef.Config->DefaultSynthesisConfig, Options);
419
420 auto OutputType = SynthesisConfigOutputType::OUTPUT_WAV;
421 if (GraphRef.Config->DefaultSynthesisConfig.OutputType) {
422 OutputType = GraphRef.Config->DefaultSynthesisConfig.OutputType.value();
423 }
424
425 if (CxtRef.JsonInputSynthesisConfig &&
426 CxtRef.JsonInputSynthesisConfig->has_value()) {
427 updatePiperOptions(CxtRef.JsonInputSynthesisConfig->value(), Options);
428 if (CxtRef.JsonInputSynthesisConfig->value().OutputType) {
429 OutputType = CxtRef.JsonInputSynthesisConfig->value().OutputType.value();
430 }

Callers

nothing calls this directly

Calls 15

parseSynthesisConfigFunction · 0.85
updatePiperOptionsFunction · 0.85
writeWavHeaderFunction · 0.85
c_strMethod · 0.80
resizeMethod · 0.80
insertMethod · 0.80
errorFunction · 0.50
valueMethod · 0.45
getMethod · 0.45
parseMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected